Sha256: 1cb3f8721558951e985e93c21e5a57311303190bdf543ff502d4e3bcccf81bb2

Contents?: true

Size: 1.34 KB

Versions: 14

Compression:

Stored size: 1.34 KB

Contents

require_relative '../../test_helper'

class MachineStateInitializationTest < StateMachinesTest
  def setup
    @klass = Class.new
    @machine = StateMachines::Machine.new(@klass, :state, initial: :parked, initialize: false)

    @object = @klass.new
    @object.state = nil
  end

  def test_should_set_states_if_nil
    @machine.initialize_state(@object)

    assert_equal 'parked', @object.state
  end

  def test_should_set_states_if_empty
    @object.state = ''
    @machine.initialize_state(@object)

    assert_equal 'parked', @object.state
  end

  def test_should_not_set_states_if_not_empty
    @object.state = 'idling'
    @machine.initialize_state(@object)

    assert_equal 'idling', @object.state
  end

  def test_should_set_states_if_not_empty_and_forced
    @object.state = 'idling'
    @machine.initialize_state(@object, force: true)

    assert_equal 'parked', @object.state
  end

  def test_should_not_set_state_if_nil_and_nil_is_valid_state
    @machine.state :initial, value: nil
    @machine.initialize_state(@object)

    assert_nil @object.state
  end

  def test_should_write_to_hash_if_specified
    @machine.initialize_state(@object, to: hash = {})
    assert_equal({ 'state' => 'parked' }, hash)
  end

  def test_should_not_write_to_object_if_writing_to_hash
    @machine.initialize_state(@object, to: {})
    assert_nil @object.state
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
state_machines-0.5.0 test/unit/machine/machine_state_initialization_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-0.2.2/test/unit/machine/machine_state_initialization_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-0.2.2/test/unit/machine/machine_state_initialization_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-0.2.2/test/unit/machine/machine_state_initialization_test.rb
state_machines-0.4.0 test/unit/machine/machine_state_initialization_test.rb
state_machines-0.3.0 test/unit/machine/machine_state_initialization_test.rb
state_machines-0.2.2 test/unit/machine/machine_state_initialization_test.rb
state_machines-0.2.1 test/unit/machine/machine_state_initialization_test.rb
state_machines-0.2.0 test/unit/machine/machine_state_initialization_test.rb
state_machines-0.1.4 test/unit/machine/machine_state_initialization_test.rb
state_machines-0.1.3 test/unit/machine/machine_state_initialization_test.rb
state_machines-0.1.2 test/unit/machine/machine_state_initialization_test.rb
state_machines-0.1.1 test/unit/machine/machine_state_initialization_test.rb
state_machines-0.1.0 test/unit/machine/machine_state_initialization_test.rb