Sha256: 73a6763089a021f5eb3ae395720071a02892fb34e5351f77cb8dece911cd2f55

Contents?: true

Size: 1.46 KB

Versions: 15

Compression:

Stored size: 1.46 KB

Contents

require_relative 'test_helper'

class MachineWithEventAttributesOnAutosaveTest < BaseTestCase
  def setup
    @vehicle_model = new_model(:vehicle) do
      connection.add_column table_name, :owner_id, :integer
    end
    MachineWithEventAttributesOnAutosaveTest.const_set('Vehicle', @vehicle_model)

    @owner_model = new_model(:owner)
    MachineWithEventAttributesOnAutosaveTest.const_set('Owner', @owner_model)

    machine = StateMachines::Machine.new(@vehicle_model)
    machine.event :ignite do
      transition :parked => :idling
    end

    @owner = @owner_model.create
    @vehicle = @vehicle_model.create(:state => 'parked', :owner_id => @owner.id)
  end

  def test_should_persist_has_one_autosave
    @owner_model.has_one :vehicle, :class_name => 'MachineWithEventAttributesOnAutosaveTest::Vehicle', :autosave => true
    @owner.vehicle.state_event = 'ignite'
    @owner.save

    @vehicle.reload
    assert_equal 'idling', @vehicle.state
  end

  def test_should_persist_has_many_autosave
    @owner_model.has_many :vehicles, :class_name => 'MachineWithEventAttributesOnAutosaveTest::Vehicle', :autosave => true
    @owner.vehicles[0].state_event = 'ignite'
    @owner.save

    @vehicle.reload
    assert_equal 'idling', @vehicle.state
  end

  def teardown
    MachineWithEventAttributesOnAutosaveTest.class_eval do
      remove_const('Vehicle')
      remove_const('Owner')
    end
    ActiveSupport::Dependencies.clear if defined?(ActiveSupport::Dependencies)
    super
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

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