composite_primary_keys 12.0.2 → 12.0.3

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +13 -0
  3. data/README.rdoc +3 -2
  4. data/lib/composite_primary_keys.rb +56 -56
  5. data/lib/composite_primary_keys/active_model/attribute_assignment.rb +19 -0
  6. data/lib/composite_primary_keys/arel/sqlserver.rb +1 -3
  7. data/lib/composite_primary_keys/associations/through_association.rb +2 -1
  8. data/lib/composite_primary_keys/attribute_methods.rb +1 -1
  9. data/lib/composite_primary_keys/attribute_methods/primary_key.rb +13 -0
  10. data/lib/composite_primary_keys/base.rb +11 -0
  11. data/lib/composite_primary_keys/composite_arrays.rb +0 -8
  12. data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +8 -3
  13. data/lib/composite_primary_keys/connection_adapters/mysql/database_statements.rb +24 -0
  14. data/lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb +29 -11
  15. data/lib/composite_primary_keys/persistence.rb +2 -2
  16. data/lib/composite_primary_keys/relation.rb +36 -27
  17. data/lib/composite_primary_keys/relation/predicate_builder/association_query_value.rb +1 -1
  18. data/lib/composite_primary_keys/version.rb +1 -1
  19. data/test/abstract_unit.rb +3 -2
  20. data/test/fixtures/article.rb +4 -0
  21. data/test/fixtures/articles.yml +4 -3
  22. data/test/fixtures/comment.rb +1 -3
  23. data/test/fixtures/comments.yml +10 -9
  24. data/test/fixtures/db_definitions/db2-create-tables.sql +0 -14
  25. data/test/fixtures/db_definitions/db2-drop-tables.sql +1 -3
  26. data/test/fixtures/db_definitions/mysql.sql +6 -43
  27. data/test/fixtures/db_definitions/oracle.drop.sql +3 -9
  28. data/test/fixtures/db_definitions/oracle.sql +12 -48
  29. data/test/fixtures/db_definitions/postgresql.sql +7 -44
  30. data/test/fixtures/db_definitions/sqlite.sql +6 -42
  31. data/test/fixtures/db_definitions/sqlserver.sql +5 -41
  32. data/test/fixtures/department.rb +8 -3
  33. data/test/fixtures/departments.yml +4 -4
  34. data/test/fixtures/readings.yml +2 -2
  35. data/test/fixtures/restaurants_suburbs.yml +1 -1
  36. data/test/fixtures/streets.yml +2 -2
  37. data/test/fixtures/suburbs.yml +2 -2
  38. data/test/fixtures/user.rb +3 -2
  39. data/test/test_associations.rb +30 -23
  40. data/test/test_create.rb +15 -18
  41. data/test/test_delete.rb +3 -3
  42. data/test/test_exists.rb +5 -5
  43. data/test/test_find.rb +2 -2
  44. data/test/test_habtm.rb +2 -2
  45. data/test/test_ids.rb +2 -6
  46. data/test/test_nested_attributes.rb +0 -57
  47. data/test/test_polymorphic.rb +29 -13
  48. data/test/test_preload.rb +4 -3
  49. data/test/test_serialize.rb +2 -2
  50. data/test/test_update.rb +19 -1
  51. metadata +5 -19
  52. data/test/fixtures/hack.rb +0 -5
  53. data/test/fixtures/hacks.yml +0 -3
  54. data/test/fixtures/pk_called_id.rb +0 -5
  55. data/test/fixtures/pk_called_ids.yml +0 -11
  56. data/test/fixtures/reference_code_using_composite_key_alias.rb +0 -8
  57. data/test/fixtures/reference_code_using_simple_key_alias.rb +0 -8
  58. data/test/fixtures/seat.rb +0 -5
  59. data/test/fixtures/seats.yml +0 -9
  60. data/test/fixtures/topic.rb +0 -6
  61. data/test/fixtures/topic_source.rb +0 -7
  62. data/test/test_aliases.rb +0 -18
  63. data/test/test_enum.rb +0 -21
  64. data/test/test_suite.rb +0 -35
@@ -1,27 +1,43 @@
1
1
  require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestPolymorphic < ActiveSupport::TestCase
4
- fixtures :users, :employees, :comments, :hacks, :articles, :readings
4
+ fixtures :articles, :departments, :employees, :users, :comments
5
5
 
6
- def test_polymorphic_has_many
7
- comments = Hack.find(7).comments
8
- assert_equal 7, comments[0].person_id
6
+ def test_has_many
7
+ user = users(:santiago)
8
+ comments = user.comments
9
+ assert_equal(user.id, comments[0].person_id)
9
10
  end
10
11
 
11
- def test_polymorphic_has_one
12
- first_comment = Hack.find(7).first_comment
13
- assert_equal 7, first_comment.person_id
12
+ def test_has_one
13
+ user = users(:santiago)
14
+ first_comment = user.first_comment
15
+ assert_equal(user.id, first_comment.person_id)
14
16
  end
15
17
 
16
18
  def test_has_many_through
17
- assert_equal(2, Article.count, 'Baseline sanity check')
18
- user = users(:santiago)
19
- article_names = user.articles.collect { |a| a.name }.sort
20
- assert_equal ['Article One', 'Article Two'], article_names
19
+ department = departments(:accounting)
20
+ comment = comments(:employee_comment)
21
+
22
+ assert_equal(1, department.comments.size)
23
+ assert_equal(comment, department.comments[0])
21
24
  end
22
25
 
23
- def test_polymorphic_has_many_through
26
+ def test_has_many_through_2
27
+ article = articles(:second)
28
+
24
29
  user = users(:santiago)
25
- assert_equal(['andrew'], user.hacks.collect { |a| a.name }.sort)
30
+ assert_equal(user, article.user_commentators[0])
31
+
32
+ user = users(:drnic)
33
+ assert_equal(user, article.user_commentators[1])
34
+ end
35
+
36
+ def test_clear_has_many_through
37
+ article = articles(:second)
38
+
39
+ assert_equal(2, article.comments.size)
40
+ article.user_commentators = []
41
+ assert_equal(0, article.comments.size)
26
42
  end
27
43
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestPreload < ActiveSupport::TestCase
4
- fixtures :comments, :users, :employees, :groups, :hacks, :readings
4
+ fixtures :articles, :comments, :users, :employees, :groups, :readings
5
5
 
6
6
  class UserForPreload < User
7
7
  has_many :comments_with_include_condition, -> { where('person_type = ?', 'User')},
@@ -31,10 +31,11 @@ class TestPreload < ActiveSupport::TestCase
31
31
 
32
32
  def test_preload_for_conditioned_has_many_association
33
33
  # has one comment
34
+ article = articles(:first)
34
35
  user1 = users(:santiago)
35
36
  user2 = UserForPreload.create(name: 'TestPreload')
36
- Comment.create(person: user2, person_type: 'User')
37
- Comment.create(person: user2, person_type: 'User')
37
+ Comment.create(article: article, person: user2, person_type: 'User')
38
+ Comment.create(article: article, person: user2, person_type: 'User')
38
39
 
39
40
  users = UserForPreload.where(id: [user1.id, user2.id]).all
40
41
  assert_equal(1, users.first.comments_with_include_condition.size)
@@ -5,11 +5,11 @@ class TestSerialization < ActiveSupport::TestCase
5
5
 
6
6
  def test_json
7
7
  department = Department.first
8
- assert_equal('{"department_id":1,"location_id":1}', department.to_json)
8
+ assert_equal('{"id":1,"location_id":1}', department.to_json)
9
9
  end
10
10
 
11
11
  def test_serializable_hash
12
12
  department = Department.first
13
- assert_equal({"department_id" => 1,"location_id" => 1}, department.serializable_hash)
13
+ assert_equal({"id" => 1,"location_id" => 1}, department.serializable_hash)
14
14
  end
15
15
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestUpdate < ActiveSupport::TestCase
4
- fixtures :reference_types, :reference_codes
4
+ fixtures :departments, :reference_types, :reference_codes, :rooms, :room_assignments
5
5
 
6
6
  CLASSES = {
7
7
  :single => {
@@ -36,6 +36,13 @@ class TestUpdate < ActiveSupport::TestCase
36
36
  end
37
37
  end
38
38
 
39
+ def test_update_attributes_with_id_field
40
+ department = departments(:accounting)
41
+ department.update_attribute(:location_id, 3)
42
+ department.reload
43
+ assert_equal(3, department.location_id)
44
+ end
45
+
39
46
  def test_update_primary_key
40
47
  obj = ReferenceCode.find([1,1])
41
48
  obj.reference_type_id = 2
@@ -76,4 +83,15 @@ class TestUpdate < ActiveSupport::TestCase
76
83
 
77
84
  assert_equal(2, query.count)
78
85
  end
86
+
87
+ def test_update_with_uniqueness
88
+ assignment = room_assignments(:jacksons_room)
89
+ room_1 = rooms(:branner_room_1)
90
+ room_2 = rooms(:branner_room_3)
91
+
92
+ assert_equal(room_1, assignment.room)
93
+ assignment.room = room_2
94
+ assignment.save!
95
+ assert_equal(room_2, assignment.room)
96
+ end
79
97
  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: 12.0.2
4
+ version: 12.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-19 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -48,6 +48,7 @@ files:
48
48
  - README.rdoc
49
49
  - Rakefile
50
50
  - lib/composite_primary_keys.rb
51
+ - lib/composite_primary_keys/active_model/attribute_assignment.rb
51
52
  - lib/composite_primary_keys/arel/sqlserver.rb
52
53
  - lib/composite_primary_keys/arel/to_sql.rb
53
54
  - lib/composite_primary_keys/associations/association.rb
@@ -70,6 +71,7 @@ files:
70
71
  - lib/composite_primary_keys/composite_relation.rb
71
72
  - lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb
72
73
  - lib/composite_primary_keys/connection_adapters/abstract_adapter.rb
74
+ - lib/composite_primary_keys/connection_adapters/mysql/database_statements.rb
73
75
  - lib/composite_primary_keys/connection_adapters/postgresql/database_statements.rb
74
76
  - lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb
75
77
  - lib/composite_primary_keys/core.rb
@@ -126,14 +128,10 @@ files:
126
128
  - test/fixtures/employees.yml
127
129
  - test/fixtures/group.rb
128
130
  - test/fixtures/groups.yml
129
- - test/fixtures/hack.rb
130
- - test/fixtures/hacks.yml
131
131
  - test/fixtures/membership.rb
132
132
  - test/fixtures/membership_status.rb
133
133
  - test/fixtures/membership_statuses.yml
134
134
  - test/fixtures/memberships.yml
135
- - test/fixtures/pk_called_id.rb
136
- - test/fixtures/pk_called_ids.yml
137
135
  - test/fixtures/product.rb
138
136
  - test/fixtures/product_tariff.rb
139
137
  - test/fixtures/product_tariffs.yml
@@ -141,8 +139,6 @@ files:
141
139
  - test/fixtures/reading.rb
142
140
  - test/fixtures/readings.yml
143
141
  - test/fixtures/reference_code.rb
144
- - test/fixtures/reference_code_using_composite_key_alias.rb
145
- - test/fixtures/reference_code_using_simple_key_alias.rb
146
142
  - test/fixtures/reference_codes.yml
147
143
  - test/fixtures/reference_type.rb
148
144
  - test/fixtures/reference_types.yml
@@ -158,8 +154,6 @@ files:
158
154
  - test/fixtures/room_attribute_assignments.yml
159
155
  - test/fixtures/room_attributes.yml
160
156
  - test/fixtures/rooms.yml
161
- - test/fixtures/seat.rb
162
- - test/fixtures/seats.yml
163
157
  - test/fixtures/street.rb
164
158
  - test/fixtures/streets.yml
165
159
  - test/fixtures/student.rb
@@ -168,15 +162,12 @@ files:
168
162
  - test/fixtures/suburbs.yml
169
163
  - test/fixtures/tariff.rb
170
164
  - test/fixtures/tariffs.yml
171
- - test/fixtures/topic.rb
172
- - test/fixtures/topic_source.rb
173
165
  - test/fixtures/topic_sources.yml
174
166
  - test/fixtures/topics.yml
175
167
  - test/fixtures/user.rb
176
168
  - test/fixtures/users.yml
177
169
  - test/plugins/pagination.rb
178
170
  - test/plugins/pagination_helper.rb
179
- - test/test_aliases.rb
180
171
  - test/test_associations.rb
181
172
  - test/test_attribute_methods.rb
182
173
  - test/test_attributes.rb
@@ -188,7 +179,6 @@ files:
188
179
  - test/test_delete.rb
189
180
  - test/test_dumpable.rb
190
181
  - test/test_dup.rb
191
- - test/test_enum.rb
192
182
  - test/test_equal.rb
193
183
  - test/test_exists.rb
194
184
  - test/test_find.rb
@@ -203,7 +193,6 @@ files:
203
193
  - test/test_preload.rb
204
194
  - test/test_santiago.rb
205
195
  - test/test_serialize.rb
206
- - test/test_suite.rb
207
196
  - test/test_touch.rb
208
197
  - test/test_tutorial_example.rb
209
198
  - test/test_update.rb
@@ -227,14 +216,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
216
  - !ruby/object:Gem::Version
228
217
  version: '0'
229
218
  requirements: []
230
- rubygems_version: 3.1.2
219
+ rubygems_version: 3.1.4
231
220
  signing_key:
232
221
  specification_version: 4
233
222
  summary: Composite key support for ActiveRecord
234
223
  test_files:
235
224
  - test/abstract_unit.rb
236
225
  - test/README_tests.rdoc
237
- - test/test_aliases.rb
238
226
  - test/test_associations.rb
239
227
  - test/test_attributes.rb
240
228
  - test/test_attribute_methods.rb
@@ -246,7 +234,6 @@ test_files:
246
234
  - test/test_delete.rb
247
235
  - test/test_dumpable.rb
248
236
  - test/test_dup.rb
249
- - test/test_enum.rb
250
237
  - test/test_equal.rb
251
238
  - test/test_exists.rb
252
239
  - test/test_find.rb
@@ -261,7 +248,6 @@ test_files:
261
248
  - test/test_preload.rb
262
249
  - test/test_santiago.rb
263
250
  - test/test_serialize.rb
264
- - test/test_suite.rb
265
251
  - test/test_touch.rb
266
252
  - test/test_tutorial_example.rb
267
253
  - test/test_update.rb
@@ -1,5 +0,0 @@
1
- class Hack < ActiveRecord::Base
2
- has_many :comments, :as => :person
3
-
4
- has_one :first_comment, :as => :person, :class_name => "Comment"
5
- end
@@ -1,3 +0,0 @@
1
- andrew:
2
- id: 7
3
- name: andrew
@@ -1,5 +0,0 @@
1
- class PkCalledId < ActiveRecord::Base
2
- self.primary_keys = :id, :reference_code
3
-
4
- validates_presence_of :reference_code, :code_label, :abbreviation
5
- end
@@ -1,11 +0,0 @@
1
- name_prefix_mr:
2
- id: 1
3
- reference_code: 1
4
- code_label: MR
5
- abbreviation: Mr
6
-
7
- name_prefix_mrs:
8
- id: 2
9
- reference_code: 1
10
- code_label: MRS
11
- abbreviation: Mrs
@@ -1,8 +0,0 @@
1
- class ReferenceCodeUsingCompositeKeyAlias < ActiveRecord::Base
2
- self.table_name = 'reference_codes'
3
- self.primary_key = [:reference_type_id, :reference_code]
4
-
5
- belongs_to :reference_type, :foreign_key => "reference_type_id"
6
-
7
- validates_presence_of :reference_code, :code_label, :abbreviation
8
- end
@@ -1,8 +0,0 @@
1
- class ReferenceCodeUsingSimpleKeyAlias < ActiveRecord::Base
2
- self.table_name = 'reference_codes'
3
- self.primary_key = :code_label
4
-
5
- belongs_to :reference_type, :foreign_key => "reference_type_id"
6
-
7
- validates_presence_of :reference_code, :code_label, :abbreviation
8
- end
@@ -1,5 +0,0 @@
1
- class Seat < ActiveRecord::Base
2
- self.primary_keys = [:flight_number, :seat]
3
-
4
- validates_uniqueness_of :customer
5
- end
@@ -1,9 +0,0 @@
1
- seat1:
2
- flight_number: 1
3
- seat: 1
4
- customer: 1
5
-
6
- seat2:
7
- flight_number: 1
8
- seat: 2
9
- customer: 2
@@ -1,6 +0,0 @@
1
- class Topic < ActiveRecord::Base
2
- has_many :topic_sources, dependent: :destroy
3
- accepts_nested_attributes_for :topic_sources
4
-
5
- validates :name, :feed_size, presence: true
6
- end
@@ -1,7 +0,0 @@
1
- class TopicSource < ActiveRecord::Base
2
- self.primary_keys = :topic_id, :platform
3
-
4
- belongs_to :topic, inverse_of: :topic_sources
5
-
6
- validates :platform, presence: true
7
- end
@@ -1,18 +0,0 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestAliases < ActiveSupport::TestCase
4
- fixtures :reference_codes
5
-
6
- def test_primary_key_setter_alias_composite_key
7
- reference_code = ReferenceCodeUsingCompositeKeyAlias.find([1, 2])
8
- assert_equal 'MRS', reference_code.code_label
9
- assert_equal 'Mrs', reference_code.abbreviation
10
- end
11
-
12
- def test_primary_key_setter_alias_simple_key
13
- reference_code = ReferenceCodeUsingSimpleKeyAlias.find('MRS')
14
- assert_equal 1, reference_code.reference_type_id
15
- assert_equal 2, reference_code.reference_code
16
- assert_equal 'Mrs', reference_code.abbreviation
17
- end
18
- end
@@ -1,21 +0,0 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestEnum < ActiveSupport::TestCase
4
- fixtures :comments
5
-
6
- def test_enum_was
7
- comment = Comment.first
8
- assert_nil comment.shown
9
- assert_equal({}, comment.changed_attributes)
10
- comment.shown = :true
11
- assert_equal({ "shown" => nil }, comment.changed_attributes)
12
- assert_equal 'true', comment.shown
13
- assert_nil comment.shown_was
14
-
15
- comment.save
16
-
17
- comment.shown = :false
18
- assert_equal 'false', comment.shown
19
- assert_equal 'true', comment.shown_was
20
- end
21
- end
@@ -1,35 +0,0 @@
1
- %w(
2
- test_aliases
3
- test_associations
4
- test_attribute_methods
5
- test_attributes
6
- test_calculations
7
- test_callbacks
8
- test_composite_arrays
9
- test_counter_cache
10
- test_create
11
- test_delete
12
- test_dumpable
13
- test_dup
14
- test_enum
15
- test_equal
16
- test_exists
17
- test_find
18
- test_habtm
19
- test_ids
20
- test_miscellaneous
21
- test_nested_attributes
22
- test_optimistic
23
- test_pagination
24
- test_polymorphic
25
- test_predicates
26
- test_preload
27
- test_santiago
28
- test_serialize
29
- test_touch
30
- test_tutorial_example
31
- test_update
32
- test_validations
33
- ).each do |test|
34
- require File.expand_path("../#{test}", __FILE__)
35
- end