Class: DataMapperMatchers::BelongsTo
- Inherits:
-
Object
- Object
- DataMapperMatchers::BelongsTo
- Defined in:
- lib/spec/matchers/dm/belongs_to.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(name) ⇒ BelongsTo
constructor
args<Symbol>: :products.
-
#matches?(model) ⇒ Boolean
args<Model>: Category.
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(name) ⇒ BelongsTo
args<Symbol>: :products
8 9 10 |
# File 'lib/spec/matchers/dm/belongs_to.rb', line 8 def initialize(name) @name = name end |
Instance Method Details
#description ⇒ Object
20 21 22 |
# File 'lib/spec/matchers/dm/belongs_to.rb', line 20 def description "belongs to" end |
#failure_message ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/spec/matchers/dm/belongs_to.rb', line 24 def belonging = @model.relationships.select { |name, relationship| relationship.name == @name && relationship.child_model == @model } belonging.map! { |array| array.first } if belonging.empty? "expected to belongs to #@name, but does not belongs to any model" else "expected to belongs to #@name, but belongs to just the following relationships: #{belonging.inspect}" end end |
#matches?(model) ⇒ Boolean
args<Model>: Category
13 14 15 16 17 18 |
# File 'lib/spec/matchers/dm/belongs_to.rb', line 13 def matches?(model) @model = model relationship = @model.relationships[@name] return false unless relationship relationship.name == @name && relationship.child_model == @model end |
#negative_failure_message ⇒ Object
34 35 36 |
# File 'lib/spec/matchers/dm/belongs_to.rb', line 34 def "expected not to belongs to #@name, but belonged" end |