Class: MR::TestHelpers::AssociationSavedAssertionBase
- Inherits:
-
Object
- Object
- MR::TestHelpers::AssociationSavedAssertionBase
- Defined in:
- lib/mr/test_helpers.rb
Direct Known Subclasses
Defined Under Namespace
Classes: NullModel, NullRecord, NullRecordClass
Instance Method Summary collapse
-
#initialize(model, association, expected_value) ⇒ AssociationSavedAssertionBase
constructor
A new instance of AssociationSavedAssertionBase.
- #run(context) ⇒ Object
Constructor Details
#initialize(model, association, expected_value) ⇒ AssociationSavedAssertionBase
Returns a new instance of AssociationSavedAssertionBase.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mr/test_helpers.rb', line 67 def initialize(model, association, expected_value) reflection = model.record.association(association).reflection if reflection.macro != :belongs_to raise ArgumentError, "association must be a belongs to" end @expected_value = expected_value || NULL_MODEL # use `record.class` instead of `record_class` here, the configured # `record_class` won't match the actual `record` class because `record` is # a fake record expected_foreign_type = @expected_value.record.class.to_s expected_foreign_key = @expected_value.id @assertions = [ build_assertion(model, reflection.foreign_type, expected_foreign_type), build_assertion(model, reflection.foreign_key, expected_foreign_key) ].compact end |
Instance Method Details
#run(context) ⇒ Object
84 85 86 |
# File 'lib/mr/test_helpers.rb', line 84 def run(context) @assertions.each{ |a| a.run(context) } end |