Sha256: 74fc22bbc507c86bc0a4ee33dca42d943ddb0b86f255335daa3e76b3dd3dc9c1

Contents?: true

Size: 1.06 KB

Versions: 29

Compression:

Stored size: 1.06 KB

Contents

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

class TestClone < ActiveSupport::TestCase
  fixtures :reference_types, :reference_codes
  
  CLASSES = {
    :single => {
      :class => ReferenceType,
      :primary_keys => :reference_type_id,
    },
    :dual   => { 
      :class => ReferenceCode,
      :primary_keys => [:reference_type_id, :reference_code],
    },
  }
  
  def setup
    self.class.classes = CLASSES
  end
  
  def test_dup
    testing_with do
      clone = @first.dup
      
      remove_keys = Array(@klass.primary_key).map(&:to_s)
      remove_keys << Array(@klass.primary_key) # Rails 4 adds the PK to the attributes, so we want to remove it as well
      assert_equal(@first.attributes.except(*remove_keys), clone.attributes.except(*remove_keys))

      if composite?
        @klass.primary_key.each do |key|
          assert_nil(clone[key], "Primary key '#{key}' should be nil")
        end
      else
        assert_nil(clone[@klass.primary_key], "Sole primary key should be nil")
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
composite_primary_keys-13.0.1 test/test_dup.rb
composite_primary_keys-13.0.0 test/test_dup.rb
composite_primary_keys-12.0.10 test/test_dup.rb
composite_primary_keys-12.0.9 test/test_dup.rb
composite_primary_keys-12.0.8 test/test_dup.rb
composite_primary_keys-12.0.6 test/test_dup.rb
composite_primary_keys-12.0.5 test/test_dup.rb
composite_primary_keys-12.0.4 test/test_dup.rb
composite_primary_keys-12.0.3 test/test_dup.rb
composite_primary_keys-12.0.2 test/test_dup.rb
composite_primary_keys-11.3.1 test/test_dup.rb
composite_primary_keys-8.1.8 test/test_dup.rb
composite_primary_keys-12.0.1 test/test_dup.rb
composite_primary_keys-12.0.0 test/test_dup.rb
composite_primary_keys-12.0.0.rc5 test/test_dup.rb
composite_primary_keys-12.0.0.rc4 test/test_dup.rb
composite_primary_keys-12.0.0.rc3 test/test_dup.rb
composite_primary_keys-12.0.0.rc2 test/test_dup.rb
composite_primary_keys-12.0.0.rc1 test/test_dup.rb
composite_primary_keys-8.1.7 test/test_dup.rb