composite_primary_keys 3.1.11 → 4.0.0.beta1

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 (62) hide show
  1. data/History.txt +6 -8
  2. data/lib/composite_primary_keys.rb +53 -36
  3. data/lib/composite_primary_keys/associations/association.rb +23 -0
  4. data/lib/composite_primary_keys/associations/association_scope.rb +67 -0
  5. data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +31 -121
  6. data/lib/composite_primary_keys/associations/has_many_association.rb +27 -66
  7. data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +22 -0
  8. data/lib/composite_primary_keys/associations/join_dependency/join_part.rb +39 -0
  9. data/lib/composite_primary_keys/associations/preloader/association.rb +61 -0
  10. data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +13 -0
  11. data/lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb +46 -0
  12. data/lib/composite_primary_keys/attribute_methods/dirty.rb +30 -0
  13. data/lib/composite_primary_keys/attribute_methods/read.rb +88 -0
  14. data/lib/composite_primary_keys/attribute_methods/write.rb +33 -0
  15. data/lib/composite_primary_keys/base.rb +18 -70
  16. data/lib/composite_primary_keys/composite_predicates.rb +53 -0
  17. data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +6 -4
  18. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +19 -41
  19. data/lib/composite_primary_keys/fixtures.rb +19 -6
  20. data/lib/composite_primary_keys/persistence.rb +32 -13
  21. data/lib/composite_primary_keys/relation.rb +23 -16
  22. data/lib/composite_primary_keys/relation/calculations.rb +48 -0
  23. data/lib/composite_primary_keys/relation/finder_methods.rb +117 -0
  24. data/lib/composite_primary_keys/relation/query_methods.rb +24 -0
  25. data/lib/composite_primary_keys/validations/uniqueness.rb +19 -23
  26. data/lib/composite_primary_keys/version.rb +5 -5
  27. data/test/connections/native_mysql/connection.rb +1 -1
  28. data/test/fixtures/articles.yml +1 -0
  29. data/test/fixtures/products.yml +2 -4
  30. data/test/fixtures/readings.yml +1 -0
  31. data/test/fixtures/suburbs.yml +1 -4
  32. data/test/fixtures/users.yml +1 -0
  33. data/test/test_associations.rb +61 -63
  34. data/test/test_attributes.rb +16 -21
  35. data/test/test_create.rb +3 -3
  36. data/test/test_delete.rb +87 -84
  37. data/test/{test_clone.rb → test_dup.rb} +8 -5
  38. data/test/test_exists.rb +22 -10
  39. data/test/test_habtm.rb +0 -74
  40. data/test/test_ids.rb +2 -1
  41. data/test/test_miscellaneous.rb +2 -2
  42. data/test/test_polymorphic.rb +1 -1
  43. data/test/test_suite.rb +1 -1
  44. data/test/test_update.rb +3 -3
  45. metadata +76 -75
  46. data/lib/composite_primary_keys/association_preload.rb +0 -158
  47. data/lib/composite_primary_keys/associations.rb +0 -155
  48. data/lib/composite_primary_keys/associations/association_proxy.rb +0 -33
  49. data/lib/composite_primary_keys/associations/has_one_association.rb +0 -27
  50. data/lib/composite_primary_keys/associations/through_association_scope.rb +0 -103
  51. data/lib/composite_primary_keys/attribute_methods.rb +0 -84
  52. data/lib/composite_primary_keys/calculations.rb +0 -31
  53. data/lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb +0 -21
  54. data/lib/composite_primary_keys/connection_adapters/oracle_adapter.rb +0 -15
  55. data/lib/composite_primary_keys/connection_adapters/oracle_enhanced_adapter.rb +0 -17
  56. data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +0 -15
  57. data/lib/composite_primary_keys/finder_methods.rb +0 -123
  58. data/lib/composite_primary_keys/primary_key.rb +0 -19
  59. data/lib/composite_primary_keys/query_methods.rb +0 -24
  60. data/lib/composite_primary_keys/read.rb +0 -25
  61. data/lib/composite_primary_keys/reflection.rb +0 -37
  62. data/lib/composite_primary_keys/write.rb +0 -18
@@ -18,14 +18,17 @@ class TestClone < ActiveSupport::TestCase
18
18
  self.class.classes = CLASSES
19
19
  end
20
20
 
21
- def test_truth
21
+ def test_dup
22
22
  testing_with do
23
- clone = @first.clone
24
- assert_equal @first.attributes.block(@klass.primary_key), clone.attributes
23
+ clone = @first.dup
24
+ assert_equal(@first.attributes.block(@klass.primary_key), clone.attributes)
25
+
25
26
  if composite?
26
- @klass.primary_key.each {|key| assert_nil clone[key], "Primary key '#{key}' should be nil"}
27
+ @klass.primary_key.each do |key|
28
+ assert_nil(clone[key], "Primary key '#{key}' should be nil")
29
+ end
27
30
  else
28
- assert_nil clone[@klass.primary_key], "Sole primary key should be nil"
31
+ assert_nil(clone[@klass.primary_key], "Sole primary key should be nil")
29
32
  end
30
33
  end
31
34
  end
@@ -3,21 +3,33 @@ require 'abstract_unit'
3
3
  class TestExists < ActiveSupport::TestCase
4
4
  fixtures :articles, :departments
5
5
 
6
- def test_single_key_exists_giving_id
7
- assert Article.exists?(1)
6
+ def test_id
7
+ assert(Article.exists?(1))
8
+ assert(!Article.exists?(-1))
8
9
  end
9
10
 
10
- def test_single_key_exists_giving_condition
11
- assert Article.exists?(['name = ?', 'Article One'])
11
+ def test_array
12
+ assert(Article.exists?(['name = ?', 'Article One']))
13
+ assert(!Article.exists?(['name = ?', 'Article -1']))
12
14
  end
13
15
 
14
- def test_composite_key_exists_giving_ids_as_array
15
- assert Department.exists?([1,1])
16
- assert_equal(false, Department.exists?([1111,1111]))
16
+ def test_hash
17
+ assert(Article.exists?('name' => 'Article One'))
18
+ assert(!Article.exists?('name' => 'Article -1'))
17
19
  end
18
20
 
19
- def test_composite_key_exists_giving_ids_as_condition
20
- assert Department.exists?(['department_id = ? and location_id = ?', 1, 1])
21
- assert_equal(false, Department.exists?(['department_id = ? and location_id = ?', 11111, 11111]))
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]))
22
34
  end
23
35
  end
@@ -1,5 +1,4 @@
1
1
  require 'abstract_unit'
2
- require 'ruby-debug'
3
2
 
4
3
  class TestHabtm < ActiveSupport::TestCase
5
4
 
@@ -13,48 +12,6 @@ class TestHabtm < ActiveSupport::TestCase
13
12
  assert_equal 2, @restaurant.suburbs.size
14
13
  end
15
14
 
16
- def test_include_cpk_both_sides
17
- # assuming the association was set up in the fixtures
18
- # file restaurants_suburbs.yml
19
- mcdonalds = restaurants(:mcdonalds)
20
- # check positive
21
- suburb = mcdonalds.suburbs[0]
22
- assert mcdonalds.suburbs.include?(suburb)
23
- # check negative
24
- suburb_with_no_mcdonalds = suburbs(:no_mcdonalds)
25
- assert !mcdonalds.suburbs.include?(suburb_with_no_mcdonalds)
26
- end
27
-
28
- def test_include_cpk_owner_side_only
29
- subway = restaurants(:subway_one)
30
- product = products(:first_product)
31
- subway.products << product
32
-
33
- # reload
34
- # test positive
35
- subway = restaurants(:subway_one)
36
- assert subway.products.include?(product)
37
-
38
- # test negative
39
- product_two = products(:second_product)
40
- assert !subway.products.include?(product_two)
41
- end
42
-
43
- def test_include_cpk_association_side_only
44
- product = products(:first_product)
45
- subway = restaurants(:subway_one)
46
- product.restaurants << subway
47
-
48
- # reload
49
- # test positive
50
- product = products(:first_product)
51
- assert product.restaurants.include?(subway)
52
-
53
- # test negative
54
- mcdonalds = restaurants(:mcdonalds)
55
- assert !product.restaurants.include?(mcdonalds)
56
- end
57
-
58
15
  def test_habtm_clear_cpk_both_sides
59
16
  @restaurant = restaurants(:mcdonalds)
60
17
  assert_equal 2, @restaurant.suburbs.size
@@ -69,8 +26,6 @@ class TestHabtm < ActiveSupport::TestCase
69
26
  subway.products << first_product << second_product
70
27
  assert_equal 2, subway.products.size
71
28
  subway.products.clear
72
- # reload to force reload of associations
73
- subway = restaurants(:subway_one)
74
29
  assert_equal 0, subway.products.size
75
30
  end
76
31
 
@@ -81,36 +36,7 @@ class TestHabtm < ActiveSupport::TestCase
81
36
  product.restaurants << subway_one << subway_two
82
37
  assert_equal 2, product.restaurants.size
83
38
  product.restaurants.clear
84
- # reload to force reload of associations
85
- product = products(:first_product)
86
39
  assert_equal 0, product.restaurants.size
87
40
  end
88
41
 
89
- # tests case reported in issue #39 where a bug resulted in
90
- # deletion of incorrect join table records because the owner's id
91
- # was assumed to be an array and is not in this case
92
- # and evaluates to a useable but incorrect value
93
- def test_habtm_clear_cpk_association_side_only_deletes_only_correct_records
94
- product_one = Product.find(1)
95
- product_three = Product.find(3)
96
- subway_one = restaurants(:subway_one)
97
- subway_two = restaurants(:subway_two)
98
- product_one.restaurants << subway_one << subway_two
99
- product_three.restaurants << subway_one << subway_two
100
- assert_equal 2, product_one.restaurants.size
101
- assert_equal 2, product_three.restaurants.size
102
-
103
- # if product_three's id is incorrectly assumed to be
104
- # an array it will be evaluated as 3[0], which is 1, which would
105
- # delete product_one's associations rather than product_three's
106
- product_three.restaurants.clear
107
-
108
- # reload to force reload of associations
109
- product_one = Product.find(1)
110
- product_three = Product.find(3)
111
-
112
- assert_equal 0, product_three.restaurants.size
113
- assert_equal 2, product_one.restaurants.size
114
- end
115
-
116
42
  end
@@ -71,7 +71,8 @@ class TestIds < ActiveSupport::TestCase
71
71
  assert_not_nil @klass.primary_keys
72
72
  assert_equal @primary_keys.map {|key| key.to_sym}, @klass.primary_keys
73
73
  assert_equal @klass.primary_keys, @klass.primary_key
74
- assert_equal @primary_keys.map {|key| key.to_sym}.to_s, @klass.primary_key.to_s
74
+ assert_kind_of(CompositePrimaryKeys::CompositeKeys, @klass.primary_keys)
75
+ assert_equal @primary_keys.map {|key| key.to_sym}.join(','), @klass.primary_key.to_s
75
76
  else
76
77
  assert_not_nil @klass.primary_key
77
78
  assert_equal @primary_keys.first, @klass.primary_key.to_sym
@@ -31,7 +31,7 @@ class TestMiscellaneous < ActiveSupport::TestCase
31
31
  end
32
32
 
33
33
  def test_count
34
- assert_equal 3, Product.count
34
+ assert_equal 2, Product.count
35
35
  end
36
36
 
37
- end
37
+ end
@@ -21,6 +21,6 @@ class TestPolymorphic < ActiveSupport::TestCase
21
21
 
22
22
  def test_polymorphic_has_many_through
23
23
  user = users(:santiago)
24
- assert_equal ['andrew'], user.hacks.collect { |a| a.name }.sort
24
+ assert_equal(['andrew'], user.hacks.collect { |a| a.name }.sort)
25
25
  end
26
26
  end
@@ -3,10 +3,10 @@ require 'test/unit'
3
3
  require 'test_associations'
4
4
  require 'test_attribute_methods'
5
5
  require 'test_attributes'
6
- require 'test_clone'
7
6
  require 'test_composite_arrays'
8
7
  require 'test_create'
9
8
  require 'test_delete'
9
+ require 'test_dup'
10
10
  require 'test_equal'
11
11
  require 'test_exists'
12
12
  require 'test_find'
@@ -28,10 +28,10 @@ class TestUpdate < ActiveSupport::TestCase
28
28
 
29
29
  def test_update_attributes
30
30
  testing_with do
31
- assert @first.update_attributes(@klass_info[:update])
32
- assert @first.reload
31
+ assert(@first.update_attributes(@klass_info[:update]))
32
+ assert(@first.reload)
33
33
  @klass_info[:update].each_pair do |attr_name, new_value|
34
- assert_equal new_value, @first[attr_name], "Attribute #{attr_name} is incorrect"
34
+ assert_equal(new_value, @first[attr_name])
35
35
  end
36
36
  end
37
37
  end
metadata CHANGED
@@ -1,62 +1,53 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: composite_primary_keys
3
- version: !ruby/object:Gem::Version
4
- version: 3.1.11
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 62196257
5
+ prerelease: 6
6
+ segments:
7
+ - 4
8
+ - 0
9
+ - 0
10
+ - beta
11
+ - 1
12
+ version: 4.0.0.beta1
6
13
  platform: ruby
7
- authors:
14
+ authors:
8
15
  - Dr Nic Williams
9
16
  - Charlie Savage
10
17
  autorequire:
11
18
  bindir: bin
12
19
  cert_chain: []
13
- date: 2012-05-20 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
20
+
21
+ date: 2011-06-09 00:00:00 Z
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
16
24
  name: activerecord
17
- requirement: !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ~>
21
- - !ruby/object:Gem::Version
22
- version: 3.0.0
23
- - - ! '>='
24
- - !ruby/object:Gem::Version
25
- version: 3.0.5
26
- type: :runtime
27
- prerelease: false
28
- version_requirements: !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 3.0.0
34
- - - ! '>='
35
- - !ruby/object:Gem::Version
36
- version: 3.0.5
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
- requirement: !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: '0'
45
- type: :development
46
25
  prerelease: false
47
- version_requirements: !ruby/object:Gem::Requirement
26
+ requirement: &id001 !ruby/object:Gem::Requirement
48
27
  none: false
49
- requirements:
50
- - - ! '>='
51
- - !ruby/object:Gem::Version
52
- version: '0'
28
+ requirements:
29
+ - - "="
30
+ - !ruby/object:Gem::Version
31
+ hash: 15424103
32
+ segments:
33
+ - 3
34
+ - 1
35
+ - 0
36
+ - rc
37
+ - 1
38
+ version: 3.1.0.rc1
39
+ type: :runtime
40
+ version_requirements: *id001
53
41
  description: Composite key support for ActiveRecord 3
54
- email:
42
+ email:
55
43
  - drnicwilliams@gmail.com
56
44
  executables: []
45
+
57
46
  extensions: []
47
+
58
48
  extra_rdoc_files: []
59
- files:
49
+
50
+ files:
60
51
  - Rakefile
61
52
  - History.txt
62
53
  - README.txt
@@ -64,34 +55,31 @@ files:
64
55
  - init.rb
65
56
  - install.rb
66
57
  - loader.rb
67
- - lib/composite_primary_keys/associations/association_proxy.rb
58
+ - lib/composite_primary_keys/associations/association.rb
59
+ - lib/composite_primary_keys/associations/association_scope.rb
68
60
  - lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb
69
61
  - lib/composite_primary_keys/associations/has_many_association.rb
70
- - lib/composite_primary_keys/associations/has_one_association.rb
71
- - lib/composite_primary_keys/associations/through_association_scope.rb
72
- - lib/composite_primary_keys/associations.rb
73
- - lib/composite_primary_keys/association_preload.rb
74
- - lib/composite_primary_keys/attribute_methods.rb
62
+ - lib/composite_primary_keys/associations/join_dependency/join_association.rb
63
+ - lib/composite_primary_keys/associations/join_dependency/join_part.rb
64
+ - lib/composite_primary_keys/associations/preloader/association.rb
65
+ - lib/composite_primary_keys/associations/preloader/belongs_to.rb
66
+ - lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb
67
+ - lib/composite_primary_keys/attribute_methods/dirty.rb
68
+ - lib/composite_primary_keys/attribute_methods/read.rb
69
+ - lib/composite_primary_keys/attribute_methods/write.rb
75
70
  - lib/composite_primary_keys/base.rb
76
- - lib/composite_primary_keys/calculations.rb
77
71
  - lib/composite_primary_keys/composite_arrays.rb
72
+ - lib/composite_primary_keys/composite_predicates.rb
78
73
  - lib/composite_primary_keys/connection_adapters/abstract_adapter.rb
79
- - lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb
80
- - lib/composite_primary_keys/connection_adapters/oracle_adapter.rb
81
- - lib/composite_primary_keys/connection_adapters/oracle_enhanced_adapter.rb
82
74
  - lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
83
- - lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb
84
- - lib/composite_primary_keys/finder_methods.rb
85
75
  - lib/composite_primary_keys/fixtures.rb
86
76
  - lib/composite_primary_keys/persistence.rb
87
- - lib/composite_primary_keys/primary_key.rb
88
- - lib/composite_primary_keys/query_methods.rb
89
- - lib/composite_primary_keys/read.rb
90
- - lib/composite_primary_keys/reflection.rb
77
+ - lib/composite_primary_keys/relation/calculations.rb
78
+ - lib/composite_primary_keys/relation/finder_methods.rb
79
+ - lib/composite_primary_keys/relation/query_methods.rb
91
80
  - lib/composite_primary_keys/relation.rb
92
81
  - lib/composite_primary_keys/validations/uniqueness.rb
93
82
  - lib/composite_primary_keys/version.rb
94
- - lib/composite_primary_keys/write.rb
95
83
  - lib/composite_primary_keys.rb
96
84
  - scripts/console.rb
97
85
  - scripts/txt2html
@@ -181,10 +169,10 @@ files:
181
169
  - test/test_associations.rb
182
170
  - test/test_attributes.rb
183
171
  - test/test_attribute_methods.rb
184
- - test/test_clone.rb
185
172
  - test/test_composite_arrays.rb
186
173
  - test/test_create.rb
187
174
  - test/test_delete.rb
175
+ - test/test_dup.rb
188
176
  - test/test_equal.rb
189
177
  - test/test_exists.rb
190
178
  - test/test_find.rb
@@ -200,29 +188,42 @@ files:
200
188
  - test/test_validations.rb
201
189
  homepage: http://github.com/cfis/composite_primary_keys
202
190
  licenses: []
191
+
203
192
  post_install_message:
204
193
  rdoc_options: []
205
- require_paths:
194
+
195
+ require_paths:
206
196
  - lib
207
- required_ruby_version: !ruby/object:Gem::Requirement
197
+ required_ruby_version: !ruby/object:Gem::Requirement
208
198
  none: false
209
- requirements:
210
- - - ! '>='
211
- - !ruby/object:Gem::Version
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ hash: 57
203
+ segments:
204
+ - 1
205
+ - 8
206
+ - 7
212
207
  version: 1.8.7
213
- required_rubygems_version: !ruby/object:Gem::Requirement
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
214
209
  none: false
215
- requirements:
216
- - - ! '>='
217
- - !ruby/object:Gem::Version
218
- version: '0'
210
+ requirements:
211
+ - - ">"
212
+ - !ruby/object:Gem::Version
213
+ hash: 25
214
+ segments:
215
+ - 1
216
+ - 3
217
+ - 1
218
+ version: 1.3.1
219
219
  requirements: []
220
+
220
221
  rubyforge_project: compositekeys
221
- rubygems_version: 1.8.24
222
+ rubygems_version: 1.7.2
222
223
  signing_key:
223
224
  specification_version: 3
224
225
  summary: Composite key support for ActiveRecord
225
- test_files:
226
+ test_files:
226
227
  - test/abstract_unit.rb
227
228
  - test/db_test.rb
228
229
  - test/debug.log
@@ -232,10 +233,10 @@ test_files:
232
233
  - test/test_associations.rb
233
234
  - test/test_attributes.rb
234
235
  - test/test_attribute_methods.rb
235
- - test/test_clone.rb
236
236
  - test/test_composite_arrays.rb
237
237
  - test/test_create.rb
238
238
  - test/test_delete.rb
239
+ - test/test_dup.rb
239
240
  - test/test_equal.rb
240
241
  - test/test_exists.rb
241
242
  - test/test_find.rb