1 require 'abstract_unit'
2 require 'fixtures/reference_type'
3 require 'fixtures/reference_code'
4 require 'fixtures/department'
5 require 'fixtures/employee'
7 class TestDelete < Test::Unit::TestCase
8 fixtures :reference_types, :reference_codes, :departments, :employees
12 :class => ReferenceType,
13 :primary_keys => :reference_type_id,
16 :class => ReferenceCode,
17 :primary_keys => [:reference_type_id, :reference_code],
22 self.class.classes = CLASSES
27 #assert @first.destroy
32 def test_destroy_one_via_class
34 assert @klass.destroy(*@first.id)
38 def test_destroy_one_alone_via_class
40 assert @klass.destroy(@first.id)
46 assert @klass.delete(*@first.id) if composite?
50 def test_delete_one_alone
52 assert @klass.delete(@first.id)
58 to_delete = @klass.find(:all)[0..1]
59 assert_equal 2, to_delete.length
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."
75 assert_equal 0, department.employees.size, "After clear and a reload from DB employee count should be 0."
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."
85 assert_equal 1, department.employees.size, "After delete and a reload from DB employee count should be 1."
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)
94 assert_equal 1, reference_type.reference_codes.size, "After deleting 2 records and a reload from DB reference_code count should be 1."