Class: DataMapper::Matchers::HaveOne
- Inherits:
-
Object
- Object
- DataMapper::Matchers::HaveOne
- Defined in:
- lib/dm/matchers/have_one.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(child) ⇒ HaveOne
constructor
A new instance of HaveOne.
- #matches?(parent) ⇒ Boolean
- #negative_failure_message ⇒ Object
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
#description ⇒ Object
25 26 27 |
# File 'lib/dm/matchers/have_one.rb', line 25 def description "has one #{@child}" end |
#failure_message ⇒ Object
17 18 19 |
# File 'lib/dm/matchers/have_one.rb', line 17 def "expected to have one #{@child}" end |
#matches?(parent) ⇒ 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_message ⇒ Object
21 22 23 |
# File 'lib/dm/matchers/have_one.rb', line 21 def "expected not to have one #{@child}" end |