composite_primary_keys 8.1.1 → 8.1.2

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +4 -1
  3. data/lib/composite_primary_keys.rb +5 -1
  4. data/lib/composite_primary_keys/arel/visitors/to_sql.rb +24 -0
  5. data/lib/composite_primary_keys/associations/association_scope.rb +32 -58
  6. data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +22 -22
  7. data/lib/composite_primary_keys/associations/preloader/association.rb +12 -6
  8. data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +19 -19
  9. data/lib/composite_primary_keys/attribute_methods/primary_key.rb +1 -2
  10. data/lib/composite_primary_keys/attribute_methods/read.rb +2 -2
  11. data/lib/composite_primary_keys/attribute_methods/write.rb +1 -1
  12. data/lib/composite_primary_keys/composite_predicates.rb +55 -50
  13. data/lib/composite_primary_keys/composite_relation.rb +48 -48
  14. data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +2 -2
  15. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +19 -46
  16. data/lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb +8 -4
  17. data/lib/composite_primary_keys/fixtures.rb +26 -22
  18. data/lib/composite_primary_keys/locking/optimistic.rb +54 -55
  19. data/lib/composite_primary_keys/relation.rb +15 -8
  20. data/lib/composite_primary_keys/relation/batches.rb +23 -19
  21. data/lib/composite_primary_keys/relation/calculations.rb +4 -2
  22. data/lib/composite_primary_keys/relation/finder_methods.rb +33 -27
  23. data/lib/composite_primary_keys/relation/predicate_builder.rb +18 -3
  24. data/lib/composite_primary_keys/relation/query_methods.rb +41 -41
  25. data/lib/composite_primary_keys/sanitization.rb +7 -5
  26. data/lib/composite_primary_keys/validations/uniqueness.rb +20 -16
  27. data/lib/composite_primary_keys/version.rb +1 -1
  28. data/tasks/databases/oracle.rake +27 -25
  29. data/tasks/databases/oracle_enhanced.rake +27 -0
  30. data/test/connections/databases.ci.yml +15 -15
  31. data/test/connections/native_oracle/connection.rb +11 -11
  32. data/test/connections/native_oracle_enhanced/connection.rb +16 -16
  33. data/test/fixtures/comment.rb +7 -7
  34. data/test/fixtures/db_definitions/db2-create-tables.sql +126 -126
  35. data/test/fixtures/db_definitions/db2-drop-tables.sql +18 -18
  36. data/test/fixtures/db_definitions/oracle.drop.sql +48 -45
  37. data/test/fixtures/db_definitions/oracle.sql +236 -223
  38. data/test/fixtures/dorm.rb +2 -2
  39. data/test/fixtures/membership.rb +6 -6
  40. data/test/fixtures/membership_statuses.yml +16 -16
  41. data/test/fixtures/memberships.yml +10 -10
  42. data/test/fixtures/product_tariffs.yml +14 -14
  43. data/test/fixtures/reference_code.rb +7 -7
  44. data/test/fixtures/restaurants_suburb.rb +2 -2
  45. data/test/fixtures/suburb.rb +5 -5
  46. data/test/fixtures/topic.rb +5 -5
  47. data/test/fixtures/topic_source.rb +6 -6
  48. data/test/fixtures/topic_sources.yml +3 -3
  49. data/test/fixtures/topics.yml +8 -8
  50. data/test/fixtures/users.yml +10 -10
  51. data/test/test_attribute_methods.rb +63 -63
  52. data/test/test_calculations.rb +42 -37
  53. data/test/test_callbacks.rb +99 -99
  54. data/test/test_delete.rb +28 -21
  55. data/test/test_delete_all.rb +5 -4
  56. data/test/test_dumpable.rb +15 -15
  57. data/test/test_nested_attributes.rb +124 -124
  58. data/test/test_optimistic.rb +18 -18
  59. data/test/test_polymorphic.rb +1 -1
  60. data/test/test_predicates.rb +40 -40
  61. data/test/test_santiago.rb +23 -23
  62. data/test/test_suite.rb +34 -34
  63. data/test/test_touch.rb +23 -23
  64. data/test/test_update.rb +71 -71
  65. metadata +9 -8
  66. data/lib/composite_primary_keys/model_schema.rb +0 -15
@@ -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 TestSantiago < ActiveSupport::TestCase
6
- fixtures :suburbs, :streets, :users, :articles, :readings
7
-
8
- def test_normal_and_composite_associations
9
- assert_not_nil @suburb = Suburb.find([1, 1])
10
- assert_equal 1, @suburb.streets.length
11
-
12
- assert_not_nil @street = Street.find(1)
13
- assert_not_nil @street.suburb
14
- end
15
-
16
- def test_single_keys
17
- @santiago = User.find(1)
18
- assert_not_nil @santiago.articles
19
- assert_equal 2, @santiago.articles.length
20
- assert_not_nil @santiago.readings
21
- assert_equal 2, @santiago.readings.length
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 TestSantiago < ActiveSupport::TestCase
6
+ fixtures :suburbs, :streets, :users, :articles, :readings
7
+
8
+ def test_normal_and_composite_associations
9
+ assert_not_nil @suburb = Suburb.find([1, 1])
10
+ assert_equal 1, @suburb.streets.length
11
+
12
+ assert_not_nil @street = Street.find(1)
13
+ assert_not_nil @street.suburb
14
+ end
15
+
16
+ def test_single_keys
17
+ @santiago = User.find(1)
18
+ assert_not_nil @santiago.articles
19
+ assert_equal 2, @santiago.articles.length
20
+ assert_not_nil @santiago.readings
21
+ assert_equal 2, @santiago.readings.length
22
+ end
23
+ end
data/test/test_suite.rb CHANGED
@@ -1,34 +1,34 @@
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_create
10
- test_delete
11
- test_delete_all
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_santiago
27
- test_serialize
28
- test_touch
29
- test_tutorial_example
30
- test_update
31
- test_validations
32
- ).each do |test|
33
- require File.expand_path("../#{test}", __FILE__)
34
- end
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_create
10
+ test_delete
11
+ test_delete_all
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_santiago
27
+ test_serialize
28
+ test_touch
29
+ test_tutorial_example
30
+ test_update
31
+ test_validations
32
+ ).each do |test|
33
+ require File.expand_path("../#{test}", __FILE__)
34
+ end
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
data/test/test_update.rb CHANGED
@@ -1,71 +1,71 @@
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(obj.primary_key_changed?)
44
- assert_equal({"reference_type_id" => 1, "reference_code" => 1}, obj.primary_key_was)
45
- assert_equal({"reference_type_id" => 2, "reference_code" => 3}, obj.ids_hash)
46
- assert(obj.save)
47
- assert(obj.reload)
48
- assert_equal(2, obj.reference_type_id)
49
- assert_equal(3, obj.reference_code)
50
- assert_equal({"reference_type_id" => 2, "reference_code" => 3}, obj.ids_hash)
51
- assert_equal([2, 3], obj.id)
52
- end
53
-
54
- def test_update_attribute
55
- obj = ReferenceType.find(1)
56
- obj[:abbreviation] = 'a'
57
- obj['abbreviation'] = 'b'
58
- assert(obj.save)
59
- assert(obj.reload)
60
- assert_equal('b', obj.abbreviation)
61
- end
62
-
63
- def test_update_all
64
- assert_nothing_raised do
65
- reference_code = ReferenceCode.create
66
- primary_key = reference_code.class.primary_key
67
- ReferenceCode.where(primary_key => reference_code[primary_key]).
68
- update_all(description: 'random value')
69
- end
70
- end
71
- 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(obj.primary_key_changed?)
44
+ assert_equal({"reference_type_id" => 1, "reference_code" => 1}, obj.primary_key_was)
45
+ assert_equal({"reference_type_id" => 2, "reference_code" => 3}, obj.ids_hash)
46
+ assert(obj.save)
47
+ assert(obj.reload)
48
+ assert_equal(2, obj.reference_type_id)
49
+ assert_equal(3, obj.reference_code)
50
+ assert_equal({"reference_type_id" => 2, "reference_code" => 3}, obj.ids_hash)
51
+ assert_equal([2, 3], obj.id)
52
+ end
53
+
54
+ def test_update_attribute
55
+ obj = ReferenceType.find(1)
56
+ obj[:abbreviation] = 'a'
57
+ obj['abbreviation'] = 'b'
58
+ assert(obj.save)
59
+ assert(obj.reload)
60
+ assert_equal('b', obj.abbreviation)
61
+ end
62
+
63
+ def test_update_all
64
+ assert_nothing_raised do
65
+ reference_code = ReferenceCode.create
66
+ primary_key = reference_code.class.primary_key
67
+ ReferenceCode.where(primary_key => reference_code[primary_key]).
68
+ update_all(description: 'random value')
69
+ end
70
+ end
71
+ 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: 8.1.1
4
+ version: 8.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-04 00:00:00.000000000 Z
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: mysql2
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.3.20
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.3.20
69
69
  description: Composite key support for ActiveRecord
70
70
  email:
71
71
  executables: []
@@ -77,6 +77,7 @@ files:
77
77
  - README_DB2.rdoc
78
78
  - Rakefile
79
79
  - lib/composite_primary_keys.rb
80
+ - lib/composite_primary_keys/arel/visitors/to_sql.rb
80
81
  - lib/composite_primary_keys/associations/association.rb
81
82
  - lib/composite_primary_keys/associations/association_scope.rb
82
83
  - lib/composite_primary_keys/associations/collection_association.rb
@@ -105,7 +106,6 @@ files:
105
106
  - lib/composite_primary_keys/dirty.rb
106
107
  - lib/composite_primary_keys/fixtures.rb
107
108
  - lib/composite_primary_keys/locking/optimistic.rb
108
- - lib/composite_primary_keys/model_schema.rb
109
109
  - lib/composite_primary_keys/nested_attributes.rb
110
110
  - lib/composite_primary_keys/persistence.rb
111
111
  - lib/composite_primary_keys/relation.rb
@@ -122,6 +122,7 @@ files:
122
122
  - scripts/txt2js
123
123
  - tasks/databases/mysql.rake
124
124
  - tasks/databases/oracle.rake
125
+ - tasks/databases/oracle_enhanced.rake
125
126
  - tasks/databases/postgresql.rake
126
127
  - tasks/databases/sqlite3.rake
127
128
  - tasks/databases/sqlserver.rake
@@ -265,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
265
266
  version: '0'
266
267
  requirements: []
267
268
  rubyforge_project:
268
- rubygems_version: 2.4.5
269
+ rubygems_version: 2.4.5.1
269
270
  signing_key:
270
271
  specification_version: 4
271
272
  summary: Composite key support for ActiveRecord
@@ -1,15 +0,0 @@
1
- module ActiveRecord
2
- module ModelSchema
3
- module ClassMethods
4
- def columns
5
- @columns ||= connection.schema_cache.columns(table_name).map do |col|
6
- col = col.dup
7
- # CPK
8
- #col.primary = (col.name == primary_key)
9
- col.primary = Array(primary_key).include?(col.name)
10
- col
11
- end
12
- end
13
- end
14
- end
15
- end