composite_primary_keys 5.0.14 → 6.0.0

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 (35) hide show
  1. checksums.yaml +14 -6
  2. data/History.rdoc +2 -8
  3. data/lib/composite_primary_keys.rb +3 -3
  4. data/lib/composite_primary_keys/associations/association.rb +1 -1
  5. data/lib/composite_primary_keys/associations/association_scope.rb +12 -13
  6. data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +4 -4
  7. data/lib/composite_primary_keys/associations/has_many_association.rb +2 -2
  8. data/lib/composite_primary_keys/associations/join_dependency.rb +1 -1
  9. data/lib/composite_primary_keys/associations/join_dependency/join_part.rb +3 -3
  10. data/lib/composite_primary_keys/associations/preloader/association.rb +2 -2
  11. data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +1 -1
  12. data/lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb +2 -2
  13. data/lib/composite_primary_keys/attribute_methods/dirty.rb +0 -2
  14. data/lib/composite_primary_keys/attribute_methods/read.rb +3 -3
  15. data/lib/composite_primary_keys/base.rb +3 -27
  16. data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +2 -2
  17. data/lib/composite_primary_keys/core.rb +28 -0
  18. data/lib/composite_primary_keys/persistence.rb +33 -50
  19. data/lib/composite_primary_keys/relation.rb +5 -5
  20. data/lib/composite_primary_keys/relation/calculations.rb +2 -2
  21. data/lib/composite_primary_keys/relation/query_methods.rb +14 -0
  22. data/lib/composite_primary_keys/version.rb +2 -2
  23. data/test/abstract_unit.rb +0 -1
  24. data/test/connections/databases.yml +10 -1
  25. data/test/debug.log +589 -0
  26. data/test/test_attributes.rb +1 -0
  27. data/test/test_calculations.rb +1 -1
  28. data/test/test_delete.rb +12 -0
  29. data/test/test_dup.rb +3 -2
  30. data/test/test_suite.rb +0 -2
  31. metadata +24 -32
  32. data/lib/composite_primary_keys/counter_cache.rb +0 -22
  33. data/test/fixtures/employees_group.rb +0 -2
  34. data/test/fixtures/employees_groups.yml +0 -15
  35. data/test/test_delete_without_pk.rb +0 -20
@@ -36,6 +36,7 @@ class TestAttributes < ActiveSupport::TestCase
36
36
  def test_brackets_assignment
37
37
  testing_with do
38
38
  @first.attributes.each_pair do |attr_name, value|
39
+ next if attr_name == @first.class.primary_key
39
40
  @first[attr_name]= !value.nil? ? value * 2 : '1'
40
41
  assert_equal !value.nil? ? value * 2 : '1', @first[attr_name]
41
42
  end
@@ -32,7 +32,7 @@ class TestCalculations < ActiveSupport::TestCase
32
32
  end
33
33
 
34
34
  def test_count_includes_dup_columns
35
- count = Tariff.includes(:product_tariffs).where("product_tariffs.tariff_id = ?", 2).count
35
+ count = Tariff.includes(:product_tariffs).references(:product_tariffs).where("product_tariffs.tariff_id = ?", 2).count
36
36
  assert_equal(1, count)
37
37
  end
38
38
  end
@@ -97,6 +97,18 @@ class TestDelete < ActiveSupport::TestCase
97
97
  assert_equal records_after, records_before - steve.groups.count
98
98
  end
99
99
 
100
+ def test_delete_not_destroy_on_cpk
101
+ tariff = Tariff.where(tariff_id: 2).first
102
+ tariff.delete
103
+ assert !tariff.persisted?
104
+ end
105
+
106
+ def test_delete_not_destroy_on_non_cpk
107
+ article = Article.first
108
+ article.delete
109
+ assert !article.persisted?
110
+ end
111
+
100
112
  # def test_destroy_has_many_delete_all
101
113
  # # In this case the association is a has_many composite key with
102
114
  # # dependent set to :delete_all
@@ -22,8 +22,9 @@ class TestClone < ActiveSupport::TestCase
22
22
  testing_with do
23
23
  clone = @first.dup
24
24
 
25
- remove_keys = Array(@klass.primary_key).map &:to_s
26
- assert_equal(@first.attributes.except(*remove_keys), clone.attributes)
25
+ remove_keys = Array(@klass.primary_key).map(&:to_s)
26
+ remove_keys << Array(@klass.primary_key) # Rails 4 adds the PK to the attributes, so we want to remove it as well
27
+ assert_equal(@first.attributes.except(*remove_keys), clone.attributes.except(*remove_keys))
27
28
 
28
29
  if composite?
29
30
  @klass.primary_key.each do |key|
@@ -1,5 +1,3 @@
1
- require 'test/unit'
2
-
3
1
  %w(
4
2
  test_associations
5
3
  test_attribute_methods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composite_primary_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.14
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Nic Williams
@@ -9,48 +9,42 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-16 00:00:00.000000000 Z
12
+ date: 2013-08-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - ! '>='
19
19
  - !ruby/object:Gem::Version
20
- version: 3.2.9
21
- - - "~>"
22
- - !ruby/object:Gem::Version
23
- version: 3.2.0
20
+ version: 4.0.0
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: 3.2.9
31
- - - "~>"
25
+ - - ! '>='
32
26
  - !ruby/object:Gem::Version
33
- version: 3.2.0
27
+ version: 4.0.0
34
28
  description: Composite key support for ActiveRecord
35
29
  email:
36
30
  executables: []
37
31
  extensions: []
38
32
  extra_rdoc_files: []
39
33
  files:
34
+ - Rakefile
40
35
  - History.rdoc
41
36
  - README.rdoc
42
37
  - README_DB2.rdoc
43
- - Rakefile
44
38
  - init.rb
45
39
  - install.rb
46
- - lib/composite_primary_keys.rb
40
+ - loader.rb
47
41
  - lib/composite_primary_keys/associations/association.rb
48
42
  - lib/composite_primary_keys/associations/association_scope.rb
49
43
  - lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb
50
44
  - lib/composite_primary_keys/associations/has_many_association.rb
51
- - lib/composite_primary_keys/associations/join_dependency.rb
52
45
  - lib/composite_primary_keys/associations/join_dependency/join_association.rb
53
46
  - lib/composite_primary_keys/associations/join_dependency/join_part.rb
47
+ - lib/composite_primary_keys/associations/join_dependency.rb
54
48
  - lib/composite_primary_keys/associations/preloader/association.rb
55
49
  - lib/composite_primary_keys/associations/preloader/belongs_to.rb
56
50
  - lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb
@@ -63,20 +57,20 @@ files:
63
57
  - lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb
64
58
  - lib/composite_primary_keys/connection_adapters/abstract_adapter.rb
65
59
  - lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
66
- - lib/composite_primary_keys/counter_cache.rb
60
+ - lib/composite_primary_keys/core.rb
67
61
  - lib/composite_primary_keys/dirty.rb
68
62
  - lib/composite_primary_keys/fixtures.rb
69
63
  - lib/composite_primary_keys/nested_attributes.rb
70
64
  - lib/composite_primary_keys/persistence.rb
71
- - lib/composite_primary_keys/relation.rb
72
65
  - lib/composite_primary_keys/relation/batches.rb
73
66
  - lib/composite_primary_keys/relation/calculations.rb
74
67
  - lib/composite_primary_keys/relation/finder_methods.rb
75
68
  - lib/composite_primary_keys/relation/query_methods.rb
69
+ - lib/composite_primary_keys/relation.rb
76
70
  - lib/composite_primary_keys/sanitization.rb
77
71
  - lib/composite_primary_keys/validations/uniqueness.rb
78
72
  - lib/composite_primary_keys/version.rb
79
- - loader.rb
73
+ - lib/composite_primary_keys.rb
80
74
  - scripts/console.rb
81
75
  - scripts/txt2html
82
76
  - scripts/txt2js
@@ -86,7 +80,6 @@ files:
86
80
  - tasks/databases/sqlite3.rake
87
81
  - tasks/databases/sqlserver.rake
88
82
  - tasks/website.rake
89
- - test/README_tests.rdoc
90
83
  - test/abstract_unit.rb
91
84
  - test/connections/connection_spec.rb
92
85
  - test/connections/databases.example.yml
@@ -99,6 +92,7 @@ files:
99
92
  - test/connections/native_sqlite3/connection.rb
100
93
  - test/connections/native_sqlserver/connection.rb
101
94
  - test/db_test.rb
95
+ - test/debug.log
102
96
  - test/fixtures/article.rb
103
97
  - test/fixtures/articles.yml
104
98
  - test/fixtures/capitol.rb
@@ -120,20 +114,18 @@ files:
120
114
  - test/fixtures/dorms.yml
121
115
  - test/fixtures/employee.rb
122
116
  - test/fixtures/employees.yml
123
- - test/fixtures/employees_group.rb
124
- - test/fixtures/employees_groups.yml
125
117
  - test/fixtures/group.rb
126
118
  - test/fixtures/groups.yml
127
119
  - test/fixtures/hack.rb
128
120
  - test/fixtures/hacks.yml
129
121
  - test/fixtures/membership.rb
122
+ - test/fixtures/memberships.yml
130
123
  - test/fixtures/membership_status.rb
131
124
  - test/fixtures/membership_statuses.yml
132
- - test/fixtures/memberships.yml
133
125
  - test/fixtures/product.rb
126
+ - test/fixtures/products.yml
134
127
  - test/fixtures/product_tariff.rb
135
128
  - test/fixtures/product_tariffs.yml
136
- - test/fixtures/products.yml
137
129
  - test/fixtures/reading.rb
138
130
  - test/fixtures/readings.yml
139
131
  - test/fixtures/reference_code.rb
@@ -144,13 +136,13 @@ files:
144
136
  - test/fixtures/restaurants.yml
145
137
  - test/fixtures/restaurants_suburbs.yml
146
138
  - test/fixtures/room.rb
139
+ - test/fixtures/rooms.yml
147
140
  - test/fixtures/room_assignment.rb
148
141
  - test/fixtures/room_assignments.yml
149
142
  - test/fixtures/room_attribute.rb
143
+ - test/fixtures/room_attributes.yml
150
144
  - test/fixtures/room_attribute_assignment.rb
151
145
  - test/fixtures/room_attribute_assignments.yml
152
- - test/fixtures/room_attributes.yml
153
- - test/fixtures/rooms.yml
154
146
  - test/fixtures/seat.rb
155
147
  - test/fixtures/seats.yml
156
148
  - test/fixtures/street.rb
@@ -165,16 +157,16 @@ files:
165
157
  - test/fixtures/users.yml
166
158
  - test/plugins/pagination.rb
167
159
  - test/plugins/pagination_helper.rb
160
+ - test/README_tests.rdoc
168
161
  - test/setup.rb
169
162
  - test/test_associations.rb
170
- - test/test_attribute_methods.rb
171
163
  - test/test_attributes.rb
164
+ - test/test_attribute_methods.rb
172
165
  - test/test_calculations.rb
173
166
  - test/test_composite_arrays.rb
174
167
  - test/test_counter_cache.rb
175
168
  - test/test_create.rb
176
169
  - test/test_delete.rb
177
- - test/test_delete_without_pk.rb
178
170
  - test/test_dup.rb
179
171
  - test/test_equal.rb
180
172
  - test/test_exists.rb
@@ -201,23 +193,24 @@ require_paths:
201
193
  - lib
202
194
  required_ruby_version: !ruby/object:Gem::Requirement
203
195
  requirements:
204
- - - ">="
196
+ - - ! '>='
205
197
  - !ruby/object:Gem::Version
206
- version: 1.8.7
198
+ version: 1.9.3
207
199
  required_rubygems_version: !ruby/object:Gem::Requirement
208
200
  requirements:
209
- - - ">="
201
+ - - ! '>='
210
202
  - !ruby/object:Gem::Version
211
203
  version: '0'
212
204
  requirements: []
213
205
  rubyforge_project: compositekeys
214
- rubygems_version: 2.2.2
206
+ rubygems_version: 2.0.6
215
207
  signing_key:
216
208
  specification_version: 4
217
209
  summary: Composite key support for ActiveRecord
218
210
  test_files:
219
211
  - test/abstract_unit.rb
220
212
  - test/db_test.rb
213
+ - test/debug.log
221
214
  - test/README_tests.rdoc
222
215
  - test/setup.rb
223
216
  - test/test_associations.rb
@@ -228,7 +221,6 @@ test_files:
228
221
  - test/test_counter_cache.rb
229
222
  - test/test_create.rb
230
223
  - test/test_delete.rb
231
- - test/test_delete_without_pk.rb
232
224
  - test/test_dup.rb
233
225
  - test/test_equal.rb
234
226
  - test/test_exists.rb
@@ -1,22 +0,0 @@
1
- module ActiveRecord
2
- module CounterCache
3
- def update_counters(id, counters)
4
- updates = counters.map do |counter_name, value|
5
- operator = value < 0 ? '-' : '+'
6
- quoted_column = connection.quote_column_name(counter_name)
7
- "#{quoted_column} = COALESCE(#{quoted_column}, 0) #{operator} #{value.abs}"
8
- end
9
-
10
- IdentityMap.remove_by_id(symbolized_base_class, id) if IdentityMap.enabled?
11
-
12
- # CPK
13
- # update_all(updates.join(', '), primary_key => id )
14
- primary_key_predicate = relation.cpk_id_predicate(self.arel_table, Array(self.primary_key), Array(id))
15
- update_all(updates.join(', '), primary_key_predicate)
16
- end
17
-
18
- def decrement_counter(counter_name, id)
19
- update_counters(id, counter_name => -1)
20
- end
21
- end
22
- end
@@ -1,2 +0,0 @@
1
- class EmployeesGroup < ActiveRecord::Base
2
- end
@@ -1,15 +0,0 @@
1
- assn1:
2
- employee_id: 1
3
- group_id: 1
4
-
5
- assn2:
6
- employee_id: 1
7
- group_id: 2
8
-
9
- assn3:
10
- employee_id: 2
11
- group_id: 1
12
-
13
- assn4:
14
- employee_id: 2
15
- group_id: 2
@@ -1,20 +0,0 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestDeleteWithoutPK < ActiveSupport::TestCase
4
-
5
- # can't load fixtures because other test dependencies
6
- setup do
7
- EmployeesGroup.create(employee_id: 1, group_id: 1)
8
- EmployeesGroup.create(employee_id: 1, group_id: 2)
9
- EmployeesGroup.create(employee_id: 2, group_id: 1)
10
- EmployeesGroup.create(employee_id: 2, group_id: 1)
11
- end
12
-
13
- def test_destroy_without_primary_key
14
- employees_group = EmployeesGroup.first
15
- assert_raise(ActiveRecord::CompositeKeyError) do
16
- employees_group.destroy
17
- end
18
- assert_equal 4, EmployeesGroup.count
19
- end
20
- end