Sha256: 961744c7556b1a18e5e0690a45de055821dd4ac9d4ccacfc95913319fad14fa8

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

require_relative 'test_helper'

class MachineWithInitializedStateTest < BaseTestCase
  def setup
    @model = new_model
    @machine = StateMachines::Machine.new(@model, :initial => :parked)
    @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 = lambda { :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_using_create_with
    record = @model.create_with(state: 'idling').new

    assert_equal 'idling', record.state
  end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
state_machines-activerecord-0.9.0 test/machine_with_initialized_state_test.rb
state_machines-activerecord-0.8.0 test/machine_with_initialized_state_test.rb
state_machines-activerecord-0.6.0 test/machine_with_initialized_state_test.rb
state_machines-activerecord-0.5.2 test/machine_with_initialized_state_test.rb