Module: Funes::ProjectionTestHelper
- Defined in:
- app/helpers/funes/projection_test_helper.rb
Overview
Test helper for testing projections in isolation.
Include this module in your test classes to access helper methods that allow you to test individual projection interpretations without needing to process entire event streams.
Instance Method Summary collapse
-
#apply_final_state_based_on(projection_class, previous_state, at = Time.current) ⇒ ActiveModel::Model, ActiveRecord::Base
Test a final_state block in isolation.
-
#build_initial_state_based_on(projection_class, at = Time.current) ⇒ ActiveModel::Model, ActiveRecord::Base
Test an initial_state block in isolation.
-
#interpret_event_based_on(projection_class, event_instance, previous_state, at = Time.current) ⇒ ActiveModel::Model, ActiveRecord::Base
Test a single event interpretation in isolation.
Instance Method Details
#apply_final_state_based_on(projection_class, previous_state, at = Time.current) ⇒ ActiveModel::Model, ActiveRecord::Base
Test a final_state block in isolation.
This method extracts and executes the final_state block from a projection, allowing you to test how the projection transforms state after all event interpretations have been applied.
107 108 109 110 |
# File 'app/helpers/funes/projection_test_helper.rb', line 107 def apply_final_state_based_on(projection_class, previous_state, at = Time.current) projection_class.instance_variable_get(:@interpretations)[:final] .call(previous_state, at) end |
#build_initial_state_based_on(projection_class, at = Time.current) ⇒ ActiveModel::Model, ActiveRecord::Base
Test an initial_state block in isolation.
This method extracts and executes the initial_state block from a projection, allowing you to test how the projection builds its starting state without processing entire event streams.
77 78 79 80 |
# File 'app/helpers/funes/projection_test_helper.rb', line 77 def build_initial_state_based_on(projection_class, at = Time.current) projection_class.instance_variable_get(:@interpretations)[:init] .call(projection_class.instance_variable_get(:@materialization_model), at) end |
#interpret_event_based_on(projection_class, event_instance, previous_state, at = Time.current) ⇒ ActiveModel::Model, ActiveRecord::Base
Test a single event interpretation in isolation.
This method extracts and executes a single interpretation block from a projection, allowing you to test how specific events transform state without processing entire event streams.
49 50 51 52 53 54 |
# File 'app/helpers/funes/projection_test_helper.rb', line 49 def interpret_event_based_on(projection_class, event_instance, previous_state, at = Time.current) at = at.beginning_of_day if at.is_a?(Date) && !at.is_a?(Time) event_at = event_instance.occurred_at || at projection_class.instance_variable_get(:@interpretations)[event_instance.class] .call(previous_state, event_instance, event_at) end |