Class: DataMapper::Matchers::HaveMany
- Inherits:
-
Object
- Object
- DataMapper::Matchers::HaveMany
- Defined in:
- lib/dm/matchers/have_many.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(children) ⇒ HaveMany
constructor
A new instance of HaveMany.
- #matches?(parent) ⇒ Boolean
- #negative_failure_message ⇒ Object
-
#through(broker) ⇒ Object
called only when the next syntax is used: Book.should have_many(:tags).trough(:tagging).
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
#description ⇒ Object
32 33 34 |
# File 'lib/dm/matchers/have_many.rb', line 32 def description "has many #{@children}" end |
#failure_message ⇒ Object
24 25 26 |
# File 'lib/dm/matchers/have_many.rb', line 24 def "expected to have many #{@children}" end |
#matches?(parent) ⇒ 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_message ⇒ Object
28 29 30 |
# File 'lib/dm/matchers/have_many.rb', line 28 def "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 |