Sha256: 5152c14ee53a6bc31c082feb8ced77d3afabeaaf73e7b27ac24636e583852256

Contents?: true

Size: 1.66 KB

Versions: 54

Compression:

Stored size: 1.66 KB

Contents

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

class TestAttributeMethods < ActiveSupport::TestCase
  fixtures :reference_types, :reference_codes

  def test_read_attribute_with_single_key
    rt = ReferenceType.find(1)
    assert_equal(1, rt.reference_type_id)
    assert_equal('NAME_PREFIX', rt.type_label)
    assert_equal('Name Prefix', rt.abbreviation)
  end

  def test_read_attribute_with_composite_keys
    ref_code = ReferenceCode.find([1, 1])
    assert_equal(1, ref_code.id.first)
    assert_equal(1, ref_code.id.last)
    assert_equal('Mr', ref_code.abbreviation)
  end

  # to_key returns array even for single key
  def test_to_key_with_single_key
    rt = ReferenceType.find(1)
    assert_equal([1], rt.to_key)
  end

  def test_to_key_with_composite_keys
    ref_code = ReferenceCode.find([1, 1])
    assert_equal(1, ref_code.to_key.first)
    assert_equal(1, ref_code.to_key.last)
  end

  def test_to_key_with_single_key_unsaved
    rt = ReferenceType.new
    assert_nil(rt.to_key)
  end

  def test_to_key_with_composite_keys_unsaved
    ref_code = ReferenceCode.new
    assert_nil(ref_code.to_key)
  end

  def test_to_key_with_single_key_destroyed
    rt = ReferenceType.find(1)
    rt.destroy
    assert_equal([1], rt.to_key)
  end

  def test_to_key_with_composite_key_destroyed
    ref_code = ReferenceCode.find([1, 1])
    ref_code.destroy
    assert_equal([1,1], ref_code.to_key)
  end

  def test_id_was
    rt = ReferenceType.find(1)
    rt.id = 2
    assert_equal 1, rt.id_was
    
    ref_code = ReferenceCode.find([1, 1])
    ref_code.id = [1,2]
    assert_equal [1,1], ref_code.id_was
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

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