Sha256: 73a26124e1b0aa012ddeeace4430839b612f3eb7e641788ff4c1709000fd7dfc

Contents?: true

Size: 942 Bytes

Versions: 13

Compression:

Stored size: 942 Bytes

Contents

require_relative 'test_helper'

class MachineWithDirtyAttributesTest < BaseTestCase
  def setup
    @model = new_model do
      include ActiveModel::Dirty
      define_attribute_methods [:state]
    end
    @machine = StateMachines::Machine.new(@model, initial: :parked)
    @machine.event :ignite
    @machine.state :idling

    @record = @model.create

    @transition = StateMachines::Transition.new(@record, @machine, :ignite, :parked, :idling)
    @transition.perform
  end

  def test_should_include_state_in_changed_attributes
    assert_equal %w(state), @record.changed
  end

  def test_should_track_attribute_change
    assert_equal %w(parked idling), @record.changes['state']
  end

  def test_should_not_reset_changes_on_multiple_transitions
    transition = StateMachines::Transition.new(@record, @machine, :ignite, :idling, :idling)
    transition.perform

    assert_equal %w(parked idling), @record.changes['state']
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
state_machines-activemodel-0.5.0 test/machine_with_dirty_attributes_test.rb
state_machines-activemodel-0.4.1 test/machine_with_dirty_attributes_test.rb
state_machines-activemodel-0.4.0 test/machine_with_dirty_attributes_test.rb
state_machines-activemodel-0.4.0.pre test/machine_with_dirty_attributes_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-activemodel-0.1.2/test/machine_with_dirty_attributes_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-activemodel-0.1.2/test/machine_with_dirty_attributes_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-activemodel-0.1.2/test/machine_with_dirty_attributes_test.rb
state_machines-activemodel-0.3.0 test/machine_with_dirty_attributes_test.rb
state_machines-activemodel-0.2.0 test/machine_with_dirty_attributes_test.rb
state_machines-activemodel-0.1.2 test/machine_with_dirty_attributes_test.rb
state_machines-activemodel-0.1.1 test/machine_with_dirty_attributes_test.rb
state_machines-activemodel-0.1.0 test/machine_with_dirty_attributes_test.rb
state_machines-activemodel-0.0.3 test/machine_with_dirty_attributes_test.rb