Class: EcfrAttributeHashStrategy
- Inherits:
-
Object
- Object
- EcfrAttributeHashStrategy
- Defined in:
- lib/ecfr/testing/strategies/ecfr_attribute_hash_strategy.rb
Overview
A build strategy that take the initialized factory and returns the attribute hash. The attribute hash or array of attribute hashes can then be passed to the .build method on the Ecfr class being testing to receive a response object.
Instance Method Summary collapse
-
#initialize ⇒ EcfrAttributeHashStrategy
constructor
A new instance of EcfrAttributeHashStrategy.
- #result(evaluation) ⇒ Object
Constructor Details
#initialize ⇒ EcfrAttributeHashStrategy
Returns a new instance of EcfrAttributeHashStrategy.
8 9 10 |
# File 'lib/ecfr/testing/strategies/ecfr_attribute_hash_strategy.rb', line 8 def initialize @strategy = FactoryBot.strategy_by_name(:build).new end |
Instance Method Details
#result(evaluation) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ecfr/testing/strategies/ecfr_attribute_hash_strategy.rb', line 14 def result(evaluation) hsh = {} hsh.merge!(evaluation.object.attributes) if evaluation.object.attributes # handle direct json results like structure that aren't cast to attributes if evaluation.object.respond_to?(:data) && evaluation.object.data hsh[:data] = evaluation.object.data end # handle classes that return metadata key = if evaluation.object.class.respond_to?(:metadata_accessor) && evaluation.object.class. evaluation.object.class. else "metadata" end if evaluation.object.respond_to?(:metadata) && evaluation.object. hsh[key] = evaluation.object..attributes end hsh.deep_stringify_keys end |