class DataMapperTest::MachineWithStateDrivenValidationsTest

Public Instance Methods

setup() click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 1077
def setup
  @resource = resource = new_resource do
    attr_accessor :seatbelt
  end
  
  @machine = StateMachine::Machine.new(@resource)
  @machine.state :first_gear, :second_gear do
    if resource.respond_to?(:validates_presence_of)
      validates_presence_of :seatbelt
    else
      validates_present :seatbelt
    end
  end
  @machine.other_states :parked
end
test_should_be_invalid_if_validation_fails_within_state_scope() click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 1098
def test_should_be_invalid_if_validation_fails_within_state_scope
  record = @resource.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/data_mapper_test.rb, line 1093
def test_should_be_valid_if_validation_fails_outside_state_scope
  record = @resource.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/data_mapper_test.rb, line 1103
def test_should_be_valid_if_validation_succeeds_within_state_scope
  record = @resource.new(:state => 'second_gear', :seatbelt => true)
  assert record.valid?
end