Class: ActiveModel::Serializers::Matchers::AssociationMatcher
- Inherits:
-
Object
- Object
- ActiveModel::Serializers::Matchers::AssociationMatcher
- Defined in:
- lib/active_model_serializers/matchers.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
Returns the value of attribute actual.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #as(value) ⇒ Object
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(name) ⇒ AssociationMatcher
constructor
A new instance of AssociationMatcher.
- #matches?(actual) ⇒ Boolean
Constructor Details
#initialize(name) ⇒ AssociationMatcher
Returns a new instance of AssociationMatcher.
128 129 130 |
# File 'lib/active_model_serializers/matchers.rb', line 128 def initialize(name) @name = name end |
Instance Attribute Details
#actual ⇒ Object
Returns the value of attribute actual.
126 127 128 |
# File 'lib/active_model_serializers/matchers.rb', line 126 def actual @actual end |
#key ⇒ Object
Returns the value of attribute key.
126 127 128 |
# File 'lib/active_model_serializers/matchers.rb', line 126 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
126 127 128 |
# File 'lib/active_model_serializers/matchers.rb', line 126 def name @name end |
Instance Method Details
#as(value) ⇒ Object
148 149 150 151 |
# File 'lib/active_model_serializers/matchers.rb', line 148 def as(value) self.key = value self end |
#description ⇒ Object
153 154 155 |
# File 'lib/active_model_serializers/matchers.rb', line 153 def description "have attribute #{name}" end |
#failure_message_for_should ⇒ Object
157 158 159 |
# File 'lib/active_model_serializers/matchers.rb', line 157 def %Q{expected #{actual.inspect} to include a "#{name}" association, but it did not} end |
#failure_message_for_should_not ⇒ Object
161 162 163 |
# File 'lib/active_model_serializers/matchers.rb', line 161 def %Q{expected #{actual.inspect} to not include a "#{name}" association, but it did} end |
#matches?(actual) ⇒ Boolean
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/active_model_serializers/matchers.rb', line 132 def matches?(actual) @actual = actual matched_association = associations.select do |assc| assc.name == name end.first return false unless matched_association if key return false if matched_association.key != key end true end |