Sha256: cd5faaa712284dcf9da9282ef0b470bee11f1440867f1c31ef54e73cc47bb861

Contents?: true

Size: 902 Bytes

Versions: 14

Compression:

Stored size: 902 Bytes

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
      assert_equal(@first.attributes.except(*remove_keys), clone.attributes)

      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

14 entries across 14 versions & 1 rubygems

Version Path
composite_primary_keys-5.0.14 test/test_dup.rb
composite_primary_keys-5.0.13 test/test_dup.rb
composite_primary_keys-5.0.12 test/test_dup.rb
composite_primary_keys-5.0.11 test/test_dup.rb
composite_primary_keys-5.0.10 test/test_dup.rb
composite_primary_keys-5.0.9 test/test_dup.rb
composite_primary_keys-5.0.8 test/test_dup.rb
composite_primary_keys-5.0.6 test/test_dup.rb
composite_primary_keys-5.0.5 test/test_dup.rb
composite_primary_keys-5.0.4 test/test_dup.rb
composite_primary_keys-5.0.2 test/test_dup.rb
composite_primary_keys-5.0.1 test/test_dup.rb
composite_primary_keys-5.0.0 test/test_dup.rb
composite_primary_keys-5.0.0.rc1 test/test_dup.rb