Skip to content

Instantly share code, notes, and snippets.

@jefflunt
Last active January 3, 2016 01:09
Show Gist options
  • Save jefflunt/8387633 to your computer and use it in GitHub Desktop.
Save jefflunt/8387633 to your computer and use it in GitHub Desktop.
Writing tests for AR validations
class Order < ActiveRecord::Base
...
validates :customer_id,
:company_id,
:credit_card_id,
:tip,
:delivery_location,
presence: true
...
end
class OrderTest < ActiveSupport::TestCase
...
[ :customer_id, :credit_card_id, :delivery_location, :company_id, :tip ].each do |field|
should validate_presence_of field
end
...
end
@franckverrot
Copy link

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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment