Class: DataMapper::Matchers::HaveMany

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

Instance Method Summary collapse

Constructor Details

#initialize(children) ⇒ HaveMany

Returns a new instance of HaveMany.



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

def initialize(children)
  @children = children
end

Instance Method Details

#descriptionObject



32
33
34
# File 'lib/dm/matchers/have_many.rb', line 32

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

#failure_messageObject



24
25
26
# File 'lib/dm/matchers/have_many.rb', line 24

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

#matches?(parent) ⇒ Boolean

Returns:

  • (Boolean)


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

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

  relation and
  relation.is_a?(DataMapper::Associations::OneToMany::Relationship) and
  relation.parent_model == parent_class
end

#negative_failure_messageObject



28
29
30
# File 'lib/dm/matchers/have_many.rb', line 28

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

#through(broker) ⇒ Object

called only when the next syntax is used:

Book.should have_many(:tags).trough(:tagging)


20
21
22
# File 'lib/dm/matchers/have_many.rb', line 20

def through(broker)
  HaveManyThrough.new(@children, broker)
end