Class: DataMapper::Matchers::HaveManyAndBelongTo

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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ HaveManyAndBelongTo

Returns a new instance of HaveManyAndBelongTo.



5
6
7
# File 'lib/dm/matchers/have_many_and_belong_to.rb', line 5

def initialize(name)
  @name = name
end

Instance Method Details

#descriptionObject



23
24
25
# File 'lib/dm/matchers/have_many_and_belong_to.rb', line 23

def description
  "belongs to #{@parent}"
end

#failure_messageObject



15
16
17
# File 'lib/dm/matchers/have_many_and_belong_to.rb', line 15

def failure_message
  "expected to have many and belong to #{@name}"
end

#matches?(model) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
# File 'lib/dm/matchers/have_many_and_belong_to.rb', line 9

def matches?(model)
  model_class = model.is_a?(Class) ? model : model.class
	relation = model_class.relationships[@name.to_s]
	relation && relation.is_a?(DataMapper::Associations::ManyToMany::Relationship)
end

#negative_failure_messageObject



19
20
21
# File 'lib/dm/matchers/have_many_and_belong_to.rb', line 19

def negative_failure_message
  "expected to not have many and belong to #{@name}"
end