Class: DataMapperMatchers::HasAndBelongsToMany
- Inherits:
-
Object
- Object
- DataMapperMatchers::HasAndBelongsToMany
- Defined in:
- lib/spec/matchers/dm/has_and_belongs_to_many.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(name) ⇒ HasAndBelongsToMany
constructor
args<Symbol>: :products.
-
#matches?(model) ⇒ Boolean
args<Model>: Category.
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(name) ⇒ HasAndBelongsToMany
args<Symbol>: :products
8 9 10 |
# File 'lib/spec/matchers/dm/has_and_belongs_to_many.rb', line 8 def initialize(name) @name = name end |
Instance Method Details
#description ⇒ Object
20 21 22 |
# File 'lib/spec/matchers/dm/has_and_belongs_to_many.rb', line 20 def description "has and belongs to many" end |
#failure_message ⇒ Object
24 25 26 27 28 |
# File 'lib/spec/matchers/dm/has_and_belongs_to_many.rb', line 24 def # TODO: filter just n:n relationships relationships = @model.relationships.map { |name, relationship| relationship.name }.inspect "expected to has and belongs to many #@name, but has just the following relationships: #{relationships}" end |
#matches?(model) ⇒ Boolean
args<Model>: Category
13 14 15 16 17 18 |
# File 'lib/spec/matchers/dm/has_and_belongs_to_many.rb', line 13 def matches?(model) @model = model relationship = @model.relationships[@name] return false unless relationship relationship.class == DataMapper::Associations::RelationshipChain && relationship.child_model == @model end |
#negative_failure_message ⇒ Object
30 31 32 |
# File 'lib/spec/matchers/dm/has_and_belongs_to_many.rb', line 30 def "expected not to has and belongs to many #@name, but had" end |