Class: DataMapperMatchers::HasAndBelongsToMany

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/matchers/dm/has_and_belongs_to_many.rb

Instance Method Summary collapse

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

#descriptionObject



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_messageObject



24
25
26
27
28
# File 'lib/spec/matchers/dm/has_and_belongs_to_many.rb', line 24

def failure_message
  # 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

Returns:

  • (Boolean)


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_messageObject



30
31
32
# File 'lib/spec/matchers/dm/has_and_belongs_to_many.rb', line 30

def negative_failure_message
  "expected not to has and belongs to many #@name, but had"
end