Skip to content

Commit

Permalink
add validation for presence of the title and descrption
Browse files Browse the repository at this point in the history
  • Loading branch information
FuriKuri committed Nov 4, 2012
1 parent 63acb2c commit 84ad2e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/models/book.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class Book < ActiveRecord::Base
attr_accessible :description, :image_url, :lent_to_user_id, :owner_id, :title

validates_presence_of :description, :title
end
21 changes: 18 additions & 3 deletions test/unit/book_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
require 'test_helper'

class BookTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "should save book" do
book = Book.new
book.title = 'Clean Code'
book.description = 'Clean Code book form Robert C. Martin'
assert book.valid?
end

test "should not save book with no title" do
book = Book.new
book.description = 'Clean Code book form Robert C. Martin'
assert book.invalid?
end

test "should not save book with no description" do
book = Book.new
book.title = 'Clean Code'
assert book.invalid?
end
end

0 comments on commit 84ad2e4

Please sign in to comment.