Class: DataMapper::Matchers::HaveManyThrough

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

Instance Method Summary collapse

Constructor Details

#initialize(children, broker) ⇒ HaveManyThrough

Returns a new instance of HaveManyThrough.



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

def initialize(children, broker)
  @children, @broker = children, broker
end

Instance Method Details

#descriptionObject



26
27
28
# File 'lib/dm/matchers/have_many_through.rb', line 26

def description
  "has many #{@children} through #{@broker}"
end

#failure_messageObject



18
19
20
# File 'lib/dm/matchers/have_many_through.rb', line 18

def failure_message
  "expected to have many #{@children} through #{@broker}"
end

#matches?(parent) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
# File 'lib/dm/matchers/have_many_through.rb', line 9

def matches?(parent)
  parent_class = parent.is_a?(Class) ?  parent : parent.class
  relation = parent_class.relationships[@children.to_s]

  relation.parent_model == parent_class and
  relation.name == @children.to_sym and
  relation.options[:through] == @broker.to_sym
end

#negative_failure_messageObject



22
23
24
# File 'lib/dm/matchers/have_many_through.rb', line 22

def negative_failure_message
  "expected to not have many #{@children} through #{@broker}"
end