Class: Mongoid::Matchers::Associations::HaveAssociationMatcher
- Defined in:
- lib/matchers/associations/associations.rb
Instance Method Summary collapse
- #as_inverse_of(inverse_of) ⇒ Object
- #failure_message ⇒ Object
-
#initialize(name, type) ⇒ HaveAssociationMatcher
constructor
A new instance of HaveAssociationMatcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #of_type(klass) ⇒ Object
Constructor Details
#initialize(name, type) ⇒ HaveAssociationMatcher
Returns a new instance of HaveAssociationMatcher.
13 14 15 16 17 18 |
# File 'lib/matchers/associations/associations.rb', line 13 def initialize name, type @association = {} @association[:name] = name.to_s @association[:type] = type @description = "#{type_description} #{@association[:name].inspect}" end |
Instance Method Details
#as_inverse_of(inverse_of) ⇒ Object
26 27 28 29 30 |
# File 'lib/matchers/associations/associations.rb', line 26 def as_inverse_of inverse_of @association[:inverse_of] = inverse_of @description << " as the inverse of #{@association[:inverse_of].inspect}" self end |
#failure_message ⇒ Object
45 46 47 |
# File 'lib/matchers/associations/associations.rb', line 45 def "#{@klass} to #{@description}, got #{@negative_message}" end |
#matches?(subject) ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/matchers/associations/associations.rb', line 32 def matches? subject @klass = class_of subject @metadata = @klass.relations[@association[:name]] @result = true check_association_name check_association_type check_association_class if @association[:class] check_association_inverse_of if @association[:inverse_of] @result end |
#negative_failure_message ⇒ Object
49 50 51 |
# File 'lib/matchers/associations/associations.rb', line 49 def "#{@klass} to not #{@description}, got #{@positive_message}" end |
#of_type(klass) ⇒ Object
20 21 22 23 24 |
# File 'lib/matchers/associations/associations.rb', line 20 def of_type klass @association[:class] = klass @description << " of type #{@association[:class].inspect}" self end |