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