I have a question about what parts of a controller should be tested in a Ruby on Rails application. Any help would be greatly appreciated.
When I create new models that need validations such as validates :name, presence: true
, I always write tests for these models. For example (if the model name is User):
test "name should be present" do
assert_not User.new({ name: nil }).valid?
end
However, I also have a controller that "goes with" the model (e.g Users). Should I also test that the controller validates its parameters even though I am already testing the model?
Example:
test "invalid user should not be created" do
assert_no_difference "User.count" do
post random_models_path, store: { name: " " }
end
end
I definitely am still going to test that a valid store is created, but should I check that an invalid store is not created?
Thanks
Aucun commentaire:
Enregistrer un commentaire