Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

test #20

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--colour
--format=d
--format=d
3 changes: 3 additions & 0 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def index
# GET /books/1
# GET /books/1.json
def show
@book = Book.find(params[:id])
@memo = @book.memos.build

respond_to do |format|
format.html # show.html.erb
format.xml { render xml: @book }
Expand Down
1 change: 1 addition & 0 deletions app/models/book.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# encoding: UTF-8
class Book < ActiveRecord::Base
has_many :memos
attr_accessible :memo, :purchased_on, :title
validates :title, :presence => true

Expand Down
3 changes: 2 additions & 1 deletion app/views/books/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<%= @book.purchased_on %>
</p>

<%= render 'memos/index' %>
<%= render 'memos/form' %>

<%= link_to 'Edit', edit_book_path(@book) %> |
<%= link_to 'Back', books_path %>
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
BookMemo2::Application.routes.draw do
resources :books
resources :books do
resources :memos
end

# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120526050801) do
ActiveRecord::Schema.define(:version => 20120627131716) do

create_table "books", :force => true do |t|
t.string "title"
Expand All @@ -21,4 +21,11 @@
t.datetime "updated_at", :null => false
end

create_table "memos", :force => true do |t|
t.integer "book_id"
t.text "memo"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

end
5 changes: 5 additions & 0 deletions spec/models/book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
require 'spec_helper'

describe Book do
it 'タイトルが未入力の場合はエラー' do
book = Book.new
book.valid?.should be_false
end

describe 'validation' do
describe 'title' do
subject { Book.new.valid? }
Expand Down