class DataMapperTest::MachineWithValidationsTest
Public Instance Methods
setup()
click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 1013 def setup @resource = new_resource @machine = StateMachine::Machine.new(@resource) @machine.state :parked @record = @resource.new end
test_should_auto_prefix_custom_attributes_on_invalidation()
click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 1028 def test_should_auto_prefix_custom_attributes_on_invalidation @machine.invalidate(@record, :event, :invalid) assert_equal ['is invalid'], @record.errors.on(:state_event) end
test_should_be_valid_if_state_is_known()
click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 1042 def test_should_be_valid_if_state_is_known @record.state = 'parked' assert @record.valid? end
test_should_clear_errors_on_reset()
click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 1034 def test_should_clear_errors_on_reset @record.state = 'parked' @record.errors.add(:state, 'is invalid') @machine.reset(@record) assert_nil @record.errors.on(:id) end
test_should_invalidate_using_errors()
click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 1021 def test_should_invalidate_using_errors @record.state = 'parked' @machine.invalidate(@record, :state, :invalid_transition, [[:event, 'park']]) assert_equal ['cannot transition via "park"'], @record.errors.on(:state) end
test_should_not_be_valid_if_state_is_unknown()
click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 1048 def test_should_not_be_valid_if_state_is_unknown @record.state = 'invalid' assert !@record.valid? assert_equal ['is invalid'], @record.errors.on(:state) end