Sha256: 6eb5830ada819001f38ac6c5007c1809776764e48fdeecb0b3b50666de9525a2

Contents?: true

Size: 1.45 KB

Versions: 9

Compression:

Stored size: 1.45 KB

Contents

require File.expand_path('../abstract_unit', __FILE__)

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

9 entries across 9 versions & 1 rubygems

Version Path
composite_primary_keys-5.0.6 test/test_update.rb
composite_primary_keys-5.0.5 test/test_update.rb
composite_primary_keys-5.0.4 test/test_update.rb
composite_primary_keys-5.0.2 test/test_update.rb
composite_primary_keys-5.0.1 test/test_update.rb
composite_primary_keys-5.0.0 test/test_update.rb
composite_primary_keys-5.0.0.rc1 test/test_update.rb
composite_primary_keys-4.1.2 test/test_update.rb
composite_primary_keys-4.1.1 test/test_update.rb