Created
July 24, 2012 17:34
-
-
Save awd/3171375 to your computer and use it in GitHub Desktop.
wrap validation rules in a context
This file contains hidden or 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
require 'test_helper' | |
class LikeTest < ActiveSupport::TestCase | |
should belong_to(:viewable) | |
should belong_to(:user) | |
context "validations" do | |
subject { Like.create(user_id: 1, viewable_id: 2, liked: false) } | |
should validate_uniqueness_of(:user_id).scoped_to(:viewable_id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ProTip: When testing a model's validation rules, you can wrap them inside a context to setup the expected objects / subject