composite_primary_keys 10.0.5 → 11.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +5 -5
  2. data/History.rdoc +2 -15
  3. data/README.rdoc +2 -1
  4. data/lib/composite_primary_keys.rb +7 -7
  5. data/lib/composite_primary_keys/arel/to_sql.rb +12 -6
  6. data/lib/composite_primary_keys/associations/association.rb +12 -14
  7. data/lib/composite_primary_keys/associations/association_scope.rb +7 -2
  8. data/lib/composite_primary_keys/associations/collection_association.rb +14 -5
  9. data/lib/composite_primary_keys/associations/foreign_association.rb +15 -0
  10. data/lib/composite_primary_keys/associations/has_many_association.rb +3 -15
  11. data/lib/composite_primary_keys/associations/has_many_through_association.rb +56 -58
  12. data/lib/composite_primary_keys/associations/join_dependency.rb +69 -71
  13. data/lib/composite_primary_keys/associations/preloader/association.rb +92 -75
  14. data/lib/composite_primary_keys/attribute_methods.rb +4 -6
  15. data/lib/composite_primary_keys/attribute_methods/primary_key.rb +20 -23
  16. data/lib/composite_primary_keys/attribute_methods/read.rb +16 -18
  17. data/lib/composite_primary_keys/attribute_methods/write.rb +31 -33
  18. data/lib/composite_primary_keys/composite_arrays.rb +1 -1
  19. data/lib/composite_primary_keys/composite_predicates.rb +3 -0
  20. data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
  21. data/lib/composite_primary_keys/core.rb +40 -45
  22. data/lib/composite_primary_keys/fixtures.rb +17 -19
  23. data/lib/composite_primary_keys/locking/optimistic.rb +46 -38
  24. data/lib/composite_primary_keys/nested_attributes.rb +58 -60
  25. data/lib/composite_primary_keys/persistence.rb +72 -44
  26. data/lib/composite_primary_keys/reflection.rb +20 -0
  27. data/lib/composite_primary_keys/relation.rb +33 -79
  28. data/lib/composite_primary_keys/relation/batches.rb +7 -28
  29. data/lib/composite_primary_keys/relation/calculations.rb +28 -28
  30. data/lib/composite_primary_keys/relation/finder_methods.rb +34 -56
  31. data/lib/composite_primary_keys/relation/predicate_builder/association_query_value.rb +18 -0
  32. data/lib/composite_primary_keys/relation/query_methods.rb +23 -11
  33. data/lib/composite_primary_keys/relation/where_clause.rb +13 -22
  34. data/lib/composite_primary_keys/sanitization.rb +0 -2
  35. data/lib/composite_primary_keys/version.rb +3 -3
  36. data/scripts/console.rb +48 -48
  37. data/scripts/txt2html +76 -76
  38. data/scripts/txt2js +65 -65
  39. data/tasks/website.rake +18 -18
  40. data/test/README_tests.rdoc +56 -56
  41. data/test/connections/databases.yml +30 -40
  42. data/test/db_test.rb +52 -52
  43. data/test/fixtures/articles.yml +6 -6
  44. data/test/fixtures/capitol.rb +3 -3
  45. data/test/fixtures/capitols.yml +16 -16
  46. data/test/fixtures/comments.yml +15 -15
  47. data/test/fixtures/department.rb +5 -5
  48. data/test/fixtures/departments.yml +15 -15
  49. data/test/fixtures/dorms.yml +4 -4
  50. data/test/fixtures/group.rb +2 -2
  51. data/test/fixtures/groups.yml +6 -6
  52. data/test/fixtures/hack.rb +4 -4
  53. data/test/fixtures/hacks.yml +2 -2
  54. data/test/fixtures/membership_status.rb +2 -2
  55. data/test/fixtures/product.rb +9 -9
  56. data/test/fixtures/product_tariff.rb +5 -5
  57. data/test/fixtures/products.yml +11 -11
  58. data/test/fixtures/reading.rb +4 -4
  59. data/test/fixtures/readings.yml +10 -10
  60. data/test/fixtures/reference_code_using_composite_key_alias.rb +8 -8
  61. data/test/fixtures/reference_code_using_simple_key_alias.rb +8 -8
  62. data/test/fixtures/reference_codes.yml +28 -28
  63. data/test/fixtures/reference_types.yml +9 -9
  64. data/test/fixtures/restaurant.rb +9 -9
  65. data/test/fixtures/restaurants.yml +14 -14
  66. data/test/fixtures/restaurants_suburbs.yml +10 -10
  67. data/test/fixtures/room.rb +11 -11
  68. data/test/fixtures/room_assignment.rb +13 -13
  69. data/test/fixtures/room_assignments.yml +24 -24
  70. data/test/fixtures/room_attribute.rb +2 -2
  71. data/test/fixtures/room_attribute_assignment.rb +4 -4
  72. data/test/fixtures/room_attribute_assignments.yml +4 -4
  73. data/test/fixtures/room_attributes.yml +2 -2
  74. data/test/fixtures/rooms.yml +12 -12
  75. data/test/fixtures/seat.rb +5 -5
  76. data/test/fixtures/seats.yml +8 -8
  77. data/test/fixtures/street.rb +2 -2
  78. data/test/fixtures/streets.yml +16 -16
  79. data/test/fixtures/student.rb +3 -3
  80. data/test/fixtures/students.yml +15 -15
  81. data/test/fixtures/suburbs.yml +14 -14
  82. data/test/fixtures/tariffs.yml +1 -1
  83. data/test/plugins/pagination.rb +405 -405
  84. data/test/plugins/pagination_helper.rb +135 -135
  85. data/test/setup.rb +50 -50
  86. data/test/test_aliases.rb +18 -18
  87. data/test/test_associations.rb +6 -20
  88. data/test/test_composite_arrays.rb +24 -24
  89. data/test/test_counter_cache.rb +30 -30
  90. data/test/test_delete.rb +146 -146
  91. data/test/test_dup.rb +37 -37
  92. data/test/test_exists.rb +39 -39
  93. data/test/test_find.rb +1 -1
  94. data/test/test_miscellaneous.rb +32 -32
  95. data/test/test_pagination.rb +35 -35
  96. data/test/test_preload.rb +0 -7
  97. data/test/test_validations.rb +13 -13
  98. metadata +10 -17
  99. data/lib/composite_primary_keys/arel/in.rb +0 -6
  100. data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +0 -24
  101. data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +0 -19
  102. data/lib/composite_primary_keys/relation/predicate_builder/association_query_handler.rb +0 -33
@@ -1,40 +1,40 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestExists < ActiveSupport::TestCase
4
- fixtures :articles, :departments, :capitols
5
-
6
- def test_id
7
- assert(Article.exists?(1))
8
- assert(!Article.exists?(-1))
9
- end
10
-
11
- def test_array
12
- assert(Article.exists?(['name = ?', 'Article One']))
13
- assert(!Article.exists?(['name = ?', 'Article -1']))
14
- end
15
-
16
- def test_hash
17
- assert(Article.exists?('name' => 'Article One'))
18
- assert(!Article.exists?('name' => 'Article -1'))
19
- end
20
-
21
- def test_cpk_id
22
- assert(Department.exists?(CompositePrimaryKeys::CompositeKeys.new([1,1])))
23
- assert(!Department.exists?(CompositePrimaryKeys::CompositeKeys.new([1,-1])))
24
- end
25
-
26
- def test_cpk_array_id
27
- assert(Department.exists?([1,1]))
28
- assert(!Department.exists?([1,-1]))
29
- end
30
-
31
- def test_cpk_array_condition
32
- assert(Department.exists?(['department_id = ? and location_id = ?', 1, 1]))
33
- assert(!Department.exists?(['department_id = ? and location_id = ?', 1, -1]))
34
- end
35
-
36
- def test_cpk_array_string_id
37
- assert(Capitol.exists?(['The Netherlands', 'Amsterdam']))
38
- assert(!Capitol.exists?(['The Netherlands', 'Paris']))
39
- end
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class TestExists < ActiveSupport::TestCase
4
+ fixtures :articles, :departments, :capitols
5
+
6
+ def test_id
7
+ assert(Article.exists?(1))
8
+ assert(!Article.exists?(-1))
9
+ end
10
+
11
+ def test_array
12
+ assert(Article.exists?(['name = ?', 'Article One']))
13
+ assert(!Article.exists?(['name = ?', 'Article -1']))
14
+ end
15
+
16
+ def test_hash
17
+ assert(Article.exists?('name' => 'Article One'))
18
+ assert(!Article.exists?('name' => 'Article -1'))
19
+ end
20
+
21
+ def test_cpk_id
22
+ assert(Department.exists?(CompositePrimaryKeys::CompositeKeys.new([1,1])))
23
+ assert(!Department.exists?(CompositePrimaryKeys::CompositeKeys.new([1,-1])))
24
+ end
25
+
26
+ def test_cpk_array_id
27
+ assert(Department.exists?([1,1]))
28
+ assert(!Department.exists?([1,-1]))
29
+ end
30
+
31
+ def test_cpk_array_condition
32
+ assert(Department.exists?(['department_id = ? and location_id = ?', 1, 1]))
33
+ assert(!Department.exists?(['department_id = ? and location_id = ?', 1, -1]))
34
+ end
35
+
36
+ def test_cpk_array_string_id
37
+ assert(Capitol.exists?(['The Netherlands', 'Amsterdam']))
38
+ assert(!Capitol.exists?(['The Netherlands', 'Paris']))
39
+ end
40
40
  end
@@ -62,7 +62,7 @@ class TestFind < ActiveSupport::TestCase
62
62
  ReferenceCode.find(['999', '999'])
63
63
  end
64
64
 
65
- expected = "Couldn't find all ReferenceCodes with 'reference_type_id,reference_code': (999, 999) (found 0 results, but was looking for 1)"
65
+ expected = "Couldn't find all ReferenceCodes with 'reference_type_id,reference_code': (999, 999) (found 0 results, but was looking for 1)."
66
66
  assert_equal(with_quoted_identifiers(expected), error.message)
67
67
  end
68
68
 
@@ -1,32 +1,32 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestMiscellaneous < ActiveSupport::TestCase
4
- fixtures :reference_types, :reference_codes, :products
5
-
6
- CLASSES = {
7
- :single => {
8
- :class => ReferenceType,
9
- :primary_keys => :reference_type_id,
10
- },
11
- :dual => {
12
- :class => ReferenceCode,
13
- :primary_keys => [:reference_type_id, :reference_code],
14
- },
15
- }
16
-
17
- def setup
18
- self.class.classes = CLASSES
19
- end
20
-
21
- def test_composite_class
22
- testing_with do
23
- assert_equal composite?, @klass.composite?
24
- end
25
- end
26
-
27
- def test_composite_instance
28
- testing_with do
29
- assert_equal composite?, @first.composite?
30
- end
31
- end
32
- end
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class TestMiscellaneous < ActiveSupport::TestCase
4
+ fixtures :reference_types, :reference_codes, :products
5
+
6
+ CLASSES = {
7
+ :single => {
8
+ :class => ReferenceType,
9
+ :primary_keys => :reference_type_id,
10
+ },
11
+ :dual => {
12
+ :class => ReferenceCode,
13
+ :primary_keys => [:reference_type_id, :reference_code],
14
+ },
15
+ }
16
+
17
+ def setup
18
+ self.class.classes = CLASSES
19
+ end
20
+
21
+ def test_composite_class
22
+ testing_with do
23
+ assert_equal composite?, @klass.composite?
24
+ end
25
+ end
26
+
27
+ def test_composite_instance
28
+ testing_with do
29
+ assert_equal composite?, @first.composite?
30
+ end
31
+ end
32
+ end
@@ -1,36 +1,36 @@
1
- #require File.expand_path('../abstract_unit', __FILE__)
2
- #require 'plugins/pagination'
3
- #
4
- #class TestPagination < ActiveSupport::TestCase
5
- # fixtures :reference_types, :reference_codes
6
- #
7
- # include ActionController::Pagination
8
- # DEFAULT_PAGE_SIZE = 2
9
- #
10
- # attr_accessor :params
11
- #
12
- # CLASSES = {
13
- # :single => {
14
- # :class => ReferenceType,
15
- # :primary_keys => :reference_type_id,
16
- # :table => :reference_types,
17
- # },
18
- # :dual => {
19
- # :class => ReferenceCode,
20
- # :primary_keys => [:reference_type_id, :reference_code],
21
- # :table => :reference_codes,
22
- # },
23
- # }
24
- #
25
- # def setup
26
- # self.class.classes = CLASSES
27
- # @params = {}
28
- # end
29
- #
30
- # def test_paginate_all
31
- # testing_with do
32
- # @object_pages, @objects = paginate @klass_info[:table], :per_page => DEFAULT_PAGE_SIZE
33
- # assert_equal 2, @objects.length, "Each page should have #{DEFAULT_PAGE_SIZE} items"
34
- # end
35
- # end
1
+ #require File.expand_path('../abstract_unit', __FILE__)
2
+ #require 'plugins/pagination'
3
+ #
4
+ #class TestPagination < ActiveSupport::TestCase
5
+ # fixtures :reference_types, :reference_codes
6
+ #
7
+ # include ActionController::Pagination
8
+ # DEFAULT_PAGE_SIZE = 2
9
+ #
10
+ # attr_accessor :params
11
+ #
12
+ # CLASSES = {
13
+ # :single => {
14
+ # :class => ReferenceType,
15
+ # :primary_keys => :reference_type_id,
16
+ # :table => :reference_types,
17
+ # },
18
+ # :dual => {
19
+ # :class => ReferenceCode,
20
+ # :primary_keys => [:reference_type_id, :reference_code],
21
+ # :table => :reference_codes,
22
+ # },
23
+ # }
24
+ #
25
+ # def setup
26
+ # self.class.classes = CLASSES
27
+ # @params = {}
28
+ # end
29
+ #
30
+ # def test_paginate_all
31
+ # testing_with do
32
+ # @object_pages, @objects = paginate @klass_info[:table], :per_page => DEFAULT_PAGE_SIZE
33
+ # assert_equal 2, @objects.length, "Each page should have #{DEFAULT_PAGE_SIZE} items"
34
+ # end
35
+ # end
36
36
  #end
@@ -91,11 +91,4 @@ class TestPreload < ActiveSupport::TestCase
91
91
  assert_equal(1, employees.first.groups_2.size)
92
92
  assert_equal(2, employees.second.groups_2.size)
93
93
  end
94
-
95
- def test_preload_settings_inversion
96
- users = User.preload(:readings).all
97
- reading = users.first.readings.first
98
-
99
- assert_equal(true, reading.association(:user).loaded?)
100
- end
101
94
  end
@@ -1,13 +1,13 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestValidations < ActiveSupport::TestCase
4
- fixtures :students, :dorms, :rooms, :room_assignments
5
-
6
- def test_uniqueness_validation_persisted
7
- room_assignment = RoomAssignment.find([1, 1, 1])
8
- assert(room_assignment.valid?)
9
-
10
- room_assignment = RoomAssignment.new(:student_id => 1, :dorm_id => 1, :room_id => 2)
11
- assert(!room_assignment.valid?)
12
- end
13
- end
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class TestValidations < ActiveSupport::TestCase
4
+ fixtures :students, :dorms, :rooms, :room_assignments
5
+
6
+ def test_uniqueness_validation_persisted
7
+ room_assignment = RoomAssignment.find([1, 1, 1])
8
+ assert(room_assignment.valid?)
9
+
10
+ room_assignment = RoomAssignment.new(:student_id => 1, :dorm_id => 1, :room_id => 2)
11
+ assert(!room_assignment.valid?)
12
+ end
13
+ 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: 10.0.5
4
+ version: 11.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-24 00:00:00.000000000 Z
11
+ date: 2017-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.1.0
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 5.1.6
19
+ version: 5.2.0.beta2
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 5.1.0
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 5.1.6
26
+ version: 5.2.0.beta2
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rake
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -96,18 +90,16 @@ files:
96
90
  - README.rdoc
97
91
  - Rakefile
98
92
  - lib/composite_primary_keys.rb
99
- - lib/composite_primary_keys/arel/in.rb
100
93
  - lib/composite_primary_keys/arel/sqlserver.rb
101
94
  - lib/composite_primary_keys/arel/to_sql.rb
102
95
  - lib/composite_primary_keys/associations/association.rb
103
96
  - lib/composite_primary_keys/associations/association_scope.rb
104
97
  - lib/composite_primary_keys/associations/collection_association.rb
98
+ - lib/composite_primary_keys/associations/foreign_association.rb
105
99
  - lib/composite_primary_keys/associations/has_many_association.rb
106
100
  - lib/composite_primary_keys/associations/has_many_through_association.rb
107
101
  - lib/composite_primary_keys/associations/join_dependency.rb
108
- - lib/composite_primary_keys/associations/join_dependency/join_association.rb
109
102
  - lib/composite_primary_keys/associations/preloader/association.rb
110
- - lib/composite_primary_keys/associations/preloader/belongs_to.rb
111
103
  - lib/composite_primary_keys/attribute_methods.rb
112
104
  - lib/composite_primary_keys/attribute_methods/primary_key.rb
113
105
  - lib/composite_primary_keys/attribute_methods/read.rb
@@ -127,11 +119,12 @@ files:
127
119
  - lib/composite_primary_keys/locking/optimistic.rb
128
120
  - lib/composite_primary_keys/nested_attributes.rb
129
121
  - lib/composite_primary_keys/persistence.rb
122
+ - lib/composite_primary_keys/reflection.rb
130
123
  - lib/composite_primary_keys/relation.rb
131
124
  - lib/composite_primary_keys/relation/batches.rb
132
125
  - lib/composite_primary_keys/relation/calculations.rb
133
126
  - lib/composite_primary_keys/relation/finder_methods.rb
134
- - lib/composite_primary_keys/relation/predicate_builder/association_query_handler.rb
127
+ - lib/composite_primary_keys/relation/predicate_builder/association_query_value.rb
135
128
  - lib/composite_primary_keys/relation/query_methods.rb
136
129
  - lib/composite_primary_keys/relation/where_clause.rb
137
130
  - lib/composite_primary_keys/sanitization.rb
@@ -273,12 +266,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
273
266
  version: 2.2.2
274
267
  required_rubygems_version: !ruby/object:Gem::Requirement
275
268
  requirements:
276
- - - ">="
269
+ - - ">"
277
270
  - !ruby/object:Gem::Version
278
- version: '0'
271
+ version: 1.3.1
279
272
  requirements: []
280
273
  rubyforge_project:
281
- rubygems_version: 2.7.6
274
+ rubygems_version: 2.6.13
282
275
  signing_key:
283
276
  specification_version: 4
284
277
  summary: Composite key support for ActiveRecord
@@ -1,6 +0,0 @@
1
- module CompositePrimaryKeys
2
- module Nodes
3
- class In < ::Arel::Nodes::Equality
4
- end
5
- end
6
- end
@@ -1,24 +0,0 @@
1
- module ActiveRecord
2
- module Associations
3
- class JoinDependency
4
- class JoinAssociation
5
- silence_warnings do
6
- def build_constraint(klass, table, key, foreign_table, foreign_key)
7
- # CPK
8
- # constraint = table[key].eq(foreign_table[foreign_key])
9
- constraint = cpk_join_predicate(table, key, foreign_table, foreign_key)
10
-
11
- if klass.finder_needs_type_condition?
12
- constraint = table.create_and([
13
- constraint,
14
- klass.send(:type_condition, table)
15
- ])
16
- end
17
-
18
- constraint
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,19 +0,0 @@
1
- module ActiveRecord
2
- module Associations
3
- class Preloader
4
- class BelongsTo
5
- def records_for(ids)
6
- # CPK
7
- # scope.where(association_key.in(ids))
8
-
9
- if association_key_name.is_a?(Array)
10
- predicate = cpk_in_predicate(table, association_key_name, ids)
11
- scope.where(predicate)
12
- else
13
- scope.where(association_key_name => ids)
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,33 +0,0 @@
1
- module ActiveRecord
2
- class PredicateBuilder
3
- class AssociationQueryHandler
4
- def call(attribute, value)
5
- queries = {}
6
-
7
- table = value.associated_table
8
- if value.base_class
9
- queries[table.association_foreign_type.to_s] = value.base_class.name
10
- end
11
-
12
- # CPK
13
- # queries[table.association_foreign_key.to_s] = value.ids
14
- # predicate_builder.build_from_hash(queries)
15
- if table.association_foreign_key.is_a?(Array)
16
- values = case value.value
17
- when Relation
18
- value.ids.map {|record| record.ids}
19
- when Array
20
- value.ids
21
- else
22
- [value.ids]
23
- end
24
-
25
- CompositePrimaryKeys::Predicates.cpk_in_predicate(attribute.relation, table.association_foreign_key, values)
26
- else
27
- queries[table.association_foreign_key.to_s] = value.ids
28
- predicate_builder.build_from_hash(queries)
29
- end
30
- end
31
- end
32
- end
33
- end