Sha256: 4c346ffb3f0e8996d06569ee37b1611705e38a8f60226af9fa41f54858437995

Contents?: true

Size: 1.8 KB

Versions: 24

Compression:

Stored size: 1.8 KB

Contents

require 'abstract_unit'
require 'fixtures/reference_type'
require 'fixtures/reference_code'

# Testing the find action on composite ActiveRecords with two primary keys
class TestFind < Test::Unit::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],
    },
    :dual_strs   => { 
      :class => ReferenceCode,
      :primary_keys => ['reference_type_id', 'reference_code'],
    },
  }
  
  def setup
    self.class.classes = CLASSES
  end
  
  def test_find_first
    testing_with do
      obj = @klass.find(:first)
      assert obj
      assert_equal @klass, obj.class
    end
  end
  
  def test_find
    testing_with do
      found = @klass.find(*first_id) # e.g. find(1,1) or find 1,1
      assert found
      assert_equal @klass, found.class
      assert_equal found, @klass.find(found.id)
      assert_equal found, @klass.find(found.to_param)
    end
  end
  
  def test_find_composite_ids
    testing_with do
      found = @klass.find(first_id) # e.g. find([1,1].to_composite_ids)
      assert found
      assert_equal @klass, found.class
      assert_equal found, @klass.find(found.id)
      assert_equal found, @klass.find(found.to_param)
    end
  end
  
  def test_to_param
    testing_with do
      assert_equal first_id_str, @first.to_param.to_s
    end
  end
  
  def things_to_look_at
    testing_with do
      assert_equal found, @klass.find(found.id.to_s) # fails for 2+ keys
    end
  end
  
  def test_not_found
    assert_raise(::ActiveRecord::RecordNotFound) do
      ReferenceCode.send :find, '999,999'
    end
  end
end

Version data entries

24 entries across 24 versions & 3 rubygems

Version Path
mingusbabcock-composite_primary_keys-2.2.2.1 test/test_find.rb
tyler-composite_primary_keys-1.1.0 test/test_find.rb
tyler-composite_primary_keys-1.1.1 test/test_find.rb
tyler-composite_primary_keys-1.1.2 test/test_find.rb
tyler-composite_primary_keys-1.1.3 test/test_find.rb
tyler-composite_primary_keys-1.1.4 test/test_find.rb
composite_primary_keys-1.0.1 test/test_find.rb
composite_primary_keys-0.9.90 test/test_find.rb
composite_primary_keys-1.0.3 test/test_find.rb
composite_primary_keys-1.0.10 test/test_find.rb
composite_primary_keys-0.9.93 test/test_find.rb
composite_primary_keys-1.0.0 test/test_find.rb
composite_primary_keys-1.0.2 test/test_find.rb
composite_primary_keys-0.9.91 test/test_find.rb
composite_primary_keys-0.9.92 test/test_find.rb
composite_primary_keys-1.0.5 test/test_find.rb
composite_primary_keys-1.0.8 test/test_find.rb
composite_primary_keys-2.2.2 test/test_find.rb
composite_primary_keys-1.0.4 test/test_find.rb
composite_primary_keys-2.2.1 test/test_find.rb