Created
April 11, 2012 23:45
-
-
Save markahesketh/2363522 to your computer and use it in GitHub Desktop.
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
# /app/models/product.rb | |
validates :title, :uniqueness => true, | |
:length => {:minimum => 10, | |
:message => 'Title is too short. Must be at least 10 characters'} | |
# /test/unit/product_test.rb | |
test "product title must be at least 10 characters long" do | |
product = Product.new(:description => "yyy", | |
:price => 1, | |
:image_url => "fred.gif") | |
product.title = "Incorrect" | |
assert product.invalid? | |
assert_equal 'Title is too short. Must be at least 10 characters', product.errors[:title].join('; ') | |
product.title "And this" | |
assert product.invalid? | |
assert_equal 'Title is too short. Must be at least 10 characters', product.errors[:title].join('; ') | |
product.title "At least 10 characters long is correct" | |
assert product.valid? | |
end | |
--- OR --- | |
# /app/models/product.rb | |
validates :title, :uniqueness => true, | |
:length => {:minimum => 10, | |
:message => :too_short} | |
# /test/unit/product_test.rb | |
test "product title must be at least 10 characters long" do | |
product = Product.new(:description => "yyy", | |
:price => 1, | |
:image_url => "fred.gif") | |
product.title = "Incorrect" | |
assert product.invalid? | |
assert_equal :too_short, product.errors[:title].join('; ') | |
product.title "And this" | |
assert product.invalid? | |
assert_equal :too_short, product.errors[:title].join('; ') | |
product.title "At least 10 characters long is correct" | |
assert product.valid? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment