Class: DataMapper::Matchers::HaveOne

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

Instance Method Summary collapse

Constructor Details

#initialize(child) ⇒ HaveOne

Returns a new instance of HaveOne.



4
5
6
# File 'lib/dm/matchers/have_one.rb', line 4

def initialize(child)
  @child = child
end

Instance Method Details

#descriptionObject



25
26
27
# File 'lib/dm/matchers/have_one.rb', line 25

def description
  "has one #{@child}"
end

#failure_messageObject



17
18
19
# File 'lib/dm/matchers/have_one.rb', line 17

def failure_message
  "expected to have one #{@child}"
end

#matches?(parent) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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

#negative_failure_messageObject



21
22
23
# File 'lib/dm/matchers/have_one.rb', line 21

def negative_failure_message
  "expected not to have one #{@child}"
end