Reputation: 29
I got a Devise model called Candidate.
And I got this test:
it { expect(subject).to validate_presence_of(:democracyengine_recipient_id) }
And this line in the model:
validates :democracyengine_recipient_id, presence: true
And the validation works (in other tests).
But in this particular test I get this error:
Failure/Error: it { expect(subject).to validate_presence_of(:democracyengine_recipient_id) }
Expected errors to include "can't be blank" when democracyengine_recipient_id is set to nil, got errors: ["email can't be blank (\"\")", "password can't be blank (nil)"]
How do I fix it?
Upvotes: 0
Views: 266
Reputation: 53038
presence: true
is an ActiveRecord validator and in my opinion it should have been called as below : (NOTE: validates and not validate)
validates :democracyengine_recipient_id, presence: true
validate
method adds a validation method or block to the class. This is useful when overriding the validate instance method becomes too unwieldy and you're looking for more descriptive declaration of your validations.
See more details in API Documentation for validate
For validates
see official API Documentation for validates
Upvotes: 1