Sha256: 4a08a58a41778bf41551b36b23b538d1904462ce48e862d2159f8d861178f4c8

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

require './abstract_unit'

class TestUpdate < ActiveSupport::TestCase
  fixtures :reference_types, :reference_codes
  
  CLASSES = {
    :single => {
      :class => ReferenceType,
      :primary_keys => :reference_type_id,
      :update => { :description => 'RT Desc' },
    },
    :dual   => { 
      :class => ReferenceCode,
      :primary_keys => [:reference_type_id, :reference_code],
      :update => { :description => 'RT Desc' },
    },
  }
  
  def setup
    self.class.classes = CLASSES
  end
  
  def test_setup
    testing_with do
      assert_not_nil @klass_info[:update]
    end
  end
  
  def test_update_attributes
    testing_with do
      assert(@first.update_attributes(@klass_info[:update]))
      assert(@first.reload)
      @klass_info[:update].each_pair do |attr_name, new_value|
        assert_equal(new_value, @first[attr_name])
      end
    end
  end
  
  def test_update_primary_key
    obj = ReferenceCode.find([1,1])
    obj.reference_type_id = 2
    obj.reference_code = 3
    assert(obj.primary_key_changed?)
    assert_equal({:reference_type_id => 1, :reference_code => 1}, obj.primary_key_was)
    assert_equal({:reference_type_id => 2, :reference_code => 3}, obj.ids_hash)
    assert(obj.save)
    assert(obj.reload)
    assert_equal(2, obj.reference_type_id)
    assert_equal(3, obj.reference_code)
    assert_equal({:reference_type_id => 2, :reference_code => 3}, obj.ids_hash)
    assert_equal([2, 3], obj.id)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
composite_primary_keys-4.0.0 test/test_update.rb
composite_primary_keys-4.0.0.beta9 test/test_update.rb
composite_primary_keys-4.0.0.beta8 test/test_update.rb