-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add validation for presence of the title and descrption
- Loading branch information
Showing
2 changed files
with
20 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |