Sha256: ba8d8f66b8e678a8b5b331e539daf54d15fb705b94cb650f3572ff5aa9f8dae1

Contents?: true

Size: 957 Bytes

Versions: 3

Compression:

Stored size: 957 Bytes

Contents

require_relative 'test_helper'

class MachineNestedActionTest < BaseTestCase
  def setup
    @callbacks = []

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

    @record = @model.new(:state => 'parked')
  end

  def test_should_allow_transition_prior_to_creation_if_skipping_action
    record = @record
    @model.before_create { record.ignite(false) }
    result = @record.save

    assert_equal true, result
    assert_equal "idling", @record.state
    @record.reload
    assert_equal "idling", @record.state
  end

  if Mongoid::VERSION !~ /^2\.1\./
    def test_should_allow_transition_after_creation
      record = @record
      @model.after_create { record.ignite }
      result = @record.save

      assert_equal true, result
      assert_equal "idling", @record.state
      @record.reload
      assert_equal "idling", @record.state
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
state_machines-mongoid-0.2.0 test/machine_nested_action_test.rb
state_machines-mongoid-0.1.1 test/machine_nested_action_test.rb
state_machines-mongoid-0.1.0 test/machine_nested_action_test.rb