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.
23 24 25 26 27 28 |
# File 'lib/matchers/associations/associations.rb', line 23 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
36 37 38 39 40 |
# File 'lib/matchers/associations/associations.rb', line 36 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
55 56 57 |
# File 'lib/matchers/associations/associations.rb', line 55 def "#{@klass} to #{@description}, got #{@negative_message}" end |
#matches?(subject) ⇒ Boolean
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/matchers/associations/associations.rb', line 42 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
59 60 61 |
# File 'lib/matchers/associations/associations.rb', line 59 def "#{@klass} to not #{@description}, got #{@positive_message}" end |
#of_type(klass) ⇒ Object
30 31 32 33 34 |
# File 'lib/matchers/associations/associations.rb', line 30 def of_type klass @association[:class] = klass @description << " of type #{@association[:class].inspect}" self end |