Class: DataMapper::Matchers::BelongTo

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

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ BelongTo

Returns a new instance of BelongTo.



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

def initialize(parent)
  @parent = parent
end

Instance Method Details

#descriptionObject



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

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

#failure_messageObject



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

def failure_message
  "expected to belong to #{@parent}"
end

#matches?(child) ⇒ Boolean

Returns:

  • (Boolean)


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

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

  relation and
  relation.is_a?(DataMapper::Associations::ManyToOne::Relationship) and
  relation.child_model == child_class
end

#negative_failure_messageObject



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

def negative_failure_message
  "expected to not belong to #{@parent}"
end