Class: Shoulda::Matchers::ActiveRecord::HaveValidAssociationMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::HaveValidAssociationMatcher
- Defined in:
- lib/beyond_the_api_test_helpers/shoulda/have_valid_association.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object (also: #failure_message_for_should)
- #failure_message_when_negated ⇒ Object (also: #failure_message_for_should_not)
-
#initialize(association) ⇒ HaveValidAssociationMatcher
constructor
A new instance of HaveValidAssociationMatcher.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(association) ⇒ HaveValidAssociationMatcher
Returns a new instance of HaveValidAssociationMatcher.
10 11 12 13 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_valid_association.rb', line 10 def initialize(association) @association = association @options = {} end |
Instance Method Details
#description ⇒ Object
35 36 37 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_valid_association.rb', line 35 def description "have a valid association called #{@association}" end |
#failure_message ⇒ Object Also known as: failure_message_for_should
25 26 27 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_valid_association.rb', line 25 def "Expected #{expectation} (#{@missing})" end |
#failure_message_when_negated ⇒ Object Also known as: failure_message_for_should_not
30 31 32 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_valid_association.rb', line 30 def "Did not expect #{expectation}" end |
#matches?(subject) ⇒ Boolean
15 16 17 18 19 20 21 22 23 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_valid_association.rb', line 15 def matches?(subject) @subject = subject @expected_message ||= :required @subject.send("#{@association}_id=", 999_967) @subject.valid? @subject.errors[@association].include? I18n.t("errors.messages.#{@expected_message}") end |