]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/composite_primary_keys-2.2.2/test/test_find.rb
Allow the format to be selected for note API responses
[rails.git] / vendor / gems / composite_primary_keys-2.2.2 / test / test_find.rb
1 require 'abstract_unit'
2 require 'fixtures/reference_type'
3 require 'fixtures/reference_code'
4
5 # Testing the find action on composite ActiveRecords with two primary keys
6 class TestFind < Test::Unit::TestCase
7   fixtures :reference_types, :reference_codes
8   
9   CLASSES = {
10     :single => {
11       :class => ReferenceType,
12       :primary_keys => [:reference_type_id],
13     },
14     :dual   => { 
15       :class => ReferenceCode,
16       :primary_keys => [:reference_type_id, :reference_code],
17     },
18     :dual_strs   => { 
19       :class => ReferenceCode,
20       :primary_keys => ['reference_type_id', 'reference_code'],
21     },
22   }
23   
24   def setup
25     self.class.classes = CLASSES
26   end
27   
28   def test_find_first
29     testing_with do
30       obj = @klass.find(:first)
31       assert obj
32       assert_equal @klass, obj.class
33     end
34   end
35   
36   def test_find
37     testing_with do
38       found = @klass.find(*first_id) # e.g. find(1,1) or find 1,1
39       assert found
40       assert_equal @klass, found.class
41       assert_equal found, @klass.find(found.id)
42       assert_equal found, @klass.find(found.to_param)
43     end
44   end
45   
46   def test_find_composite_ids
47     testing_with do
48       found = @klass.find(first_id) # e.g. find([1,1].to_composite_ids)
49       assert found
50       assert_equal @klass, found.class
51       assert_equal found, @klass.find(found.id)
52       assert_equal found, @klass.find(found.to_param)
53     end
54   end
55   
56   def test_to_param
57     testing_with do
58       assert_equal first_id_str, @first.to_param.to_s
59     end
60   end
61   
62   def things_to_look_at
63     testing_with do
64       assert_equal found, @klass.find(found.id.to_s) # fails for 2+ keys
65     end
66   end
67   
68   def test_not_found
69     assert_raise(::ActiveRecord::RecordNotFound) do
70       ReferenceCode.send :find, '999,999'
71     end
72   end
73 end