Created
November 13, 2012 05:35
-
-
Save benmacleod/4064150 to your computer and use it in GitHub Desktop.
Specs for validations using #send
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
describe "#has_no_duplicates" do | |
before do | |
account = Fabricate :account | |
@contact = Fabricate.build :contact, account: account, locale: account.locale | |
end | |
it "should add errors if there are duplicates" do | |
@contact.stub(:duplicates).and_return [mock(Contact, details: {email_address: 'foo', mobile_number: 'bar'})] | |
@contact.send(:has_no_duplicates) | |
@contact.errors.should be_present | |
@contact.errors[:base].should include("A duplicate contact exists with email_address 'foo' and mobile_number 'bar'") | |
end | |
it "should have no errors if there are no duplicates" do | |
@contact.stub(:duplicates).and_return [] | |
@contact.send(:has_no_duplicates) | |
@contact.errors.should be_blank | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment