composite_primary_keys 3.1.11 → 4.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/History.txt +6 -8
  2. data/lib/composite_primary_keys.rb +53 -36
  3. data/lib/composite_primary_keys/associations/association.rb +23 -0
  4. data/lib/composite_primary_keys/associations/association_scope.rb +67 -0
  5. data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +31 -121
  6. data/lib/composite_primary_keys/associations/has_many_association.rb +27 -66
  7. data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +22 -0
  8. data/lib/composite_primary_keys/associations/join_dependency/join_part.rb +39 -0
  9. data/lib/composite_primary_keys/associations/preloader/association.rb +61 -0
  10. data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +13 -0
  11. data/lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb +46 -0
  12. data/lib/composite_primary_keys/attribute_methods/dirty.rb +30 -0
  13. data/lib/composite_primary_keys/attribute_methods/read.rb +88 -0
  14. data/lib/composite_primary_keys/attribute_methods/write.rb +33 -0
  15. data/lib/composite_primary_keys/base.rb +18 -70
  16. data/lib/composite_primary_keys/composite_predicates.rb +53 -0
  17. data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +6 -4
  18. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +19 -41
  19. data/lib/composite_primary_keys/fixtures.rb +19 -6
  20. data/lib/composite_primary_keys/persistence.rb +32 -13
  21. data/lib/composite_primary_keys/relation.rb +23 -16
  22. data/lib/composite_primary_keys/relation/calculations.rb +48 -0
  23. data/lib/composite_primary_keys/relation/finder_methods.rb +117 -0
  24. data/lib/composite_primary_keys/relation/query_methods.rb +24 -0
  25. data/lib/composite_primary_keys/validations/uniqueness.rb +19 -23
  26. data/lib/composite_primary_keys/version.rb +5 -5
  27. data/test/connections/native_mysql/connection.rb +1 -1
  28. data/test/fixtures/articles.yml +1 -0
  29. data/test/fixtures/products.yml +2 -4
  30. data/test/fixtures/readings.yml +1 -0
  31. data/test/fixtures/suburbs.yml +1 -4
  32. data/test/fixtures/users.yml +1 -0
  33. data/test/test_associations.rb +61 -63
  34. data/test/test_attributes.rb +16 -21
  35. data/test/test_create.rb +3 -3
  36. data/test/test_delete.rb +87 -84
  37. data/test/{test_clone.rb → test_dup.rb} +8 -5
  38. data/test/test_exists.rb +22 -10
  39. data/test/test_habtm.rb +0 -74
  40. data/test/test_ids.rb +2 -1
  41. data/test/test_miscellaneous.rb +2 -2
  42. data/test/test_polymorphic.rb +1 -1
  43. data/test/test_suite.rb +1 -1
  44. data/test/test_update.rb +3 -3
  45. metadata +76 -75
  46. data/lib/composite_primary_keys/association_preload.rb +0 -158
  47. data/lib/composite_primary_keys/associations.rb +0 -155
  48. data/lib/composite_primary_keys/associations/association_proxy.rb +0 -33
  49. data/lib/composite_primary_keys/associations/has_one_association.rb +0 -27
  50. data/lib/composite_primary_keys/associations/through_association_scope.rb +0 -103
  51. data/lib/composite_primary_keys/attribute_methods.rb +0 -84
  52. data/lib/composite_primary_keys/calculations.rb +0 -31
  53. data/lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb +0 -21
  54. data/lib/composite_primary_keys/connection_adapters/oracle_adapter.rb +0 -15
  55. data/lib/composite_primary_keys/connection_adapters/oracle_enhanced_adapter.rb +0 -17
  56. data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +0 -15
  57. data/lib/composite_primary_keys/finder_methods.rb +0 -123
  58. data/lib/composite_primary_keys/primary_key.rb +0 -19
  59. data/lib/composite_primary_keys/query_methods.rb +0 -24
  60. data/lib/composite_primary_keys/read.rb +0 -25
  61. data/lib/composite_primary_keys/reflection.rb +0 -37
  62. data/lib/composite_primary_keys/write.rb +0 -18
@@ -0,0 +1,24 @@
1
+ module CompositePrimaryKeys
2
+ module ActiveRecord
3
+ module QueryMethods
4
+ def reverse_order
5
+ order_clause = arel.order_clauses
6
+
7
+ # CPK
8
+ # order = order_clause.empty? ?
9
+ # "#{table_name}.#{primary_key} DESC" :
10
+ # reverse_sql_order(order_clause).join(', ')
11
+
12
+ order = unless order_clause.empty?
13
+ reverse_sql_order(order_clause).join(', ')
14
+ else
15
+ klass.primary_key.map do |key|
16
+ "#{table_name}.#{key} DESC"
17
+ end.join(", ")
18
+ end
19
+
20
+ except(:order).order(Arel.sql(order))
21
+ end
22
+ end
23
+ end
24
+ end
@@ -3,39 +3,35 @@ module ActiveRecord
3
3
  class UniquenessValidator
4
4
  def validate_each(record, attribute, value)
5
5
  finder_class = find_finder_class_for(record)
6
- table = finder_class.unscoped
6
+ table = finder_class.arel_table
7
7
 
8
- table_name = record.class.quoted_table_name
8
+ coder = record.class.serialized_attributes[attribute.to_s]
9
9
 
10
- if value && record.class.serialized_attributes.key?(attribute.to_s)
11
- value = YAML.dump value
10
+ if value && coder
11
+ value = coder.dump value
12
12
  end
13
13
 
14
- sql, params = mount_sql_and_params(finder_class, table_name, attribute, value)
14
+ relation = build_relation(finder_class, table, attribute, value)
15
+ # CPK
16
+ # relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.send(:id))) if record.persisted?
17
+ if record.persisted?
18
+ not_eq_conditions = Array(finder_class.primary_key).zip(Array(record.send(:id))).map do |name, value|
19
+ table[name.to_sym].not_eq(value)
20
+ end
15
21
 
16
- relation = table.where(sql, *params)
22
+ condition = not_eq_conditions.shift
23
+ not_eq_conditions.each do |not_eq_condition|
24
+ condition = condition.or(not_eq_conditions)
25
+ end
26
+ relation = relation.and(condition)
27
+ end
17
28
 
18
29
  Array.wrap(options[:scope]).each do |scope_item|
19
30
  scope_value = record.send(scope_item)
20
- relation = relation.where(scope_item => scope_value)
21
- end
22
-
23
- if record.persisted?
24
- # CPK
25
- if record.composite?
26
- predicate = nil
27
- record.ids_hash.each do |key, value|
28
- neq = relation.table[key].not_eq(value)
29
- predicate = predicate ? predicate.or(neq) : neq
30
- end
31
- relation = relation.where(predicate)
32
- else
33
- # TODO : This should be in Arel
34
- relation = relation.where("#{record.class.quoted_table_name}.#{record.class.primary_key} <> ?", record.send(:id))
35
- end
31
+ relation = relation.and(table[scope_item].eq(scope_value))
36
32
  end
37
33
 
38
- if relation.exists?
34
+ if finder_class.unscoped.where(relation).exists?
39
35
  record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
40
36
  end
41
37
  end
@@ -1,8 +1,8 @@
1
1
  module CompositePrimaryKeys
2
- module VERSION #:nodoc:
3
- MAJOR = 3
4
- MINOR = 1
5
- TINY = 11
6
- STRING = [MAJOR, MINOR, TINY].join('.')
2
+ module VERSION
3
+ MAJOR = 4
4
+ MINOR = 0
5
+ TINY = 0
6
+ STRING = [MAJOR, MINOR, TINY, 'beta1'].join('.')
7
7
  end
8
8
  end
@@ -7,7 +7,7 @@ def connection_string
7
7
  options['u'] = SPEC['username'] if SPEC['username']
8
8
  options['p'] = SPEC['password'] if SPEC['password']
9
9
  options['S'] = SPEC['sock'] if SPEC['sock']
10
- options.map { |key, value| "-#{key} #{value}" }.join(" ")
10
+ options.map { |key, value| "-#{key}#{value}" }.join(" ")
11
11
  end
12
12
 
13
13
  # Adapter config setup in locals/database_connections.rb
@@ -1,6 +1,7 @@
1
1
  first:
2
2
  id: 1
3
3
  name: Article One
4
+
4
5
  second:
5
6
  id: 2
6
7
  name: Article Two
@@ -1,9 +1,7 @@
1
1
  first_product:
2
2
  id: 1
3
3
  name: Product One
4
+
4
5
  second_product:
5
6
  id: 2
6
- name: Product Two
7
- third_product:
8
- id: 3
9
- name: Product Three
7
+ name: Product Two
@@ -3,6 +3,7 @@ santiago_first:
3
3
  user_id: 1
4
4
  article_id: 1
5
5
  rating: 4
6
+
6
7
  santiago_second:
7
8
  id: 2
8
9
  user_id: 1
@@ -6,7 +6,4 @@ second:
6
6
  city_id: 2
7
7
  suburb_id: 1
8
8
  name: Second Suburb
9
- no_mcdonalds:
10
- city_id: 1
11
- suburb_id: 2
12
- name: Third Suburb
9
+
@@ -1,6 +1,7 @@
1
1
  santiago:
2
2
  id: 1
3
3
  name: Santiago
4
+
4
5
  drnic:
5
6
  id: 2
6
7
  name: Dr Nic
@@ -6,15 +6,20 @@ class TestAssociations < ActiveSupport::TestCase
6
6
  :departments, :memberships
7
7
 
8
8
  def test_count
9
- assert_equal(3, Product.count(:include => :product_tariffs))
9
+ assert_equal(2, Product.count(:include => :product_tariffs))
10
10
  assert_equal(3, Tariff.count(:include => :product_tariffs))
11
11
 
12
12
  expected = {Date.today => 2,
13
13
  Date.today.next => 1}
14
-
14
+
15
15
  assert_equal(expected, Tariff.count(:group => :start_date))
16
16
  end
17
17
 
18
+ def test_count_distinct
19
+ product = products(:first_product)
20
+ assert_equal(2, product.product_tariffs.count(:distinct => true))
21
+ end
22
+
18
23
  def test_products
19
24
  assert_not_nil products(:first_product).product_tariffs
20
25
  assert_equal 2, products(:first_product).product_tariffs.length
@@ -39,87 +44,80 @@ class TestAssociations < ActiveSupport::TestCase
39
44
  # Its not generating the instances of associated classes from the rows
40
45
  def test_find_includes_products
41
46
  # Old style
42
- assert @products = Product.find(:all, :include => :product_tariffs)
43
- assert_equal 3, @products.length
44
- assert_not_nil @products.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
45
- assert_equal 3, @products.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
46
- "Incorrect number of product_tariffs returned"
47
+ products = Product.find(:all, :include => :product_tariffs)
48
+ assert_equal(2, products.length)
49
+ assert_equal(3, products.inject(0) {|sum, product| sum + product.product_tariffs.length})
47
50
 
48
51
  # New style
49
- assert @products = Product.includes(:product_tariffs)
50
- assert_equal 3, @products.length
51
- assert_not_nil @products.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
52
- assert_equal 3, @products.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
53
- "Incorrect number of product_tariffs returned"
52
+ products = Product.includes(:product_tariffs)
53
+ assert_equal(2, products.length)
54
+ assert_equal(3, products.inject(0) {|sum, product| sum + product.product_tariffs.length})
54
55
  end
55
56
 
56
57
  def test_find_includes_tariffs
57
58
  # Old style
58
- assert @tariffs = Tariff.find(:all, :include => :product_tariffs)
59
- assert_equal 3, @tariffs.length
60
- assert_not_nil @tariffs.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
61
- assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
62
- "Incorrect number of product_tariffs returnedturned"
59
+ tariffs = Tariff.find(:all, :include => :product_tariffs)
60
+ assert_equal(3, tariffs.length)
61
+ assert_equal(3, tariffs.inject(0) {|sum, tariff| sum + tariff.product_tariffs.length})
63
62
 
64
63
  # New style
65
- assert @tariffs = Tariff.includes(:product_tariffs)
66
- assert_equal 3, @tariffs.length
67
- assert_not_nil @tariffs.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
68
- assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
69
- "Incorrect number of product_tariffs returnedturned"
64
+ tariffs = Tariff.includes(:product_tariffs)
65
+ assert_equal(3, tariffs.length)
66
+ assert_equal(3, tariffs.inject(0) {|sum, tariff| sum + tariff.product_tariffs.length})
70
67
  end
71
68
 
72
- def test_find_includes_product_tariffs
69
+ def test_find_includes_product_tariffs_product
73
70
  # Old style
74
- assert @product_tariffs = ProductTariff.find(:all, :include => :product)
75
- assert_equal 3, @product_tariffs.length
76
- assert_not_nil @product_tariffs.first.instance_variable_get('@product'), '@product not set'
71
+ product_tariffs = ProductTariff.find(:all, :include => :product)
72
+ assert_not_nil(product_tariffs)
73
+ assert_equal(3, product_tariffs.length)
77
74
 
78
75
  # New style
79
- assert @product_tariffs = ProductTariff.includes(:product)
80
- assert_equal 3, @product_tariffs.length
81
- assert_not_nil @product_tariffs.first.instance_variable_get('@product'), '@product not set'
76
+ product_tariffs = ProductTariff.includes(:product)
77
+ assert_not_nil(product_tariffs)
78
+ assert_equal(3, product_tariffs.length)
82
79
  end
83
80
 
84
- def test_find_includes_comp_belongs_to_tariff
81
+ def test_find_includes_product_tariffs_tariff
85
82
  # Old style
86
- assert @product_tariffs = ProductTariff.find(:all, :include => :tariff)
87
- assert_equal 3, @product_tariffs.length
88
- assert_not_nil @product_tariffs.first.instance_variable_get('@tariff'), '@tariff not set'
83
+ product_tariffs = ProductTariff.find(:all, :include => :tariff)
84
+ assert_equal(3, product_tariffs.length)
89
85
 
90
86
  # New style
91
- assert @product_tariffs = ProductTariff.includes(:tariff)
92
- assert_equal 3, @product_tariffs.length
93
- assert_not_nil @product_tariffs.first.instance_variable_get('@tariff'), '@tariff not set'
87
+ product_tariffs = ProductTariff.includes(:tariff)
88
+ assert_equal(3, product_tariffs.length)
94
89
  end
95
90
 
96
- def test_new_style_includes_with_conditions
97
- product_tariff = ProductTariff.includes(:tariff).where('tariffs.amount < 5').first
98
- assert_equal(0, product_tariff.tariff.amount)
91
+ def test_has_many_through
92
+ products = Product.find(:all, :include => :tariffs)
93
+ assert_equal(2, products.length)
94
+
95
+ tarrifs_length = products.inject(0) {|sum, product| sum + product.tariffs.length}
96
+ assert_equal(3, tarrifs_length)
99
97
  end
100
98
 
101
- def test_find_includes_extended
102
- assert @products = Product.find(:all, :include => {:product_tariffs => :tariff})
103
- assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@product_tariffs').length},
104
- "Incorrect number of product_tariffs returned"
99
+ def test_find_product_includes
100
+ products = Product.find(:all, :include => {:product_tariffs => :tariff})
101
+ assert_equal(2, products.length)
105
102
 
106
- assert @tariffs = Tariff.find(:all, :include => {:product_tariffs => :product})
107
- assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
108
- "Incorrect number of product_tariffs returned"
103
+ product_tariffs_length = products.inject(0) {|sum, product| sum + product.product_tariffs.length}
104
+ assert_equal(3, product_tariffs_length)
109
105
  end
110
106
 
111
- def test_has_many_through
112
- @products = Product.find(:all, :include => :tariffs)
113
- assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@tariffs').length},
114
- "Incorrect number of tariffs returned"
107
+ def test_find_tariffs_includes
108
+ tariffs = Tariff.find(:all, :include => {:product_tariffs => :product})
109
+ assert_equal(3, tariffs.length)
110
+
111
+ product_tariffs_length = tariffs.inject(0) {|sum, tariff| sum + tariff.product_tariffs.length}
112
+ assert_equal(3, product_tariffs_length)
115
113
  end
116
114
 
117
115
  def test_has_many_through_when_not_pre_loaded
118
116
  student = Student.find(:first)
119
117
  rooms = student.rooms
120
- assert_equal 1, rooms.size
121
- assert_equal 1, rooms.first.dorm_id
122
- assert_equal 1, rooms.first.room_id
118
+ assert_equal(1, rooms.size)
119
+ assert_equal(1, rooms.first.dorm_id)
120
+ assert_equal(1, rooms.first.room_id)
123
121
  end
124
122
 
125
123
  def test_has_many_through_when_through_association_is_composite
@@ -130,17 +128,17 @@ class TestAssociations < ActiveSupport::TestCase
130
128
  end
131
129
 
132
130
  def test_associations_with_conditions
133
- @suburb = Suburb.find([2, 1])
134
- assert_equal 2, @suburb.streets.size
131
+ suburb = Suburb.find([2, 1])
132
+ assert_equal 2, suburb.streets.size
135
133
 
136
- @suburb = Suburb.find([2, 1])
137
- assert_equal 1, @suburb.first_streets.size
134
+ suburb = Suburb.find([2, 1])
135
+ assert_equal 1, suburb.first_streets.size
138
136
 
139
- @suburb = Suburb.find([2, 1], :include => :streets)
140
- assert_equal 2, @suburb.streets.size
137
+ suburb = Suburb.find([2, 1], :include => :streets)
138
+ assert_equal 2, suburb.streets.size
141
139
 
142
- @suburb = Suburb.find([2, 1], :include => :first_streets)
143
- assert_equal 1, @suburb.first_streets.size
140
+ suburb = Suburb.find([2, 1], :include => :first_streets)
141
+ assert_equal 1, suburb.first_streets.size
144
142
  end
145
143
 
146
144
  def test_composite_has_many_composites
@@ -205,12 +203,12 @@ class TestAssociations < ActiveSupport::TestCase
205
203
 
206
204
  def test_has_many_through_on_custom_finder_when_through_association_is_composite_finder_when_through_association_is_not_composite
207
205
  user = User.find(:first)
208
- assert_equal 1, user.find_custom_articles.size
206
+ assert_equal(1, user.find_custom_articles.size)
209
207
  end
210
208
 
211
209
  def test_has_many_through_on_custom_finder_when_through_association_is_composite
212
210
  room = Room.find(:first)
213
- assert_equal 0, room.find_custom_room_attributes.size
211
+ assert_equal(0, room.find_custom_room_attributes.size)
214
212
  end
215
213
 
216
214
  def test_has_many_with_primary_key_with_associations
@@ -28,8 +28,8 @@ class TestAttributes < ActiveSupport::TestCase
28
28
 
29
29
  def test_brackets_primary_key
30
30
  testing_with do
31
- assert_equal @first.id, @first[@primary_keys], "[] failing for #{@klass}"
32
- assert_equal @first.id, @first[@first.class.primary_key]
31
+ assert_equal(@first.id, @first[@primary_keys])
32
+ assert_equal(@first.id, @first[@first.class.primary_key])
33
33
  end
34
34
  end
35
35
 
@@ -43,33 +43,28 @@ class TestAttributes < ActiveSupport::TestCase
43
43
  end
44
44
 
45
45
  def test_brackets_foreign_key_assignment
46
- @flat = Tariff.find(1, Date.today.to_s(:db))
47
- @second_free = ProductTariff.find(2,2,Date.today.to_s(:db))
48
- @second_free_fk = [:tariff_id, :tariff_start_date]
46
+ flat = tariffs(:flat)
47
+ second_free = tariffs(:free)
48
+ second_free_fk = [:tariff_id, :tariff_start_date]
49
49
 
50
- @second_free[key = @second_free_fk] = @flat.id
51
- compare_indexes('@flat', @flat.class.primary_key, '@second_free', @second_free_fk)
52
- assert_equal @flat.id, @second_free[key]
50
+ second_free[key = second_free_fk] = flat.id
51
+ compare_indexes(flat, flat.class.primary_key, second_free, second_free_fk)
52
+ assert_equal flat.id, second_free[key]
53
53
 
54
- @second_free[key = @second_free_fk.to_composite_keys] = @flat.id
55
- assert_equal @flat.id, @second_free[key]
56
- compare_indexes('@flat', @flat.class.primary_key, '@second_free', @second_free_fk)
54
+ second_free[key = second_free_fk.to_composite_keys] = flat.id
55
+ assert_equal flat.id, second_free[key]
56
+ compare_indexes(flat, flat.class.primary_key, second_free, second_free_fk)
57
57
 
58
- @second_free[key = @second_free_fk.to_composite_keys.to_s] = @flat.id
59
- assert_equal @flat.id, @second_free[key]
60
- compare_indexes('@flat', @flat.class.primary_key, '@second_free', @second_free_fk)
58
+ second_free[key = second_free_fk.to_composite_keys.to_s] = flat.id
59
+ assert_equal flat.id, second_free[key]
60
+ compare_indexes(flat, flat.class.primary_key, second_free, second_free_fk)
61
61
  end
62
62
 
63
63
  private
64
64
 
65
- def compare_indexes(obj_name1, indexes1, obj_name2, indexes2)
66
- obj1, obj2 = eval "[#{obj_name1}, #{obj_name2}]"
65
+ def compare_indexes(obj1, indexes1, obj2, indexes2)
67
66
  indexes1.length.times do |key_index|
68
- assert_equal obj1[indexes1[key_index].to_s],
69
- obj2[indexes2[key_index].to_s],
70
- "#{obj_name1}[#{indexes1[key_index]}]=#{obj1[indexes1[key_index].to_s].inspect} != " +
71
- "#{obj_name2}[#{indexes2[key_index]}]=#{obj2[indexes2[key_index].to_s].inspect}; " +
72
- "#{obj_name2} = #{obj2.inspect}"
67
+ assert_equal(obj1[indexes1[key_index].to_s], obj2[indexes2[key_index].to_s])
73
68
  end
74
69
  end
75
70
  end
@@ -13,7 +13,7 @@ class TestCreate < ActiveSupport::TestCase
13
13
  :class => ReferenceCode,
14
14
  :primary_keys => [:reference_type_id, :reference_code],
15
15
  :create => {:reference_type_id => 1, :reference_code => 20, :code_label => 'NEW_CODE', :abbreviation => 'New Code'}
16
- },
16
+ }
17
17
  }
18
18
 
19
19
  def setup
@@ -38,7 +38,7 @@ class TestCreate < ActiveSupport::TestCase
38
38
  begin
39
39
  @obj = @klass.create(@klass_info[:create].block(@klass.primary_key))
40
40
  @successful = !composite?
41
- rescue CompositePrimaryKeys::ActiveRecord::CompositeKeyError
41
+ rescue ActiveRecord::CompositeKeyError
42
42
  @successful = false
43
43
  rescue
44
44
  flunk "Incorrect exception raised: #{$!}, #{$!.class}"
@@ -87,4 +87,4 @@ class TestCreate < ActiveSupport::TestCase
87
87
  assert_equal(25, suburb.suburb_id)
88
88
  assert_equal("My Suburb", suburb.name)
89
89
  end
90
- end
90
+ end
@@ -19,55 +19,57 @@ class TestDelete < ActiveSupport::TestCase
19
19
  self.class.classes = CLASSES
20
20
  end
21
21
 
22
- def test_destroy_one
23
- testing_with do
24
- assert @first.destroy
25
- end
26
- end
27
-
28
- def test_destroy_one_alone_via_class
29
- testing_with do
30
- assert @klass.destroy(@first.id)
31
- end
32
- end
33
-
34
- def test_delete_one_alone
35
- testing_with do
36
- assert @klass.delete(@first.id)
37
- end
38
- end
39
-
40
- def test_delete_many
41
- testing_with do
42
- to_delete = @klass.find(:all)[0..1]
43
- assert_equal 2, to_delete.length
44
- end
45
- end
46
-
47
- def test_delete_all
48
- testing_with do
49
- @klass.delete_all
50
- end
51
- end
52
-
53
- def test_clear_association
54
- department = Department.find(1,1)
55
- assert_equal 2, department.employees.size, "Before clear employee count should be 2."
56
- department.employees.clear
57
- assert_equal 0, department.employees.size, "After clear employee count should be 0."
58
- department.reload
59
- assert_equal 0, department.employees.size, "After clear and a reload from DB employee count should be 0."
60
- end
61
-
62
- def test_delete_association
63
- department = Department.find(1,1)
64
- assert_equal 2, department.employees.size , "Before delete employee count should be 2."
65
- first_employee = department.employees[0]
66
- department.employees.delete(first_employee)
67
- assert_equal 1, department.employees.size, "After delete employee count should be 1."
68
- department.reload
69
- assert_equal 1, department.employees.size, "After delete and a reload from DB employee count should be 1."
70
- end
22
+ # def test_destroy_one
23
+ # testing_with do
24
+ # assert @first.destroy
25
+ # end
26
+ # end
27
+ #
28
+ # def test_destroy_one_alone_via_class
29
+ # testing_with do
30
+ # assert @klass.destroy(@first.id)
31
+ # end
32
+ # end
33
+ #
34
+ # def test_delete_one_alone
35
+ # testing_with do
36
+ # assert @klass.delete(@first.id)
37
+ # end
38
+ # end
39
+ #
40
+ # def test_delete_many
41
+ # testing_with do
42
+ # to_delete = @klass.find(:all)[0..1]
43
+ # assert_equal 2, to_delete.length
44
+ # end
45
+ # end
46
+ #
47
+ # def test_delete_all
48
+ # testing_with do
49
+ # @klass.delete_all
50
+ # end
51
+ # end
52
+ #
53
+ # def test_clear_association
54
+ # department = Department.find(1,1)
55
+ # assert_equal(2, department.employees.size, "Before clear employee count should be 2.")
56
+ #
57
+ # department.employees.clear
58
+ # assert_equal(0, department.employees.size, "After clear employee count should be 0.")
59
+ #
60
+ # department.reload
61
+ # assert_equal(0, department.employees.size, "After clear and a reload from DB employee count should be 0.")
62
+ # end
63
+ #
64
+ # def test_delete_association
65
+ # department = Department.find(1,1)
66
+ # assert_equal 2, department.employees.size , "Before delete employee count should be 2."
67
+ # first_employee = department.employees[0]
68
+ # department.employees.delete(first_employee)
69
+ # assert_equal 1, department.employees.size, "After delete employee count should be 1."
70
+ # department.reload
71
+ # assert_equal 1, department.employees.size, "After delete and a reload from DB employee count should be 1."
72
+ # end
71
73
 
72
74
  def test_destroy_has_one
73
75
  # In this case the association is a has_one with
@@ -87,39 +89,40 @@ class TestDelete < ActiveSupport::TestCase
87
89
  end
88
90
  end
89
91
 
90
- def test_destroy_has_many_delete_all
91
- # In this case the association is a has_many composite key with
92
- # dependent set to :delete_all
93
- product = Product.find(1)
94
- assert_equal(2, product.product_tariffs.length)
95
-
96
- # Get product_tariff length
97
- product_tariff_size = ProductTariff.count
98
-
99
- # Delete product - should delete 2 product tariffs
100
- product.destroy
101
-
102
- # Verify product_tariff are deleted
103
- assert_equal(product_tariff_size - 2, ProductTariff.count)
104
- end
105
-
106
- def test_delete_cpk_association
107
- product = Product.find(1)
108
- assert_equal(2, product.product_tariffs.length)
109
-
110
- product_tariff = product.product_tariffs.first
111
- product.product_tariffs.delete(product_tariff)
112
-
113
- product.reload
114
- assert_equal(1, product.product_tariffs.length)
115
- end
116
-
117
- def test_delete_records_for_has_many_association_with_composite_primary_key
118
- reference_type = ReferenceType.find(1)
119
- codes_to_delete = reference_type.reference_codes[0..1]
120
- assert_equal 3, reference_type.reference_codes.size, "Before deleting records reference_code count should be 3."
121
- reference_type.reference_codes.delete_records(codes_to_delete)
122
- reference_type.reload
123
- assert_equal 1, reference_type.reference_codes.size, "After deleting 2 records and a reload from DB reference_code count should be 1."
124
- end
92
+ # def test_destroy_has_many_delete_all
93
+ # # In this case the association is a has_many composite key with
94
+ # # dependent set to :delete_all
95
+ # product = Product.find(1)
96
+ # assert_equal(2, product.product_tariffs.length)
97
+ #
98
+ # # Get product_tariff length
99
+ # product_tariff_size = ProductTariff.count
100
+ #
101
+ # # Delete product - should delete 2 product tariffs
102
+ # product.destroy
103
+ #
104
+ # # Verify product_tariff are deleted
105
+ # assert_equal(product_tariff_size - 2, ProductTariff.count)
106
+ # end
107
+ #
108
+ # def test_delete_cpk_association
109
+ # product = Product.find(1)
110
+ # assert_equal(2, product.product_tariffs.length)
111
+ #
112
+ # product_tariff = product.product_tariffs.first
113
+ # product.product_tariffs.delete(product_tariff)
114
+ #
115
+ # product.reload
116
+ # assert_equal(1, product.product_tariffs.length)
117
+ # end
118
+ #
119
+ # def test_delete_records_for_has_many_association_with_composite_primary_key
120
+ # reference_type = ReferenceType.find(1)
121
+ # codes_to_delete = reference_type.reference_codes[0..1]
122
+ # assert_equal(3, reference_type.reference_codes.size, "Before deleting records reference_code count should be 3.")
123
+ #
124
+ # reference_type.reference_codes.delete(codes_to_delete)
125
+ # reference_type.reload
126
+ # assert_equal(1, reference_type.reference_codes.size, "After deleting 2 records and a reload from DB reference_code count should be 1.")
127
+ # end
125
128
  end