]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/composite_primary_keys-2.2.2/test/test_delete.rb
Merge branch 'master' into openid
[rails.git] / vendor / gems / composite_primary_keys-2.2.2 / test / test_delete.rb
1 require 'abstract_unit'
2 require 'fixtures/reference_type'
3 require 'fixtures/reference_code'
4 require 'fixtures/department'
5 require 'fixtures/employee'
6
7 class TestDelete < Test::Unit::TestCase
8   fixtures :reference_types, :reference_codes, :departments, :employees
9   
10   CLASSES = {
11     :single => {
12       :class => ReferenceType,
13       :primary_keys => :reference_type_id,
14     },
15     :dual   => { 
16       :class => ReferenceCode,
17       :primary_keys => [:reference_type_id, :reference_code],
18     },
19   }
20   
21   def setup
22     self.class.classes = CLASSES
23   end
24   
25   def test_destroy_one
26     testing_with do
27       #assert @first.destroy
28       assert true
29     end
30   end
31   
32   def test_destroy_one_via_class
33     testing_with do
34       assert @klass.destroy(*@first.id)
35     end
36   end
37   
38   def test_destroy_one_alone_via_class
39     testing_with do
40       assert @klass.destroy(@first.id)
41     end
42   end
43   
44   def test_delete_one
45     testing_with do
46       assert @klass.delete(*@first.id) if composite?
47     end
48   end
49   
50   def test_delete_one_alone
51     testing_with do
52       assert @klass.delete(@first.id)
53     end
54   end
55   
56   def test_delete_many
57     testing_with do
58       to_delete = @klass.find(:all)[0..1]
59       assert_equal 2, to_delete.length
60     end
61   end
62   
63   def test_delete_all
64     testing_with do
65       @klass.delete_all
66     end
67   end
68
69   def test_clear_association
70       department = Department.find(1,1)
71       assert_equal 2, department.employees.size, "Before clear employee count should be 2."
72       department.employees.clear
73       assert_equal 0, department.employees.size, "After clear employee count should be 0."
74       department.reload
75       assert_equal 0, department.employees.size, "After clear and a reload from DB employee count should be 0."
76   end
77
78   def test_delete_association
79       department = Department.find(1,1)
80       assert_equal 2, department.employees.size , "Before delete employee count should be 2."
81       first_employee = department.employees[0]
82       department.employees.delete(first_employee)
83       assert_equal 1, department.employees.size, "After delete employee count should be 1."
84       department.reload
85       assert_equal 1, department.employees.size, "After delete and a reload from DB employee count should be 1."
86   end
87
88   def test_delete_records_for_has_many_association_with_composite_primary_key
89       reference_type  = ReferenceType.find(1)
90       codes_to_delete = reference_type.reference_codes[0..1]
91       assert_equal 3, reference_type.reference_codes.size, "Before deleting records reference_code count should be 3."
92       reference_type.reference_codes.delete_records(codes_to_delete)
93       reference_type.reload
94       assert_equal 1, reference_type.reference_codes.size, "After deleting 2 records and a reload from DB reference_code count should be 1."
95   end
96 end