My Question
def test_check_for_validity
post=County.new(:name=>"
myname",:description=>“mydesc”)
assert post.save
end
above is the method and when i run unit test it is saying as
- Failure:
test_check_for_validity(CountyTest) [/test/unit/county_test.rb:10]:
is not true.
what does it say i cannot under stand
please help
your answer
It is saying that the post.save failed (the assert is expecting true,
so false makes the test fail). Possibly your validations are failing.
If you put the line
assert post.valid?, post.errors.full_messages
before the save this will check the item for validity before
attempting to save it and show you any errors from validations (I
think).
Colin
My question
hi
i am updating the data in unit testing
def test_for_update
post=counties(:one)
assert post.valid?, post.errors.full_messages
assert post.update_attributes(:name=>
“”)
end
name should not be empty but as you said i displayed
“assert post.valid?, post.errors.full_messages”
But i am not getting error message in assert but getting error message
hi Colin
- Failure:
test_for_update(CountyTest) [test/unit/county_test.rb:19]:
Name has already been taken.
is not true.
your answer
Could you reply with your comments inserted into the existing email
please rather than at the top, it makes it much easier to follow the
thread, so your comment above should have been after my bit asking for
the error.
Have you got a validates_uniqueness_of :name? I think the error means
there are two with the same name. If you can’t see the problem post
your counties.yml.
Earlier it was suggested that you look at the rails guides Getting
Started and Testing. Have you done that and do you understand all
that is in them? (Or at least understand most of it)
Colin
Yes
i have validates_uniqueness_of :name
what i need to do
please help
karthik.k