class MachineCollectionFireWithTransactionsTest
Public Instance Methods
save()
click to toggle source
# File test/unit/machine_collection_test.rb, line 197 def save @allow_save end
setup()
click to toggle source
# File test/unit/machine_collection_test.rb, line 191 def setup @machines = StateMachine::MachineCollection.new @klass = Class.new do attr_accessor :allow_save def save @allow_save end end StateMachine::Integrations.const_set('Custom', Module.new do include StateMachine::Integrations::Base attr_reader :rolled_back def transaction(object) @rolled_back = yield end end) # First machine @machines[:state] = @state = StateMachine::Machine.new(@klass, :state, :initial => :parked, :action => :save, :integration => :custom) @state.event :ignite do transition :parked => :idling end # Second machine @machines[:alarm_state] = @alarm_state = StateMachine::Machine.new(@klass, :alarm_state, :initial => :active, :action => :save, :namespace => 'alarm', :integration => :custom) @alarm_state.event :disable do transition :active => :off end @object = @klass.new end
teardown()
click to toggle source
# File test/unit/machine_collection_test.rb, line 258 def teardown StateMachine::Integrations.send(:remove_const, 'Custom') end
test_should_not_rollback_if_successful()
click to toggle source
# File test/unit/machine_collection_test.rb, line 227 def test_should_not_rollback_if_successful @object.allow_save = true assert @machines.fire_events(@object, :ignite, :disable_alarm) assert_equal true, @state.rolled_back assert_nil @alarm_state.rolled_back assert_equal 'idling', @object.state assert_equal 'off', @object.alarm_state end
test_should_rollback_if_not_successful()
click to toggle source
# File test/unit/machine_collection_test.rb, line 237 def test_should_rollback_if_not_successful @object.allow_save = false assert !@machines.fire_events(@object, :ignite, :disable_alarm) assert_equal false, @state.rolled_back assert_nil @alarm_state.rolled_back assert_equal 'parked', @object.state assert_equal 'active', @object.alarm_state end
test_should_run_failure_callbacks_if_not_successful()
click to toggle source
# File test/unit/machine_collection_test.rb, line 247 def test_should_run_failure_callbacks_if_not_successful @object.allow_save = false @machines[:state].after_failure {@state_failure_run = true} @machines[:alarm_state].after_failure {@alarm_state_failure_run = true} assert !@machines.fire_events(@object, :ignite, :disable_alarm) assert @state_failure_run assert @alarm_state_failure_run end
transaction(object) { || ... }
click to toggle source
# File test/unit/machine_collection_test.rb, line 207 def transaction(object) @rolled_back = yield end