composite_primary_keys 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/README.txt +1 -1
- data/Rakefile +11 -6
- data/lib/composite_primary_keys/base.rb +9 -3
- data/lib/composite_primary_keys/reflection.rb +1 -1
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/README_tests.txt +16 -4
- data/test/abstract_unit.rb +1 -1
- data/test/connections/native_postgresql/connection.rb +0 -1
- data/test/test_associations.rb +29 -1
- metadata +6 -6
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 3.1.1 2010-02-07
|
2
|
+
* Implement id_before_type_cast (Jason Lewis)
|
3
|
+
* Add in tests for Model.includes(:other_model)
|
4
|
+
* Fix object comparison with nil in composite primary keys (StackNG)
|
5
|
+
* Make it easier to run tests with different database adapters (Toby Cabot)
|
6
|
+
* Fix AssociationReflection#primary_key_name for polymorphic relationships (Dave Doan)
|
7
|
+
|
8
|
+
|
1
9
|
== 3.1.0 2010-12-17
|
2
10
|
* Add back in rake test tasks (Toby Cabot)
|
3
11
|
* Add support for multiple string composite keys (wouter)
|
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -21,11 +21,16 @@ Dir.glob('tasks/**/*.rake').each do |rake_file|
|
|
21
21
|
load File.join(File.dirname(__FILE__), rake_file)
|
22
22
|
end
|
23
23
|
|
24
|
-
# Set up test tasks
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
# Set up test tasks for each supported connection adapter
|
25
|
+
%w(mysql sqlite oracle oracle_enhanced postgresql ibm_db).each do |adapter|
|
26
|
+
namespace adapter do
|
27
|
+
desc "Run tests using the #{adapter} adapter"
|
28
|
+
task "test" do
|
29
|
+
ENV["ADAPTER"] = adapter
|
30
|
+
Rake::TestTask.new("subtest_#{adapter}") do |t|
|
31
|
+
t.libs << "test"
|
32
|
+
end
|
33
|
+
Rake::Task["subtest_#{adapter}"].invoke
|
34
|
+
end
|
30
35
|
end
|
31
36
|
end
|
@@ -116,8 +116,10 @@ module ActiveRecord
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
def id_before_type_cast
|
120
|
-
|
119
|
+
def id_before_type_cast
|
120
|
+
self.class.primary_keys.map do |key|
|
121
|
+
self.send("#{key.to_s}_before_type_cast")
|
122
|
+
end
|
121
123
|
end
|
122
124
|
|
123
125
|
def quoted_id #:nodoc:
|
@@ -138,6 +140,10 @@ module ActiveRecord
|
|
138
140
|
id
|
139
141
|
end
|
140
142
|
|
143
|
+
def ==(comparison_object)
|
144
|
+
ids.is_a?(Array) ? super(comparison_object) && ids.all? {|id| id.present?} : super(comparison_object)
|
145
|
+
end
|
146
|
+
|
141
147
|
# Cloned objects have no id assigned and are treated as new records. Note that this is a "shallow" clone
|
142
148
|
# as it copies the object's attributes only, not its associations. The extent of a "deep" clone is
|
143
149
|
# application specific and is therefore left to the application to implement according to its need.
|
@@ -188,4 +194,4 @@ module ActiveRecord
|
|
188
194
|
end
|
189
195
|
end
|
190
196
|
end
|
191
|
-
end
|
197
|
+
end
|
data/test/README_tests.txt
CHANGED
@@ -7,17 +7,29 @@ There are tests available for the following adapters:
|
|
7
7
|
* ibmdb
|
8
8
|
* mysql
|
9
9
|
* oracle
|
10
|
+
* oracle_enhanced
|
10
11
|
* postgresql
|
11
12
|
* sqlite
|
12
13
|
|
13
|
-
To run the tests for
|
14
|
+
To run the tests for one of the adapters follow these steps (using mysql in the example):
|
14
15
|
|
15
|
-
* rake -T
|
16
|
+
* rake -T mysql
|
16
17
|
|
17
18
|
rake mysql:build_databases # Build the MySQL test databases
|
18
19
|
rake mysql:drop_databases # Drop the MySQL test databases
|
19
20
|
rake mysql:rebuild_databases # Rebuild the MySQL test databases
|
20
|
-
rake
|
21
|
+
rake mysql:test # Run tests using the mysql adapter
|
21
22
|
|
22
23
|
* rake mysql:build_databases
|
23
|
-
* rake
|
24
|
+
* rake mysql:test
|
25
|
+
|
26
|
+
== Running tests individually
|
27
|
+
|
28
|
+
You can specify which test you'd like to run on the command line:
|
29
|
+
|
30
|
+
* rake mysql:test TEST=test/test_equal.rb
|
31
|
+
|
32
|
+
If you want to run closer to the metal you can cd into the test/
|
33
|
+
directory and run the tests like so:
|
34
|
+
|
35
|
+
* ADAPTER=mysql ruby test_equal.rb
|
data/test/abstract_unit.rb
CHANGED
@@ -7,7 +7,6 @@ require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys', 'connection_ada
|
|
7
7
|
def connection_string
|
8
8
|
options = Hash.new
|
9
9
|
options['U'] = SPEC['username'] if SPEC['username']
|
10
|
-
options['p'] = SPEC['password'] if SPEC['password']
|
11
10
|
options.map { |key, value| "-#{key} #{value}" }.join(" ")
|
12
11
|
end
|
13
12
|
|
data/test/test_associations.rb
CHANGED
@@ -56,31 +56,59 @@ class TestAssociations < ActiveSupport::TestCase
|
|
56
56
|
|
57
57
|
# Its not generating the instances of associated classes from the rows
|
58
58
|
def test_find_includes_products
|
59
|
+
# Old style
|
59
60
|
assert @products = Product.find(:all, :include => :product_tariffs)
|
60
61
|
assert_equal 2, @products.length
|
61
62
|
assert_not_nil @products.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
|
62
63
|
assert_equal 3, @products.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
63
64
|
"Incorrect number of product_tariffs returned"
|
65
|
+
|
66
|
+
# New style
|
67
|
+
assert @products = Product.includes(:product_tariffs)
|
68
|
+
assert_equal 2, @products.length
|
69
|
+
assert_not_nil @products.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
|
70
|
+
assert_equal 3, @products.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
71
|
+
"Incorrect number of product_tariffs returned"
|
64
72
|
end
|
65
73
|
|
66
74
|
def test_find_includes_tariffs
|
75
|
+
# Old style
|
67
76
|
assert @tariffs = Tariff.find(:all, :include => :product_tariffs)
|
68
77
|
assert_equal 3, @tariffs.length
|
69
78
|
assert_not_nil @tariffs.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
|
70
79
|
assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
71
80
|
"Incorrect number of product_tariffs returnedturned"
|
81
|
+
|
82
|
+
# New style
|
83
|
+
assert @tariffs = Tariff.includes(:product_tariffs)
|
84
|
+
assert_equal 3, @tariffs.length
|
85
|
+
assert_not_nil @tariffs.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
|
86
|
+
assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
87
|
+
"Incorrect number of product_tariffs returnedturned"
|
72
88
|
end
|
73
89
|
|
74
|
-
def
|
90
|
+
def test_find_includes_product_tariffs
|
91
|
+
# Old style
|
75
92
|
assert @product_tariffs = ProductTariff.find(:all, :include => :product)
|
76
93
|
assert_equal 3, @product_tariffs.length
|
77
94
|
assert_not_nil @product_tariffs.first.instance_variable_get('@product'), '@product not set'
|
95
|
+
|
96
|
+
# New style
|
97
|
+
assert @product_tariffs = ProductTariff.includes(:product)
|
98
|
+
assert_equal 3, @product_tariffs.length
|
99
|
+
assert_not_nil @product_tariffs.first.instance_variable_get('@product'), '@product not set'
|
78
100
|
end
|
79
101
|
|
80
102
|
def test_find_includes_comp_belongs_to_tariff
|
103
|
+
# Old style
|
81
104
|
assert @product_tariffs = ProductTariff.find(:all, :include => :tariff)
|
82
105
|
assert_equal 3, @product_tariffs.length
|
83
106
|
assert_not_nil @product_tariffs.first.instance_variable_get('@tariff'), '@tariff not set'
|
107
|
+
|
108
|
+
# New style
|
109
|
+
assert @product_tariffs = ProductTariff.includes(:tariff)
|
110
|
+
assert_equal 3, @product_tariffs.length
|
111
|
+
assert_not_nil @product_tariffs.first.instance_variable_get('@tariff'), '@tariff not set'
|
84
112
|
end
|
85
113
|
|
86
114
|
def test_find_includes_extended
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 1
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 3.1.
|
9
|
+
- 1
|
10
|
+
version: 3.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dr Nic Williams
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2011-02-05 00:00:00 -08:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -232,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
232
232
|
requirements: []
|
233
233
|
|
234
234
|
rubyforge_project: compositekeys
|
235
|
-
rubygems_version: 1.
|
235
|
+
rubygems_version: 1.5.0
|
236
236
|
signing_key:
|
237
237
|
specification_version: 3
|
238
238
|
summary: Composite key support for ActiveRecord
|