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.
- checksums.yaml +4 -4
- data/History.rdoc +13 -0
- data/README.rdoc +3 -2
- data/lib/composite_primary_keys.rb +56 -56
- data/lib/composite_primary_keys/active_model/attribute_assignment.rb +19 -0
- data/lib/composite_primary_keys/arel/sqlserver.rb +1 -3
- data/lib/composite_primary_keys/associations/through_association.rb +2 -1
- data/lib/composite_primary_keys/attribute_methods.rb +1 -1
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +13 -0
- data/lib/composite_primary_keys/base.rb +11 -0
- data/lib/composite_primary_keys/composite_arrays.rb +0 -8
- data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +8 -3
- data/lib/composite_primary_keys/connection_adapters/mysql/database_statements.rb +24 -0
- data/lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb +29 -11
- data/lib/composite_primary_keys/persistence.rb +2 -2
- data/lib/composite_primary_keys/relation.rb +36 -27
- data/lib/composite_primary_keys/relation/predicate_builder/association_query_value.rb +1 -1
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/abstract_unit.rb +3 -2
- data/test/fixtures/article.rb +4 -0
- data/test/fixtures/articles.yml +4 -3
- data/test/fixtures/comment.rb +1 -3
- data/test/fixtures/comments.yml +10 -9
- data/test/fixtures/db_definitions/db2-create-tables.sql +0 -14
- data/test/fixtures/db_definitions/db2-drop-tables.sql +1 -3
- data/test/fixtures/db_definitions/mysql.sql +6 -43
- data/test/fixtures/db_definitions/oracle.drop.sql +3 -9
- data/test/fixtures/db_definitions/oracle.sql +12 -48
- data/test/fixtures/db_definitions/postgresql.sql +7 -44
- data/test/fixtures/db_definitions/sqlite.sql +6 -42
- data/test/fixtures/db_definitions/sqlserver.sql +5 -41
- data/test/fixtures/department.rb +8 -3
- data/test/fixtures/departments.yml +4 -4
- data/test/fixtures/readings.yml +2 -2
- data/test/fixtures/restaurants_suburbs.yml +1 -1
- data/test/fixtures/streets.yml +2 -2
- data/test/fixtures/suburbs.yml +2 -2
- data/test/fixtures/user.rb +3 -2
- data/test/test_associations.rb +30 -23
- data/test/test_create.rb +15 -18
- data/test/test_delete.rb +3 -3
- data/test/test_exists.rb +5 -5
- data/test/test_find.rb +2 -2
- data/test/test_habtm.rb +2 -2
- data/test/test_ids.rb +2 -6
- data/test/test_nested_attributes.rb +0 -57
- data/test/test_polymorphic.rb +29 -13
- data/test/test_preload.rb +4 -3
- data/test/test_serialize.rb +2 -2
- data/test/test_update.rb +19 -1
- metadata +5 -19
- data/test/fixtures/hack.rb +0 -5
- data/test/fixtures/hacks.yml +0 -3
- data/test/fixtures/pk_called_id.rb +0 -5
- data/test/fixtures/pk_called_ids.yml +0 -11
- data/test/fixtures/reference_code_using_composite_key_alias.rb +0 -8
- data/test/fixtures/reference_code_using_simple_key_alias.rb +0 -8
- data/test/fixtures/seat.rb +0 -5
- data/test/fixtures/seats.yml +0 -9
- data/test/fixtures/topic.rb +0 -6
- data/test/fixtures/topic_source.rb +0 -7
- data/test/test_aliases.rb +0 -18
- data/test/test_enum.rb +0 -21
- data/test/test_suite.rb +0 -35
data/test/test_polymorphic.rb
CHANGED
@@ -1,27 +1,43 @@
|
|
1
1
|
require File.expand_path('../abstract_unit', __FILE__)
|
2
2
|
|
3
3
|
class TestPolymorphic < ActiveSupport::TestCase
|
4
|
-
fixtures :
|
4
|
+
fixtures :articles, :departments, :employees, :users, :comments
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
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
|
12
|
-
|
13
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
assert_equal
|
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
|
26
|
+
def test_has_many_through_2
|
27
|
+
article = articles(:second)
|
28
|
+
|
24
29
|
user = users(:santiago)
|
25
|
-
assert_equal(
|
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
|
data/test/test_preload.rb
CHANGED
@@ -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, :
|
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)
|
data/test/test_serialize.rb
CHANGED
@@ -5,11 +5,11 @@ class TestSerialization < ActiveSupport::TestCase
|
|
5
5
|
|
6
6
|
def test_json
|
7
7
|
department = Department.first
|
8
|
-
assert_equal('{"
|
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({"
|
13
|
+
assert_equal({"id" => 1,"location_id" => 1}, department.serializable_hash)
|
14
14
|
end
|
15
15
|
end
|
data/test/test_update.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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
|
data/test/fixtures/hack.rb
DELETED
data/test/fixtures/hacks.yml
DELETED
@@ -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
|
data/test/fixtures/seat.rb
DELETED
data/test/fixtures/seats.yml
DELETED
data/test/fixtures/topic.rb
DELETED
data/test/test_aliases.rb
DELETED
@@ -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
|
data/test/test_enum.rb
DELETED
@@ -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
|
data/test/test_suite.rb
DELETED
@@ -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
|