Sha256: 1c6e81267d8cafc02e8c835ea7e624c14904854dc1cf4de421a7f97bbbfccc39

Contents?: true

Size: 973 Bytes

Versions: 16

Compression:

Stored size: 973 Bytes

Contents

require_relative 'test_helper'

class MachineWithDirtyAttributesAndCustomAttributeTest < BaseTestCase
  def setup
    @model = new_model do
      connection.add_column table_name, :status, :string
    end
    @machine = StateMachines::Machine.new(@model, :status, :initial => :parked)
    @machine.event :ignite
    @machine.state :idling

    @record = @model.create

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

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

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

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

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

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
state_machines-activerecord-0.9.0 test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.8.0 test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.6.0 test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.5.2 test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.5.1 test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.5.0 test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.4.1 test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.4.0 test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.4.0.pre test/machine_with_dirty_attributes_and_custom_attribute_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-activerecord-0.2.0/test/machine_with_dirty_attributes_and_custom_attribute_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-activerecord-0.2.0/test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.3.0 test/machine_with_dirty_attributes_and_custom_attribute_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-activerecord-0.2.0/test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.2.0 test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.1.0 test/machine_with_dirty_attributes_and_custom_attribute_test.rb
state_machines-activerecord-0.0.1 test/machine_with_dirty_attributes_and_custom_attribute_test.rb