class SequelTest::MachineWithEventAttributesOnValidationTest

Public Instance Methods

setup() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1031
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 1055
def test_should_be_successful_if_event_has_transition
  assert @record.valid?
end
test_should_fail_if_event_has_no_transition() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1049
def test_should_fail_if_event_has_no_transition
  @record.state = 'idling'
  assert !@record.valid?
  assert_equal ['state_event cannot transition when idling'], @record.errors.full_messages
end
test_should_fail_if_event_is_invalid() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1043
def test_should_fail_if_event_is_invalid
  @record.state_event = 'invalid'
  assert !@record.valid?
  assert_equal ['state_event is invalid'], @record.errors.full_messages
end
test_should_not_run_after_callbacks() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1080
def test_should_not_run_after_callbacks
  ran_callback = false
  @machine.after_transition { ran_callback = true }
  
  @record.valid?
  assert !ran_callback
end
test_should_not_run_after_callbacks_with_failures_disabled_if_validation_fails() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1088
def test_should_not_run_after_callbacks_with_failures_disabled_if_validation_fails
  @model.class_eval do
    attr_accessor :seatbelt
    validates_presence_of :seatbelt
  end
  
  ran_callback = false
  @machine.after_transition { ran_callback = true }
  
  @record.valid?
  assert !ran_callback
end
test_should_not_run_around_callbacks_after_yield() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1114
def test_should_not_run_around_callbacks_after_yield
  ran_callback = [false]
  @machine.around_transition {|block| block.call; ran_callback[0] = true }
  
  @record.valid?
  assert !ran_callback[0]
end
test_should_not_run_around_callbacks_after_yield_with_failures_disabled_if_validation_fails() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1122
def test_should_not_run_around_callbacks_after_yield_with_failures_disabled_if_validation_fails
  @model.class_eval do
    attr_accessor :seatbelt
    validates_presence_of :seatbelt
  end
  
  ran_callback = [false]
  @machine.around_transition {|block| block.call; ran_callback[0] = true }
  
  @record.valid?
  assert !ran_callback[0]
end
test_should_not_run_before_transitions_within_transaction() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1135
def test_should_not_run_before_transitions_within_transaction
  @machine.before_transition { self.class.create; raise Sequel::Error::Rollback }
  
  begin
    @record.valid?
  rescue Sequel::Error::Rollback
  end
  
  assert_equal 1, @model.count
end
test_should_persist_new_state() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1075
def test_should_persist_new_state
  @record.valid?
  assert_equal 'idling', @record.state
end
test_should_run_around_callbacks_before_yield() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1067
def test_should_run_around_callbacks_before_yield
  ran_callback = false
  @machine.around_transition {|block| ran_callback = true; block.call }
  
  @record.valid?
  assert ran_callback
end
test_should_run_before_callbacks() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1059
def test_should_run_before_callbacks
  ran_callback = false
  @machine.before_transition { ran_callback = true }
  
  @record.valid?
  assert ran_callback
end
test_should_run_failure_callbacks_if_validation_fails() click to toggle source
# File test/unit/integrations/sequel_test.rb, line 1101
def test_should_run_failure_callbacks_if_validation_fails
  @model.class_eval do
    attr_accessor :seatbelt
    validates_presence_of :seatbelt
  end
  
  ran_callback = false
  @machine.after_failure { ran_callback = true }
  
  @record.valid?
  assert ran_callback
end