Class: EntityProjection::Fixtures::Projection
- Inherits:
-
Object
- Object
- EntityProjection::Fixtures::Projection
- Includes:
- Initializer, TestBench::Fixture
- Defined in:
- lib/entity_projection/fixtures/projection.rb
Class Method Summary collapse
- .build(projection, event, &action) ⇒ Object
- .printed_attribute_name(event_time_attribute, entity_time_attribute) ⇒ Object
Instance Method Summary collapse
- #assert_attributes_copied(attribute_names = nil) ⇒ Object
- #assert_transformed_and_copied(attribute_name, &transform) ⇒ Object
- #call ⇒ Object
- #entity_class ⇒ Object
- #event_class ⇒ Object
Class Method Details
.build(projection, event, &action) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/entity_projection/fixtures/projection.rb', line 17 def self.build(projection, event, &action) entity = projection.entity control_entity = entity.clone new(projection, control_entity, entity, event, action) end |
.printed_attribute_name(event_time_attribute, entity_time_attribute) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/entity_projection/fixtures/projection.rb', line 82 def self.printed_attribute_name(event_time_attribute, entity_time_attribute) if event_time_attribute == entity_time_attribute return event_time_attribute.to_s else return "#{event_time_attribute} => #{entity_time_attribute}" end end |
Instance Method Details
#assert_attributes_copied(attribute_names = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/entity_projection/fixtures/projection.rb', line 44 def assert_attributes_copied(attribute_names=nil) fixture( Schema::Fixtures::Equality, event, entity, attribute_names, ignore_class: true, print_title_context: false, attributes_context_name: 'Copied' ) end |
#assert_transformed_and_copied(attribute_name, &transform) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/entity_projection/fixtures/projection.rb', line 56 def assert_transformed_and_copied(attribute_name, &transform) if attribute_name.is_a?(Hash) event_attribute_name = attribute_name.keys.first entity_attribute_name = attribute_name.values.first else event_attribute_name = attribute_name entity_attribute_name = attribute_name end event_attribute_value = event.public_send(event_attribute_name) entity_attribute_value = entity.public_send(entity_attribute_name) context "Transformed and Copied" do detail "#{event_class.name.split('::').last} Value (#{event_attribute_value.class.name}): #{event_attribute_value.inspect}" detail "#{entity_class.name.split('::').last} Value (#{entity_attribute_value.class.name}): #{entity_attribute_value.inspect}" printed_attribute_name = self.class.printed_attribute_name(event_attribute_name, entity_attribute_name) transformed_event_value = transform.call(event_attribute_value) test printed_attribute_name do assert(transformed_event_value == entity_attribute_value) end end end |
#call ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/entity_projection/fixtures/projection.rb', line 24 def call projection_type = projection.class.name.split('::').last entity_type = entity.class.name.split('::').last event_type = event. detail "Projection Class: #{projection.class.name}" context "Apply #{event.} to #{entity.class.type}" do detail "Event Class: #{event.class.name}" detail "Entity Class: #{entity.class.name}" projection.(event) if not action.nil? action.call(self) end end end |
#entity_class ⇒ Object
7 8 9 |
# File 'lib/entity_projection/fixtures/projection.rb', line 7 def entity_class entity.class end |
#event_class ⇒ Object
11 12 13 |
# File 'lib/entity_projection/fixtures/projection.rb', line 11 def event_class event.class end |