class ActiveModelTest::MachineWithStateDrivenValidationsTest

Public Instance Methods

setup() click to toggle source
# File test/unit/integrations/active_model_test.rb, line 699
def setup
  @model = new_model do
    include ActiveModel::Validations
    attr_accessor :seatbelt
  end
  
  @machine = StateMachine::Machine.new(@model)
  @machine.state :first_gear, :second_gear do
    validates_presence_of :seatbelt
  end
  @machine.other_states :parked
end
test_should_be_invalid_if_validation_fails_within_state_scope() click to toggle source
# File test/unit/integrations/active_model_test.rb, line 717
def test_should_be_invalid_if_validation_fails_within_state_scope
  record = @model.new(:state => 'first_gear', :seatbelt => nil)
  assert !record.valid?
end
test_should_be_valid_if_validation_fails_outside_state_scope() click to toggle source
# File test/unit/integrations/active_model_test.rb, line 712
def test_should_be_valid_if_validation_fails_outside_state_scope
  record = @model.new(:state => 'parked', :seatbelt => nil)
  assert record.valid?
end
test_should_be_valid_if_validation_succeeds_within_state_scope() click to toggle source
# File test/unit/integrations/active_model_test.rb, line 722
def test_should_be_valid_if_validation_succeeds_within_state_scope
  record = @model.new(:state => 'second_gear', :seatbelt => true)
  assert record.valid?
end