Class: SequelSpec::Matchers::Association::AssociationMatcher
- Defined in:
- lib/sequel_spec/association/association_matcher.rb
Direct Known Subclasses
HaveManyThroughManyMatcher, HaveManyToManyMatcher, HaveManyToOneMatcher, HaveOneThroughOneMatcher, HaveOneToManyMatcher, HaveOneToOneMatcher
Instance Method Summary collapse
Methods inherited from Base
#failure_message, #hash_to_nice_string, #initialize, #matches?, #negative_failure_message, #with_options
Constructor Details
This class inherits a constructor from SequelSpec::Matchers::Base
Instance Method Details
#description ⇒ Object
5 6 7 8 9 |
# File 'lib/sequel_spec/association/association_matcher.rb', line 5 def description desc = "have a #{association_type} association #{@attribute.inspect}" desc << " with option(s) #{hash_to_nice_string @options}" unless .empty? desc end |
#valid?(db, instance, klass, attribute, options) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sequel_spec/association/association_matcher.rb', line 11 def valid?(db, instance, klass, attribute, ) @association = klass.association_reflection(attribute) || {} if @association.empty? @suffix << "(no association #{@attribute.inspect} found)" false else matching = @association[:type] == association_type .each do |key, value| if @association[key] != value @suffix << "expected #{key.inspect} == #{value.inspect} but found #{@association[key].inspect} instead" matching = false end end matching end end |