Sha256: 8123e0d8b505e7aeb35102c5ad34a08a75d5ce279a0252100466362371e9e845

Contents?: true

Size: 933 Bytes

Versions: 2

Compression:

Stored size: 933 Bytes

Contents

require 'helper'
require_relative './machine_template'

class TestFireEventMachine < Test::Unit::TestCase
  def setup
    @record  = MachineTestSubject.new
    @machine = MachineTestSubject.get_state_machine
    @event   = @machine.events_for(@record.current_state).first
    assert_not_nil @event
  end

  test 'fire_event returns true if state transition was successful' do
    @machine.stubs(:transition_to_new_state).returns(:closed)

    assert_equal true, @machine.fire_event(@event, @record, false)
  end

  test 'fire_event returns false if state transition was unsuccessful' do
    @machine.stubs(:transition_to_new_state).returns(false)

    assert_equal false, @machine.fire_event(@event, @record, false)
  end

  test 'fire_event returns false if state transition raises' do
    @machine.stubs(:transition_to_new_state).raises(StandardError)

    assert_equal false, @machine.fire_event(@event, @record, false)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
transitions-1.0.0 test/machine/test_fire_event_machine.rb
transitions-0.2.1 test/machine/test_fire_event_machine.rb