1 require 'abstract_unit'
\r
2 require 'fixtures/reference_type'
\r
3 require 'fixtures/reference_code'
\r
4 require 'fixtures/department'
\r
5 require 'fixtures/employee'
\r
7 class TestDelete < Test::Unit::TestCase
\r
8 fixtures :reference_types, :reference_codes, :departments, :employees
\r
12 :class => ReferenceType,
\r
13 :primary_keys => :reference_type_id,
\r
16 :class => ReferenceCode,
\r
17 :primary_keys => [:reference_type_id, :reference_code],
\r
22 self.class.classes = CLASSES
\r
25 def test_destroy_one
\r
27 #assert @first.destroy
\r
32 def test_destroy_one_via_class
\r
34 assert @klass.destroy(*@first.id)
\r
38 def test_destroy_one_alone_via_class
\r
40 assert @klass.destroy(@first.id)
\r
46 assert @klass.delete(*@first.id) if composite?
\r
50 def test_delete_one_alone
\r
52 assert @klass.delete(@first.id)
\r
56 def test_delete_many
\r
58 to_delete = @klass.find(:all)[0..1]
\r
59 assert_equal 2, to_delete.length
\r
69 def test_clear_association
\r
70 department = Department.find(1,1)
\r
71 assert_equal 2, department.employees.size, "Before clear employee count should be 2."
\r
72 department.employees.clear
\r
73 assert_equal 0, department.employees.size, "After clear employee count should be 0."
\r
75 assert_equal 0, department.employees.size, "After clear and a reload from DB employee count should be 0."
\r
78 def test_delete_association
\r
79 department = Department.find(1,1)
\r
80 assert_equal 2, department.employees.size , "Before delete employee count should be 2."
\r
81 first_employee = department.employees[0]
\r
82 department.employees.delete(first_employee)
\r
83 assert_equal 1, department.employees.size, "After delete employee count should be 1."
\r
85 assert_equal 1, department.employees.size, "After delete and a reload from DB employee count should be 1."
\r
88 def test_delete_records_for_has_many_association_with_composite_primary_key
\r
89 reference_type = ReferenceType.find(1)
\r
90 codes_to_delete = reference_type.reference_codes[0..1]
\r
91 assert_equal 3, reference_type.reference_codes.size, "Before deleting records reference_code count should be 3."
\r
92 reference_type.reference_codes.delete_records(codes_to_delete)
\r
93 reference_type.reload
\r
94 assert_equal 1, reference_type.reference_codes.size, "After deleting 2 records and a reload from DB reference_code count should be 1."
\r