composite_primary_keys 13.0.7 → 14.0.9

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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +50 -1
  3. data/README.rdoc +182 -181
  4. data/Rakefile +1 -1
  5. data/lib/composite_primary_keys/associations/association.rb +2 -2
  6. data/lib/composite_primary_keys/associations/association_scope.rb +1 -1
  7. data/lib/composite_primary_keys/associations/collection_association.rb +38 -31
  8. data/lib/composite_primary_keys/associations/has_many_through_association.rb +19 -0
  9. data/lib/composite_primary_keys/associations/preloader/association.rb +52 -61
  10. data/lib/composite_primary_keys/autosave_association.rb +60 -60
  11. data/lib/composite_primary_keys/composite_arrays.rb +88 -86
  12. data/lib/composite_primary_keys/composite_predicates.rb +121 -120
  13. data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +1 -2
  14. data/lib/composite_primary_keys/nested_attributes.rb +2 -2
  15. data/lib/composite_primary_keys/persistence.rb +96 -83
  16. data/lib/composite_primary_keys/relation/calculations.rb +110 -104
  17. data/lib/composite_primary_keys/relation/query_methods.rb +14 -16
  18. data/lib/composite_primary_keys/relation.rb +2 -0
  19. data/lib/composite_primary_keys/validations/uniqueness.rb +40 -32
  20. data/lib/composite_primary_keys/version.rb +2 -2
  21. data/lib/composite_primary_keys.rb +117 -119
  22. data/scripts/console.rb +2 -2
  23. data/tasks/databases/trilogy.rake +23 -0
  24. data/test/abstract_unit.rb +124 -114
  25. data/test/connections/databases.ci.yml +10 -0
  26. data/test/fixtures/admin.rb +4 -0
  27. data/test/fixtures/comments.yml +6 -0
  28. data/test/fixtures/db_definitions/db2-create-tables.sql +34 -0
  29. data/test/fixtures/db_definitions/db2-drop-tables.sql +7 -1
  30. data/test/fixtures/db_definitions/mysql.sql +23 -0
  31. data/test/fixtures/db_definitions/oracle.drop.sql +4 -0
  32. data/test/fixtures/db_definitions/oracle.sql +21 -0
  33. data/test/fixtures/db_definitions/postgresql.sql +23 -0
  34. data/test/fixtures/db_definitions/sqlite.sql +21 -0
  35. data/test/fixtures/db_definitions/sqlserver.sql +23 -0
  36. data/test/fixtures/department.rb +20 -16
  37. data/test/fixtures/moderator.rb +4 -0
  38. data/test/fixtures/room.rb +4 -1
  39. data/test/fixtures/room_assignment.rb +18 -14
  40. data/test/fixtures/staff_room.rb +6 -0
  41. data/test/fixtures/staff_room_key.rb +6 -0
  42. data/test/fixtures/user.rb +3 -0
  43. data/test/fixtures/user_with_polymorphic_name.rb +9 -0
  44. data/test/test_associations.rb +403 -372
  45. data/test/test_composite_arrays.rb +44 -38
  46. data/test/test_has_one_through.rb +30 -0
  47. data/test/test_nested_attributes.rb +23 -0
  48. data/test/test_polymorphic.rb +6 -0
  49. metadata +14 -7
  50. data/lib/composite_primary_keys/associations/through_association.rb +0 -24
@@ -1,38 +1,44 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class CompositeArraysTest < ActiveSupport::TestCase
4
-
5
- def test_new_primary_keys
6
- keys = CompositePrimaryKeys::CompositeKeys.new
7
- assert_not_nil keys
8
- assert_equal '', keys.to_s
9
- assert_equal '', "#{keys}"
10
- end
11
-
12
- def test_initialize_primary_keys
13
- keys = CompositePrimaryKeys::CompositeKeys.new([1,2,3])
14
- assert_not_nil keys
15
- assert_equal '1,2,3', keys.to_s
16
- assert_equal '1,2,3', "#{keys}"
17
- end
18
-
19
- def test_to_composite_keys
20
- keys = [1,2,3].to_composite_keys
21
- assert_equal CompositePrimaryKeys::CompositeKeys, keys.class
22
- assert_equal '1,2,3', keys.to_s
23
- end
24
-
25
- def test_parse
26
- assert_equal ['1', '2'], CompositePrimaryKeys::CompositeKeys.parse('1,2')
27
- assert_equal ['The USA', '^Washington, D.C.'],
28
- CompositePrimaryKeys::CompositeKeys.parse('The USA,^5EWashington^2C D.C.')
29
- assert_equal ['The USA', '^Washington, D.C.'],
30
- CompositePrimaryKeys::CompositeKeys.parse(['The USA', '^Washington, D.C.'])
31
- end
32
-
33
- def test_to_s
34
- assert_equal '1,2', CompositePrimaryKeys::CompositeKeys.new([1, 2]).to_s
35
- assert_equal 'The USA,^5EWashington^2C D.C.',
36
- CompositePrimaryKeys::CompositeKeys.new(['The USA', '^Washington, D.C.']).to_s
37
- end
38
- end
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class CompositeArraysTest < ActiveSupport::TestCase
4
+
5
+ def test_new_primary_keys
6
+ keys = CompositePrimaryKeys::CompositeKeys.new
7
+ assert_not_nil keys
8
+ assert_equal '', keys.to_s
9
+ assert_equal '', "#{keys}"
10
+ end
11
+
12
+ def test_initialize_primary_keys
13
+ keys = CompositePrimaryKeys::CompositeKeys.new([1,2,3])
14
+ assert_not_nil keys
15
+ assert_equal '1,2,3', keys.to_s
16
+ assert_equal '1,2,3', "#{keys}"
17
+ end
18
+
19
+ def test_to_composite_keys
20
+ keys = [1,2,3].to_composite_keys
21
+ assert_equal CompositePrimaryKeys::CompositeKeys, keys.class
22
+ assert_equal '1,2,3', keys.to_s
23
+ end
24
+
25
+ def test_parse
26
+ assert_equal ['1', '2'], CompositePrimaryKeys::CompositeKeys.parse('1,2')
27
+ assert_equal ['The USA', '^Washington, D.C.'],
28
+ CompositePrimaryKeys::CompositeKeys.parse('The USA,^5EWashington^2C D.C.')
29
+ assert_equal ['The USA', '^Washington, D.C.'],
30
+ CompositePrimaryKeys::CompositeKeys.parse(['The USA', '^Washington, D.C.'])
31
+ end
32
+
33
+ def test_to_s
34
+ assert_equal '1,2', CompositePrimaryKeys::CompositeKeys.new([1, 2]).to_s
35
+ assert_equal 'The USA,^5EWashington^2C D.C.',
36
+ CompositePrimaryKeys::CompositeKeys.new(['The USA', '^Washington, D.C.']).to_s
37
+ end
38
+
39
+ def test_to_param
40
+ assert_equal '1,2', CompositePrimaryKeys::CompositeKeys.new([1, 2]).to_param
41
+ assert_equal 'The USA,^5EWashington^2C D.C.',
42
+ CompositePrimaryKeys::CompositeKeys.new(['The USA', '^Washington, D.C.']).to_param
43
+ end
44
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class TestHasOneThrough < ActiveSupport::TestCase
4
+ fixtures :users, :rooms
5
+
6
+ def test_no_cpk
7
+ # This test makes sure we don't break anything in standard rails by using CPK
8
+ user = User.find(1)
9
+ assert_nil user.moderator
10
+ assert_nil user.admin
11
+
12
+ admin = Admin.create!(user: user)
13
+ assert_equal admin, user.admin
14
+ assert_equal 1, user.moderator.id
15
+ assert_equal 1, admin.id
16
+ end
17
+
18
+ def test_has_one_through
19
+ room = Room.find([1,1])
20
+ assert_nil room.staff_room
21
+ assert_nil room.staff_room_key
22
+
23
+ key = StaffRoomKey.create!(room: room, key_no: '1234')
24
+ assert_equal key, room.staff_room_key
25
+ assert_equal 1, room.staff_room.dorm_id
26
+ assert_equal 1, room.staff_room.room_id
27
+ assert_equal 1, key.dorm_id
28
+ assert_equal 1, key.room_id
29
+ end
30
+ end
@@ -64,4 +64,27 @@ class TestNestedAttributes < ActiveSupport::TestCase
64
64
  assert_equal(reference_code.code_label, 'XX')
65
65
  assert_equal(reference_code.abbreviation, 'Xx')
66
66
  end
67
+
68
+ def test_nested_atttribute_update_4
69
+ code_id = 1003
70
+
71
+ reference_type = reference_types(:name_prefix)
72
+ reference_type.update :reference_codes_attributes => [{
73
+ :reference_code => code_id,
74
+ :code_label => 'XX',
75
+ :abbreviation => 'Xx'
76
+ }]
77
+ assert_not_nil ReferenceCode.find_by_reference_code(code_id)
78
+ reference_code = ReferenceCode.find_by_reference_code(code_id)
79
+ # directly pass :id as a array
80
+ reference_type.update :reference_codes_attributes => [{
81
+ :id => [reference_type.reference_type_id, code_id],
82
+ :code_label => 'AAA',
83
+ :abbreviation => 'Aaa'
84
+ }]
85
+
86
+ reference_code = ReferenceCode.find_by_reference_code(code_id)
87
+ assert_kind_of(ReferenceCode, reference_code)
88
+ assert_equal(reference_code.code_label, 'AAA')
89
+ end
67
90
  end
@@ -40,4 +40,10 @@ class TestPolymorphic < ActiveSupport::TestCase
40
40
  article.user_commentators = []
41
41
  assert_equal(0, article.comments.size)
42
42
  end
43
+
44
+ def test_polymorphic_has_many_with_polymorphic_name
45
+ comments = UserWithPolymorphicName.find(1).comments
46
+ assert_equal 1, comments[0].person_id
47
+ assert_equal "User1", comments[0].person_type
48
+ end
43
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composite_primary_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.0.7
4
+ version: 14.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-04 00:00:00.000000000 Z
11
+ date: 2023-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 6.1.0
19
+ version: 7.0.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 6.1.0
26
+ version: 7.0.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +59,6 @@ files:
59
59
  - lib/composite_primary_keys/associations/has_many_through_association.rb
60
60
  - lib/composite_primary_keys/associations/join_association.rb
61
61
  - lib/composite_primary_keys/associations/preloader/association.rb
62
- - lib/composite_primary_keys/associations/through_association.rb
63
62
  - lib/composite_primary_keys/attribute_methods.rb
64
63
  - lib/composite_primary_keys/attribute_methods/primary_key.rb
65
64
  - lib/composite_primary_keys/attribute_methods/read.rb
@@ -99,6 +98,7 @@ files:
99
98
  - tasks/databases/postgresql.rake
100
99
  - tasks/databases/sqlite.rake
101
100
  - tasks/databases/sqlserver.rake
101
+ - tasks/databases/trilogy.rake
102
102
  - tasks/website.rake
103
103
  - test/README_tests.rdoc
104
104
  - test/abstract_unit.rb
@@ -106,6 +106,7 @@ files:
106
106
  - test/connections/databases.ci.yml
107
107
  - test/connections/databases.example.yml
108
108
  - test/connections/databases.yml
109
+ - test/fixtures/admin.rb
109
110
  - test/fixtures/article.rb
110
111
  - test/fixtures/articles.yml
111
112
  - test/fixtures/capitol.rb
@@ -132,6 +133,7 @@ files:
132
133
  - test/fixtures/membership_status.rb
133
134
  - test/fixtures/membership_statuses.yml
134
135
  - test/fixtures/memberships.yml
136
+ - test/fixtures/moderator.rb
135
137
  - test/fixtures/product.rb
136
138
  - test/fixtures/product_tariff.rb
137
139
  - test/fixtures/product_tariffs.yml
@@ -154,6 +156,8 @@ files:
154
156
  - test/fixtures/room_attribute_assignments.yml
155
157
  - test/fixtures/room_attributes.yml
156
158
  - test/fixtures/rooms.yml
159
+ - test/fixtures/staff_room.rb
160
+ - test/fixtures/staff_room_key.rb
157
161
  - test/fixtures/street.rb
158
162
  - test/fixtures/streets.yml
159
163
  - test/fixtures/student.rb
@@ -165,6 +169,7 @@ files:
165
169
  - test/fixtures/topic_sources.yml
166
170
  - test/fixtures/topics.yml
167
171
  - test/fixtures/user.rb
172
+ - test/fixtures/user_with_polymorphic_name.rb
168
173
  - test/fixtures/users.yml
169
174
  - test/plugins/pagination.rb
170
175
  - test/plugins/pagination_helper.rb
@@ -183,6 +188,7 @@ files:
183
188
  - test/test_exists.rb
184
189
  - test/test_find.rb
185
190
  - test/test_habtm.rb
191
+ - test/test_has_one_through.rb
186
192
  - test/test_ids.rb
187
193
  - test/test_miscellaneous.rb
188
194
  - test/test_nested_attributes.rb
@@ -209,14 +215,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
215
  requirements:
210
216
  - - ">="
211
217
  - !ruby/object:Gem::Version
212
- version: 2.5.0
218
+ version: 2.7.0
213
219
  required_rubygems_version: !ruby/object:Gem::Requirement
214
220
  requirements:
215
221
  - - ">="
216
222
  - !ruby/object:Gem::Version
217
223
  version: '0'
218
224
  requirements: []
219
- rubygems_version: 3.4.6
225
+ rubygems_version: 3.4.21
220
226
  signing_key:
221
227
  specification_version: 4
222
228
  summary: Composite key support for ActiveRecord
@@ -238,6 +244,7 @@ test_files:
238
244
  - test/test_exists.rb
239
245
  - test/test_find.rb
240
246
  - test/test_habtm.rb
247
+ - test/test_has_one_through.rb
241
248
  - test/test_ids.rb
242
249
  - test/test_miscellaneous.rb
243
250
  - test/test_nested_attributes.rb
@@ -1,24 +0,0 @@
1
- module ActiveRecord
2
- module Associations
3
- module ThroughAssociation
4
- alias :original_construct_join_attributes :construct_join_attributes
5
-
6
- def construct_join_attributes(*records)
7
- # CPK
8
- if !self.source_reflection.polymorphic? && source_reflection.klass.composite?
9
- ensure_mutable
10
-
11
- ids = records.map do |record|
12
- source_reflection.association_primary_key(reflection.klass).map do |key|
13
- record.send(key)
14
- end
15
- end
16
-
17
- cpk_in_predicate(through_association.scope.klass.arel_table, source_reflection.foreign_key, ids)
18
- else
19
- original_construct_join_attributes(*records)
20
- end
21
- end
22
- end
23
- end
24
- end