Class: Remarkable::Mongoid::Matchers::ValidateAssociationMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/remarkable/mongoid/validate_association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr) ⇒ ValidateAssociationMatcher

Returns a new instance of ValidateAssociationMatcher.



19
20
21
# File 'lib/remarkable/mongoid/validate_association.rb', line 19

def initialize(attr)
  self.attr = attr.to_sym
end

Instance Attribute Details

#attrObject

Returns the value of attribute attr.



17
18
19
# File 'lib/remarkable/mongoid/validate_association.rb', line 17

def attr
  @attr
end

Instance Method Details

#descriptionObject



29
30
31
# File 'lib/remarkable/mongoid/validate_association.rb', line 29

def description
  "validates the :#{attr} association"
end

#failure_message_for_shouldObject



33
34
35
# File 'lib/remarkable/mongoid/validate_association.rb', line 33

def failure_message_for_should
  "\nAssociation validation failure\nExpected: #{@subject.class} to validate the '#{attr}' association"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/remarkable/mongoid/validate_association.rb', line 23

def matches?(subject)
  @subject    = subject
  validations = @subject._validators[attr]
  validations.detect { |k| k.class == ::Mongoid::Validations::AssociatedValidator }
end