composite_primary_keys 11.0.0.rc1 → 11.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +763 -754
- data/Rakefile +37 -37
- data/lib/composite_primary_keys.rb +122 -121
- data/lib/composite_primary_keys/arel/sqlserver.rb +37 -37
- data/lib/composite_primary_keys/arel/to_sql.rb +32 -32
- data/lib/composite_primary_keys/associations/association.rb +23 -23
- data/lib/composite_primary_keys/associations/association_scope.rb +68 -68
- data/lib/composite_primary_keys/associations/collection_association.rb +31 -31
- data/lib/composite_primary_keys/associations/has_many_association.rb +34 -34
- data/lib/composite_primary_keys/associations/join_dependency.rb +102 -102
- data/lib/composite_primary_keys/associations/preloader/association.rb +117 -117
- data/lib/composite_primary_keys/attribute_methods.rb +9 -9
- data/lib/composite_primary_keys/attribute_methods/read.rb +27 -27
- data/lib/composite_primary_keys/attribute_methods/write.rb +44 -44
- data/lib/composite_primary_keys/autosave_association.rb +32 -32
- data/lib/composite_primary_keys/base.rb +130 -130
- data/lib/composite_primary_keys/composite_arrays.rb +51 -51
- data/lib/composite_primary_keys/composite_predicates.rb +69 -69
- data/lib/composite_primary_keys/composite_relation.rb +29 -48
- data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +29 -22
- data/lib/composite_primary_keys/connection_adapters/postgresql/database_statements.rb +26 -26
- data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +22 -22
- data/lib/composite_primary_keys/core.rb +54 -54
- data/lib/composite_primary_keys/counter_cache.rb +28 -0
- data/lib/composite_primary_keys/fixtures.rb +26 -26
- data/lib/composite_primary_keys/locking/optimistic.rb +56 -56
- data/lib/composite_primary_keys/persistence.rb +112 -93
- data/lib/composite_primary_keys/reflection.rb +20 -20
- data/lib/composite_primary_keys/relation.rb +88 -88
- data/lib/composite_primary_keys/relation/calculations.rb +79 -79
- data/lib/composite_primary_keys/relation/finder_methods.rb +229 -229
- data/lib/composite_primary_keys/relation/predicate_builder/association_query_value.rb +20 -20
- data/lib/composite_primary_keys/relation/query_methods.rb +42 -42
- data/lib/composite_primary_keys/relation/where_clause.rb +24 -24
- data/lib/composite_primary_keys/sanitization.rb +42 -42
- data/lib/composite_primary_keys/validations/uniqueness.rb +32 -32
- data/lib/composite_primary_keys/version.rb +8 -8
- data/scripts/console.rb +0 -0
- data/tasks/databases/mysql.rake +40 -40
- data/tasks/databases/oracle.rake +41 -41
- data/tasks/databases/postgresql.rake +38 -38
- data/tasks/databases/sqlite.rake +25 -25
- data/tasks/databases/sqlserver.rake +43 -43
- data/test/abstract_unit.rb +120 -120
- data/test/connections/connection_spec.rb +27 -27
- data/test/connections/databases.ci.yml +16 -16
- data/test/connections/databases.example.yml +40 -40
- data/test/connections/databases.yml +10 -0
- data/test/fixtures/article.rb +6 -6
- data/test/fixtures/comment.rb +7 -7
- data/test/fixtures/db_definitions/db2-create-tables.sql +126 -126
- data/test/fixtures/db_definitions/db2-drop-tables.sql +18 -18
- data/test/fixtures/db_definitions/mysql.sql +226 -226
- data/test/fixtures/db_definitions/oracle.drop.sql +49 -49
- data/test/fixtures/db_definitions/oracle.sql +246 -246
- data/test/fixtures/db_definitions/postgresql.sql +229 -229
- data/test/fixtures/db_definitions/sqlite.sql +214 -214
- data/test/fixtures/db_definitions/sqlserver.sql +211 -211
- data/test/fixtures/dorm.rb +2 -2
- data/test/fixtures/employee.rb +10 -10
- data/test/fixtures/employees.yml +18 -18
- data/test/fixtures/membership.rb +6 -6
- data/test/fixtures/membership_statuses.yml +16 -16
- data/test/fixtures/memberships.yml +10 -10
- data/test/fixtures/pk_called_id.rb +5 -5
- data/test/fixtures/pk_called_ids.yml +11 -11
- data/test/fixtures/product_tariffs.yml +14 -14
- data/test/fixtures/reference_code.rb +7 -7
- data/test/fixtures/reference_type.rb +12 -12
- data/test/fixtures/restaurants_suburb.rb +2 -2
- data/test/fixtures/salary.rb +5 -5
- data/test/fixtures/suburb.rb +5 -5
- data/test/fixtures/tariff.rb +5 -5
- data/test/fixtures/tariffs.yml +14 -14
- data/test/fixtures/topic.rb +5 -5
- data/test/fixtures/topic_source.rb +6 -6
- data/test/fixtures/topic_sources.yml +3 -3
- data/test/fixtures/topics.yml +8 -8
- data/test/fixtures/user.rb +10 -10
- data/test/fixtures/users.yml +10 -10
- data/test/test_associations.rb +345 -345
- data/test/test_attribute_methods.rb +63 -63
- data/test/test_attributes.rb +60 -60
- data/test/test_calculations.rb +42 -42
- data/test/test_callbacks.rb +99 -99
- data/test/test_counter_cache.rb +1 -1
- data/test/test_create.rb +164 -164
- data/test/test_delete.rb +167 -167
- data/test/test_dumpable.rb +15 -15
- data/test/test_enum.rb +21 -21
- data/test/test_equal.rb +26 -26
- data/test/test_find.rb +137 -137
- data/test/test_habtm.rb +141 -141
- data/test/test_ids.rb +113 -113
- data/test/test_nested_attributes.rb +124 -124
- data/test/test_optimistic.rb +18 -18
- data/test/test_polymorphic.rb +27 -27
- data/test/test_predicates.rb +59 -59
- data/test/test_preload.rb +94 -94
- data/test/test_santiago.rb +23 -23
- data/test/test_suite.rb +34 -34
- data/test/test_touch.rb +23 -23
- data/test/test_tutorial_example.rb +25 -25
- data/test/test_update.rb +76 -76
- metadata +29 -28
data/test/test_touch.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
# Test cases devised by Santiago that broke the Composite Primary Keys
|
2
|
-
# code at one point in time. But no more!!!
|
3
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
4
|
-
|
5
|
-
class TestTouch < ActiveSupport::TestCase
|
6
|
-
fixtures :products, :tariffs
|
7
|
-
|
8
|
-
def test_touching_a_record_updates_its_timestamp
|
9
|
-
tariff = tariffs(:flat)
|
10
|
-
previous_amount = tariff.amount
|
11
|
-
previously_updated_at = tariff.updated_at
|
12
|
-
|
13
|
-
tariff.amount = previous_amount + 1
|
14
|
-
sleep 1.0 # we need to sleep for 1 second because the times updated (on mysql, at least) are only precise to 1 second.
|
15
|
-
tariff.touch
|
16
|
-
assert_not_equal previously_updated_at, tariff.updated_at
|
17
|
-
assert_equal previous_amount + 1, tariff.amount
|
18
|
-
assert tariff.amount_changed?, 'tarif amount should have changed'
|
19
|
-
assert tariff.changed?, 'tarif should be marked as changed'
|
20
|
-
tariff.reload
|
21
|
-
assert_not_equal previously_updated_at, tariff.updated_at
|
22
|
-
end
|
23
|
-
end
|
1
|
+
# Test cases devised by Santiago that broke the Composite Primary Keys
|
2
|
+
# code at one point in time. But no more!!!
|
3
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
4
|
+
|
5
|
+
class TestTouch < ActiveSupport::TestCase
|
6
|
+
fixtures :products, :tariffs
|
7
|
+
|
8
|
+
def test_touching_a_record_updates_its_timestamp
|
9
|
+
tariff = tariffs(:flat)
|
10
|
+
previous_amount = tariff.amount
|
11
|
+
previously_updated_at = tariff.updated_at
|
12
|
+
|
13
|
+
tariff.amount = previous_amount + 1
|
14
|
+
sleep 1.0 # we need to sleep for 1 second because the times updated (on mysql, at least) are only precise to 1 second.
|
15
|
+
tariff.touch
|
16
|
+
assert_not_equal previously_updated_at, tariff.updated_at
|
17
|
+
assert_equal previous_amount + 1, tariff.amount
|
18
|
+
assert tariff.amount_changed?, 'tarif amount should have changed'
|
19
|
+
assert tariff.changed?, 'tarif should be marked as changed'
|
20
|
+
tariff.reload
|
21
|
+
assert_not_equal previously_updated_at, tariff.updated_at
|
22
|
+
end
|
23
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
-
|
3
|
-
class TestTutorialExample < ActiveSupport::TestCase
|
4
|
-
fixtures :users, :groups, :memberships, :membership_statuses
|
5
|
-
|
6
|
-
def test_membership
|
7
|
-
membership = Membership.find([1, 1])
|
8
|
-
assert(membership, "Cannot find a membership")
|
9
|
-
assert(membership.user)
|
10
|
-
assert(membership.group)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_status
|
14
|
-
membership = Membership.find([1, 1])
|
15
|
-
statuses = membership.statuses
|
16
|
-
assert(membership, "Cannot find a membership")
|
17
|
-
assert(statuses, "No has_many association to status")
|
18
|
-
assert_equal(membership, statuses.first.membership)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_count
|
22
|
-
membership = Membership.find([1, 1])
|
23
|
-
assert(membership, "Cannot find a membership")
|
24
|
-
assert_equal(1, membership.statuses.count)
|
25
|
-
end
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TestTutorialExample < ActiveSupport::TestCase
|
4
|
+
fixtures :users, :groups, :memberships, :membership_statuses
|
5
|
+
|
6
|
+
def test_membership
|
7
|
+
membership = Membership.find([1, 1])
|
8
|
+
assert(membership, "Cannot find a membership")
|
9
|
+
assert(membership.user)
|
10
|
+
assert(membership.group)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_status
|
14
|
+
membership = Membership.find([1, 1])
|
15
|
+
statuses = membership.statuses
|
16
|
+
assert(membership, "Cannot find a membership")
|
17
|
+
assert(statuses, "No has_many association to status")
|
18
|
+
assert_equal(membership, statuses.first.membership)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_count
|
22
|
+
membership = Membership.find([1, 1])
|
23
|
+
assert(membership, "Cannot find a membership")
|
24
|
+
assert_equal(1, membership.statuses.count)
|
25
|
+
end
|
26
26
|
end
|
data/test/test_update.rb
CHANGED
@@ -1,76 +1,76 @@
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
-
|
3
|
-
class TestUpdate < ActiveSupport::TestCase
|
4
|
-
fixtures :reference_types, :reference_codes
|
5
|
-
|
6
|
-
CLASSES = {
|
7
|
-
:single => {
|
8
|
-
:class => ReferenceType,
|
9
|
-
:primary_keys => :reference_type_id,
|
10
|
-
:update => { :description => 'RT Desc' },
|
11
|
-
},
|
12
|
-
:dual => {
|
13
|
-
:class => ReferenceCode,
|
14
|
-
:primary_keys => [:reference_type_id, :reference_code],
|
15
|
-
:update => { :description => 'RT Desc' },
|
16
|
-
},
|
17
|
-
}
|
18
|
-
|
19
|
-
def setup
|
20
|
-
self.class.classes = CLASSES
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_setup
|
24
|
-
testing_with do
|
25
|
-
assert_not_nil @klass_info[:update]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_update_attributes
|
30
|
-
testing_with do
|
31
|
-
assert(@first.update_attributes(@klass_info[:update]))
|
32
|
-
assert(@first.reload)
|
33
|
-
@klass_info[:update].each_pair do |attr_name, new_value|
|
34
|
-
assert_equal(new_value, @first[attr_name])
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_update_primary_key
|
40
|
-
obj = ReferenceCode.find([1,1])
|
41
|
-
obj.reference_type_id = 2
|
42
|
-
obj.reference_code = 3
|
43
|
-
assert_equal({"reference_type_id" => 2, "reference_code" => 3}, obj.ids_hash)
|
44
|
-
assert(obj.save)
|
45
|
-
assert(obj.reload)
|
46
|
-
assert_equal(2, obj.reference_type_id)
|
47
|
-
assert_equal(3, obj.reference_code)
|
48
|
-
assert_equal({"reference_type_id" => 2, "reference_code" => 3}, obj.ids_hash)
|
49
|
-
assert_equal([2, 3], obj.id)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_update_attribute
|
53
|
-
obj = ReferenceType.find(1)
|
54
|
-
obj[:abbreviation] = 'a'
|
55
|
-
obj['abbreviation'] = 'b'
|
56
|
-
assert(obj.save)
|
57
|
-
assert(obj.reload)
|
58
|
-
assert_equal('b', obj.abbreviation)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_update_all
|
62
|
-
ReferenceCode.update_all(description: 'random value')
|
63
|
-
|
64
|
-
ReferenceCode.all.each do |reference_code|
|
65
|
-
assert_equal('random value', reference_code.description)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_update_all_join
|
70
|
-
ReferenceCode.joins(:reference_type).update_all(description: 'random value')
|
71
|
-
|
72
|
-
ReferenceCode.all.each do |reference_code|
|
73
|
-
assert_equal('random value', reference_code.description)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TestUpdate < ActiveSupport::TestCase
|
4
|
+
fixtures :reference_types, :reference_codes
|
5
|
+
|
6
|
+
CLASSES = {
|
7
|
+
:single => {
|
8
|
+
:class => ReferenceType,
|
9
|
+
:primary_keys => :reference_type_id,
|
10
|
+
:update => { :description => 'RT Desc' },
|
11
|
+
},
|
12
|
+
:dual => {
|
13
|
+
:class => ReferenceCode,
|
14
|
+
:primary_keys => [:reference_type_id, :reference_code],
|
15
|
+
:update => { :description => 'RT Desc' },
|
16
|
+
},
|
17
|
+
}
|
18
|
+
|
19
|
+
def setup
|
20
|
+
self.class.classes = CLASSES
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_setup
|
24
|
+
testing_with do
|
25
|
+
assert_not_nil @klass_info[:update]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_update_attributes
|
30
|
+
testing_with do
|
31
|
+
assert(@first.update_attributes(@klass_info[:update]))
|
32
|
+
assert(@first.reload)
|
33
|
+
@klass_info[:update].each_pair do |attr_name, new_value|
|
34
|
+
assert_equal(new_value, @first[attr_name])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_update_primary_key
|
40
|
+
obj = ReferenceCode.find([1,1])
|
41
|
+
obj.reference_type_id = 2
|
42
|
+
obj.reference_code = 3
|
43
|
+
assert_equal({"reference_type_id" => 2, "reference_code" => 3}, obj.ids_hash)
|
44
|
+
assert(obj.save)
|
45
|
+
assert(obj.reload)
|
46
|
+
assert_equal(2, obj.reference_type_id)
|
47
|
+
assert_equal(3, obj.reference_code)
|
48
|
+
assert_equal({"reference_type_id" => 2, "reference_code" => 3}, obj.ids_hash)
|
49
|
+
assert_equal([2, 3], obj.id)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_update_attribute
|
53
|
+
obj = ReferenceType.find(1)
|
54
|
+
obj[:abbreviation] = 'a'
|
55
|
+
obj['abbreviation'] = 'b'
|
56
|
+
assert(obj.save)
|
57
|
+
assert(obj.reload)
|
58
|
+
assert_equal('b', obj.abbreviation)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_update_all
|
62
|
+
ReferenceCode.update_all(description: 'random value')
|
63
|
+
|
64
|
+
ReferenceCode.all.each do |reference_code|
|
65
|
+
assert_equal('random value', reference_code.description)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_update_all_join
|
70
|
+
ReferenceCode.joins(:reference_type).update_all(description: 'random value')
|
71
|
+
|
72
|
+
ReferenceCode.all.each do |reference_code|
|
73
|
+
assert_equal('random value', reference_code.description)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
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: 11.0.0.
|
4
|
+
version: 11.0.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb
|
116
116
|
- lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb
|
117
117
|
- lib/composite_primary_keys/core.rb
|
118
|
+
- lib/composite_primary_keys/counter_cache.rb
|
118
119
|
- lib/composite_primary_keys/fixtures.rb
|
119
120
|
- lib/composite_primary_keys/locking/optimistic.rb
|
120
121
|
- lib/composite_primary_keys/nested_attributes.rb
|
@@ -272,44 +273,44 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
273
|
version: 1.3.1
|
273
274
|
requirements: []
|
274
275
|
rubyforge_project:
|
275
|
-
rubygems_version: 2.7.
|
276
|
+
rubygems_version: 2.7.6
|
276
277
|
signing_key:
|
277
278
|
specification_version: 4
|
278
279
|
summary: Composite key support for ActiveRecord
|
279
280
|
test_files:
|
280
|
-
- test/abstract_unit.rb
|
281
|
-
- test/db_test.rb
|
282
|
-
- test/README_tests.rdoc
|
283
|
-
- test/setup.rb
|
284
|
-
- test/test_aliases.rb
|
285
|
-
- test/test_associations.rb
|
286
281
|
- test/test_attributes.rb
|
287
|
-
- test/test_attribute_methods.rb
|
288
|
-
- test/test_calculations.rb
|
289
|
-
- test/test_callbacks.rb
|
290
|
-
- test/test_composite_arrays.rb
|
291
|
-
- test/test_counter_cache.rb
|
292
|
-
- test/test_create.rb
|
293
|
-
- test/test_delete.rb
|
294
|
-
- test/test_dumpable.rb
|
295
|
-
- test/test_dup.rb
|
296
282
|
- test/test_enum.rb
|
283
|
+
- test/test_predicates.rb
|
284
|
+
- test/test_validations.rb
|
285
|
+
- test/test_counter_cache.rb
|
297
286
|
- test/test_equal.rb
|
298
|
-
- test/
|
287
|
+
- test/test_suite.rb
|
288
|
+
- test/test_calculations.rb
|
289
|
+
- test/test_aliases.rb
|
290
|
+
- test/test_associations.rb
|
291
|
+
- test/test_serialize.rb
|
292
|
+
- test/test_create.rb
|
299
293
|
- test/test_find.rb
|
300
|
-
- test/
|
294
|
+
- test/test_composite_arrays.rb
|
301
295
|
- test/test_ids.rb
|
296
|
+
- test/test_delete.rb
|
302
297
|
- test/test_miscellaneous.rb
|
303
|
-
- test/
|
304
|
-
- test/
|
305
|
-
- test/
|
306
|
-
- test/
|
307
|
-
- test/test_predicates.rb
|
298
|
+
- test/test_exists.rb
|
299
|
+
- test/test_update.rb
|
300
|
+
- test/setup.rb
|
301
|
+
- test/abstract_unit.rb
|
308
302
|
- test/test_preload.rb
|
309
303
|
- test/test_santiago.rb
|
310
|
-
- test/
|
311
|
-
- test/
|
304
|
+
- test/test_dup.rb
|
305
|
+
- test/db_test.rb
|
306
|
+
- test/test_attribute_methods.rb
|
307
|
+
- test/test_polymorphic.rb
|
308
|
+
- test/test_habtm.rb
|
309
|
+
- test/test_dumpable.rb
|
310
|
+
- test/README_tests.rdoc
|
312
311
|
- test/test_touch.rb
|
312
|
+
- test/test_optimistic.rb
|
313
|
+
- test/test_nested_attributes.rb
|
313
314
|
- test/test_tutorial_example.rb
|
314
|
-
- test/
|
315
|
-
- test/
|
315
|
+
- test/test_callbacks.rb
|
316
|
+
- test/test_pagination.rb
|