Last active
January 3, 2016 01:09
-
-
Save jefflunt/8387633 to your computer and use it in GitHub Desktop.
Writing tests for AR validations
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
class Order < ActiveRecord::Base | |
... | |
validates :customer_id, | |
:company_id, | |
:credit_card_id, | |
:tip, | |
:delivery_location, | |
presence: true | |
... | |
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
class OrderTest < ActiveSupport::TestCase | |
... | |
[ :customer_id, :credit_card_id, :delivery_location, :company_id, :tip ].each do |field| | |
should validate_presence_of field | |
end | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMHO if this is some sort of double check (like "am I really sure I should remove those validations because I would have to go modify the tests too") it's not something I would want to write.
I used to write lots of tests on AR, on the router, etc. None of these are actually worth the effort. What's worth the effort though is to isolate the app from the framework, and test the interactions. YMMV :-)