Permalink
Browse files

add validation for presence of the title and descrption

  • Loading branch information...
1 parent 63acb2c commit 84ad2e43d1c176d9eba43f6fe3f1cc5ecdad2e01 @FuriKuri committed Nov 4, 2012
Showing with 20 additions and 3 deletions.
  1. +2 −0 app/models/book.rb
  2. +18 −3 test/unit/book_test.rb
View
@@ -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
@@ -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.