Sha256: 0925aca709ae420ded874f19e396fd69c3655b3c244b9a40e2acfdb728a67f85

Contents?: true

Size: 1012 Bytes

Versions: 3

Compression:

Stored size: 1012 Bytes

Contents

require_relative 'test_helper'

class MachineWithFailedAfterCallbacksTest < BaseTestCase
  def setup
    @callbacks = []

    @model = new_model
    @machine = StateMachines::Machine.new(@model)
    @machine.state :parked, :idling
    @machine.event :ignite
    @machine.after_transition {@callbacks << :after_1; false}
    @machine.after_transition {@callbacks << :after_2}
    @machine.around_transition {|block| @callbacks << :around_before; block.call; @callbacks << :around_after}

    @record = @model.new(:state => 'parked')
    @transition = StateMachines::Transition.new(@record, @machine, :ignite, :parked, :idling)
    @result = @transition.perform
  end

  def test_should_be_successful
    assert @result
  end

  def test_should_change_current_state
    assert_equal 'idling', @record.state
  end

  def test_should_save_record
    assert !@record.new_record?
  end

  def test_should_not_run_further_after_callbacks
    assert_equal [:around_before, :around_after, :after_1], @callbacks
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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