spec/unit/target_spec.rb in finite_machine-0.12.0 vs spec/unit/target_spec.rb in finite_machine-0.12.1

- old
+ new

@@ -187,6 +187,39 @@ expect(called).to eq([ 'car save called', 'event save called' ]) end + + it "handles targets responding to :to_hash message" do + stub_const("Serializer", Class.new do + def initialize(data) + @data = data + end + + def write(new_data) + @data.merge!(new_data) + end + + def to_hash + @data + end + alias to_h to_hash + end) + + model = Serializer.new({a: 1, b: 2}) + + fsm = FiniteMachine.new(model) do + initial :a + + event :serialize, :a => :b + + on_after :serialize do |event| + target.write(c: 3) + end + end + + fsm.serialize + + expect(model.to_h).to include({a: 1, b: 2, c: 3}) + end end