class SequelTest::MachineWithEventAttributesOnSaveTest
Public Instance Methods
setup()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1148 def setup @model = new_model @machine = StateMachine::Machine.new(@model) @machine.event :ignite do transition :parked => :idling end @record = @model.new @record.state = 'parked' @record.state_event = 'ignite' end
test_should_be_successful_if_event_has_transition()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1190 def test_should_be_successful_if_event_has_transition assert @record.save end
test_should_fail_if_event_has_no_transition()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1175 def test_should_fail_if_event_has_no_transition @record.state = 'idling' assert !@record.save end
test_should_fail_if_event_is_invalid()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1160 def test_should_fail_if_event_is_invalid @record.state_event = 'invalid' assert !@record.save end
test_should_not_run_after_callbacks_with_failures_disabled_if_fails()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1239 def test_should_not_run_after_callbacks_with_failures_disabled_if_fails @model.before_create {|record| false} ran_callback = false @machine.after_transition { ran_callback = true } @record.save assert !ran_callback end
test_should_not_run_after_transitions_within_transaction()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1317 def test_should_not_run_after_transitions_within_transaction @machine.after_transition { self.class.create; raise Sequel::Error::Rollback } begin @record.save rescue Sequel::Error::Rollback end assert_equal 2, @model.count end
test_should_not_run_around_callbacks_with_failures_disabled_if_fails()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1282 def test_should_not_run_around_callbacks_with_failures_disabled_if_fails @model.before_create {|record| false} ran_callback = [false] @machine.around_transition {|block| block.call; ran_callback[0] = true } @record.save assert !ran_callback[0] end
test_should_not_run_around_transition_within_transaction()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1328 def test_should_not_run_around_transition_within_transaction @machine.around_transition {|block| block.call; self.class.create; raise Sequel::Error::Rollback } begin @record.save rescue Sequel::Error::Rollback end assert_equal 2, @model.count end
test_should_not_run_before_transitions_within_transaction()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1271 def test_should_not_run_before_transitions_within_transaction @machine.before_transition { self.class.create; raise Sequel::Error::Rollback } begin @record.save rescue Sequel::Error::Rollback end assert_equal 1, @model.count end
test_should_not_run_failure_callbacks_if_fails()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1250 def test_should_not_run_failure_callbacks_if_fails @model.before_create {|record| false} ran_callback = false @machine.after_failure { ran_callback = true } @record.save assert !ran_callback end
test_should_persist_new_state()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1226 def test_should_persist_new_state @record.save assert_equal 'idling', @record.state end
test_should_raise_exception_when_enabled_if_event_has_no_transition()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1180 def test_should_raise_exception_when_enabled_if_event_has_no_transition @record.state = 'idling' @model.raise_on_save_failure = true if defined?(Sequel::BeforeHookFailed) assert_raise(Sequel::BeforeHookFailed) { @record.save } else assert_raise(Sequel::Error) { @record.save } end end
test_should_raise_exception_when_enabled_if_event_is_invalid()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1165 def test_should_raise_exception_when_enabled_if_event_is_invalid @record.state_event = 'invalid' @model.raise_on_save_failure = true if defined?(Sequel::BeforeHookFailed) assert_raise(Sequel::BeforeHookFailed) { @record.save } else assert_raise(Sequel::Error) { @record.save } end end
test_should_run_after_callbacks()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1231 def test_should_run_after_callbacks ran_callback = false @machine.after_transition { ran_callback = true } @record.save assert ran_callback end
test_should_run_after_transitions_within_transaction()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1301 def test_should_run_after_transitions_within_transaction @machine.after_transition { self.class.create; raise Sequel::Error::Rollback } @record.save assert_equal 0, @model.count end
test_should_run_around_callbacks_after_yield()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1292 def test_should_run_around_callbacks_after_yield ran_callback = [false] @machine.around_transition {|block| block.call; ran_callback[0] = true } @record.save assert ran_callback[0] end
test_should_run_around_callbacks_before_yield()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1210 def test_should_run_around_callbacks_before_yield ran_callback = false @machine.around_transition {|block| ran_callback = true; block.call } @record.save assert ran_callback end
test_should_run_around_callbacks_before_yield_once()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1218 def test_should_run_around_callbacks_before_yield_once around_before_count = 0 @machine.around_transition {|block| around_before_count += 1; block.call } @record.save assert_equal 1, around_before_count end
test_should_run_around_transition_within_transaction()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1309 def test_should_run_around_transition_within_transaction @machine.around_transition {|block| block.call; self.class.create; raise Sequel::Error::Rollback } @record.save assert_equal 0, @model.count end
test_should_run_before_callbacks()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1194 def test_should_run_before_callbacks ran_callback = false @machine.before_transition { ran_callback = true } @record.save assert ran_callback end
test_should_run_before_callbacks_once()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1202 def test_should_run_before_callbacks_once before_count = 0 @machine.before_transition { before_count += 1 } @record.save assert_equal 1, before_count end
test_should_run_failure_callbacks_if_fails()
click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1260 def test_should_run_failure_callbacks_if_fails @model.before_create {|record| false} ran_callback = false @machine.after_failure { ran_callback = true } @record.save assert ran_callback end