1 require 'abstract_unit'
2 require 'fixtures/reference_type'
3 require 'fixtures/reference_code'
5 # Testing the find action on composite ActiveRecords with two primary keys
6 class TestFind < Test::Unit::TestCase
7 fixtures :reference_types, :reference_codes
11 :class => ReferenceType,
12 :primary_keys => [:reference_type_id],
15 :class => ReferenceCode,
16 :primary_keys => [:reference_type_id, :reference_code],
19 :class => ReferenceCode,
20 :primary_keys => ['reference_type_id', 'reference_code'],
25 self.class.classes = CLASSES
30 obj = @klass.find(:first)
32 assert_equal @klass, obj.class
38 found = @klass.find(*first_id) # e.g. find(1,1) or find 1,1
40 assert_equal @klass, found.class
41 assert_equal found, @klass.find(found.id)
42 assert_equal found, @klass.find(found.to_param)
46 def test_find_composite_ids
48 found = @klass.find(first_id) # e.g. find([1,1].to_composite_ids)
50 assert_equal @klass, found.class
51 assert_equal found, @klass.find(found.id)
52 assert_equal found, @klass.find(found.to_param)
58 assert_equal first_id_str, @first.to_param.to_s
64 assert_equal found, @klass.find(found.id.to_s) # fails for 2+ keys
69 assert_raise(::ActiveRecord::RecordNotFound) do
70 ReferenceCode.send :find, '999,999'