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