Sha256: 01c92c22eb33ddb54ce308c6c2fd5c79ada1acb49d7c50fbec6fd7db52de8bff

Contents?: true

Size: 937 Bytes

Versions: 17

Compression:

Stored size: 937 Bytes

Contents

require_relative 'test_helper'

class MachineWithInitializedStateTest < BaseTestCase
  def setup
    @model = new_model
    @machine = StateMachines::Machine.new(@model, initial: :parked, integration: :active_model)
    @machine.state :idling
  end

  def test_should_allow_nil_initial_state_when_static
    @machine.state nil

    record = @model.new(state: nil)
    assert_nil record.state
  end

  def test_should_allow_nil_initial_state_when_dynamic
    @machine.state nil

    @machine.initial_state = -> { :parked }
    record = @model.new(state: nil)
    assert_nil record.state
  end

  def test_should_allow_different_initial_state_when_static
    record = @model.new(state: 'idling')
    assert_equal 'idling', record.state
  end

  def test_should_allow_different_initial_state_when_dynamic
    @machine.initial_state = -> { :parked }
    record = @model.new(state: 'idling')
    assert_equal 'idling', record.state
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
state_machines-activemodel-0.9.0 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.8.0 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.7.1 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.7.0 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.6.0 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.5.1 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.5.0 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.4.1 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.4.0 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.4.0.pre test/machine_with_initialized_state_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-activemodel-0.1.2/test/machine_with_initialized_state_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-activemodel-0.1.2/test/machine_with_initialized_state_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-activemodel-0.1.2/test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.3.0 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.2.0 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.1.2 test/machine_with_initialized_state_test.rb
state_machines-activemodel-0.1.1 test/machine_with_initialized_state_test.rb