class DataMapperTest::MachineWithDirtyAttributesTest

Public Instance Methods

setup() click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 547
def setup
  @resource = new_resource
  @machine = StateMachine::Machine.new(@resource, :initial => :parked)
  @machine.event :ignite
  @machine.state :idling
  
  @record = @resource.create
  
  @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
  @transition.perform(false)
end
test_should_have_changes_when_loaded_from_database() click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 582
def test_should_have_changes_when_loaded_from_database
  record = @resource.get(@record.id)
  assert record.dirty_attributes.empty?
end
test_should_include_state_in_changed_attributes() click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 559
def test_should_include_state_in_changed_attributes
  assert_equal e = {@resource.properties[:state] => 'idling'}, @record.dirty_attributes
end
test_should_not_reset_changes_on_multiple_transitions() click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 571
def test_should_not_reset_changes_on_multiple_transitions
  transition = StateMachine::Transition.new(@record, @machine, :ignite, :idling, :idling)
  transition.perform(false)
  
  if Gem::Version.new(::DataMapper::VERSION) >= Gem::Version.new('0.10.0')
    assert_equal e = {@resource.properties[:state] => 'parked'}, @record.original_attributes
  else
    assert_equal e = {:state => 'parked'},  @record.original_values
  end
end
test_should_track_attribute_change() click to toggle source
# File test/unit/integrations/data_mapper_test.rb, line 563
def test_should_track_attribute_change
  if Gem::Version.new(::DataMapper::VERSION) >= Gem::Version.new('0.10.0')
    assert_equal e = {@resource.properties[:state] => 'parked'}, @record.original_attributes
  else
    assert_equal e = {:state => 'parked'},  @record.original_values
  end
end