composite_primary_keys 4.0.0 → 4.1.1
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.
- data/History.txt +23 -1
- data/README.txt +1 -1
- data/lib/composite_primary_keys/associations/association_scope.rb +7 -2
- data/lib/composite_primary_keys/version.rb +2 -2
- data/test/README_tests.txt +10 -3
- data/test/abstract_unit.rb +5 -6
- data/test/connections/databases.example.yml +2 -2
- data/test/connections/databases.yml +13 -0
- data/test/fixtures/comments.yml +2 -2
- data/test/fixtures/db_definitions/mysql.sql +4 -3
- data/test/fixtures/db_definitions/oracle.drop.sql +1 -0
- data/test/fixtures/db_definitions/oracle.sql +6 -3
- data/test/fixtures/db_definitions/postgresql.sql +6 -3
- data/test/fixtures/db_definitions/sqlite.sql +6 -5
- data/test/fixtures/hack.rb +0 -1
- data/test/fixtures/hacks.yml +1 -0
- data/test/fixtures/reference_type.rb +0 -1
- data/test/test_associations.rb +2 -2
- data/test/test_attribute_methods.rb +2 -2
- data/test/test_attributes.rb +1 -1
- data/test/test_composite_arrays.rb +1 -1
- data/test/test_create.rb +1 -1
- data/test/test_delete.rb +1 -1
- data/test/test_dup.rb +1 -1
- data/test/test_equal.rb +1 -1
- data/test/test_exists.rb +1 -1
- data/test/test_find.rb +1 -1
- data/test/test_habtm.rb +1 -1
- data/test/test_ids.rb +1 -1
- data/test/test_miscellaneous.rb +1 -1
- data/test/test_pagination.rb +1 -1
- data/test/test_polymorphic.rb +5 -5
- data/test/test_predicates.rb +1 -1
- data/test/test_santiago.rb +1 -1
- data/test/test_suite.rb +24 -20
- data/test/test_tutorial_example.rb +1 -1
- data/test/test_update.rb +1 -1
- data/test/test_validations.rb +1 -1
- metadata +5 -5
data/History.txt
CHANGED
@@ -1,9 +1,31 @@
|
|
1
|
+
== 4.1.1 2011-08-31
|
2
|
+
* Support for AR 3.1.1
|
3
|
+
* Make polymorphic belongs_to work in rails 3.1.1 (Tom Hughes)
|
4
|
+
* Eliminate relative paths from the test suite (Rhett Sutphin)
|
5
|
+
* Minor improvements to the CPK test runner w/o relative path changes (Rhett Sutphin)
|
6
|
+
* Remove stray puts (Rhett Sutphin)
|
7
|
+
* Allow AR logs to go to a file when running tests. This commit allows you to
|
8
|
+
specify a file to use instead via the CPK_LOGFILE environment variable.
|
9
|
+
STDOUT is still the default. (Rhett Sutphin)
|
10
|
+
* Use ADAPTER env variable to select database to test. For example:
|
11
|
+
|
12
|
+
ADAPTER=sqlite3 ruby test/test_suite.rb
|
13
|
+
(Rhett Sutphin)
|
14
|
+
|
15
|
+
* Eliminate constant redef warnings during test runs (Rhett Sutphin)
|
16
|
+
* Add missing fixture declarations (Rhett Sutphin)
|
17
|
+
* Standardize on integer PKs in polymorphic fixtures (Rhett Sutphin)
|
18
|
+
* Fix tiny file name typos (Buck)
|
19
|
+
|
1
20
|
== 4.0.0 2011-08-31
|
2
|
-
*
|
21
|
+
* Support for AR 3.1
|
3
22
|
|
4
23
|
== 4.0.0.beta9 2011-08-22
|
5
24
|
* Fix eager-loading in AR 3.1.rc6.
|
6
25
|
|
26
|
+
== 4.0.0.beta9 2011-082-22
|
27
|
+
* Fix eager-loading in AR 3.1.rc6.
|
28
|
+
|
7
29
|
== 4.0.0.beta8 2011-082-22
|
8
30
|
* Sqlite 3 fixes (Jan Vlnas)
|
9
31
|
* Fixes for to_key method (Jan Vlnas)
|
data/README.txt
CHANGED
@@ -24,7 +24,12 @@ module ActiveRecord
|
|
24
24
|
end
|
25
25
|
|
26
26
|
if reflection.source_macro == :belongs_to
|
27
|
-
|
27
|
+
if reflection.options[:polymorphic]
|
28
|
+
key = reflection.association_primary_key(klass)
|
29
|
+
else
|
30
|
+
key = reflection.association_primary_key
|
31
|
+
end
|
32
|
+
|
28
33
|
foreign_key = reflection.foreign_key
|
29
34
|
else
|
30
35
|
key = reflection.foreign_key
|
@@ -64,4 +69,4 @@ module ActiveRecord
|
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
67
|
-
end
|
72
|
+
end
|
data/test/README_tests.txt
CHANGED
@@ -18,9 +18,8 @@ To run the tests for one of the adapters follow these steps (using mysql in the
|
|
18
18
|
- activerecord (3.1.0.rc5 or later)
|
19
19
|
- mysql (or the adapter of your choice)
|
20
20
|
|
21
|
-
* Put your
|
22
|
-
|
23
|
-
keep only one connection spec at once in databases.yml
|
21
|
+
* Put your database connection settings in test/connections/databases.yml.
|
22
|
+
Look at databases.example.yml for examples.
|
24
23
|
|
25
24
|
mysql:
|
26
25
|
adapter: mysql
|
@@ -47,3 +46,11 @@ If you want to run closer to the metal you can cd into the test/
|
|
47
46
|
directory and run the tests like so:
|
48
47
|
|
49
48
|
* ADAPTER=mysql ruby test_equal.rb
|
49
|
+
|
50
|
+
== Logging
|
51
|
+
|
52
|
+
By default, ActiveRecord's log messages are sent to standard out when
|
53
|
+
running the tests. If you would prefer to send them to a file, specify
|
54
|
+
it as the environment variable CPK_LOGFILE:
|
55
|
+
|
56
|
+
* CPK_LOGFILE=cpk_test.log rake mysql:test
|
data/test/abstract_unit.rb
CHANGED
@@ -2,16 +2,15 @@ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
2
2
|
|
3
3
|
require "pp"
|
4
4
|
require "test/unit"
|
5
|
-
require
|
5
|
+
require File.expand_path('../hash_tricks', __FILE__)
|
6
6
|
|
7
7
|
# To make debugging easier, test within this source tree versus an installed gem
|
8
|
-
|
9
|
-
require
|
8
|
+
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
|
9
|
+
require 'composite_primary_keys'
|
10
10
|
|
11
11
|
# Now load the connection spec
|
12
12
|
require File.join(PROJECT_ROOT, "test", "connections", "connection_spec")
|
13
|
-
|
14
|
-
spec = config[config.keys.first]
|
13
|
+
spec = CompositePrimaryKeys::ConnectionSpec[ENV['ADAPTER'] || 'postgresql']
|
15
14
|
|
16
15
|
# And now connect to the database
|
17
16
|
adapter = spec['adapter']
|
@@ -98,4 +97,4 @@ ActiveRecord::Base.connection.class.class_eval do
|
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
101
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
100
|
+
ActiveRecord::Base.logger = Logger.new(ENV['CPK_LOGFILE'] || STDOUT)
|
@@ -1,3 +1,16 @@
|
|
1
|
+
# To run tests:
|
2
|
+
# 1. Copy this file to test/connections/databases.yml.
|
3
|
+
# 2. Update to match the databases you want to test against.
|
4
|
+
|
5
|
+
mysql:
|
6
|
+
adapter: mysql
|
7
|
+
username: root
|
8
|
+
database: composite_primary_keys_unittest
|
9
|
+
|
10
|
+
sqlite3:
|
11
|
+
adapter: sqlite3
|
12
|
+
database: db/composite_primary_keys_unittest.sqlite3
|
13
|
+
|
1
14
|
postgresql:
|
2
15
|
adapter: postgresql
|
3
16
|
database: composite_primary_keys_unittest
|
data/test/fixtures/comments.yml
CHANGED
@@ -105,15 +105,16 @@ create table employees (
|
|
105
105
|
|
106
106
|
create table comments (
|
107
107
|
id int(11) not null auto_increment,
|
108
|
-
person_id
|
108
|
+
person_id int(11) default null,
|
109
109
|
person_type varchar(100) default null,
|
110
|
-
hack_id
|
110
|
+
hack_id int(11) default null,
|
111
111
|
primary key (id)
|
112
112
|
) type=InnoDB;
|
113
113
|
|
114
114
|
create table hacks (
|
115
|
+
id int(11) not null auto_increment,
|
115
116
|
name varchar(50) not null,
|
116
|
-
primary key (
|
117
|
+
primary key (id)
|
117
118
|
) type=InnoDB;
|
118
119
|
|
119
120
|
create table restaurants (
|
@@ -115,13 +115,16 @@ create sequence comments_seq start with 1000;
|
|
115
115
|
|
116
116
|
create table comments (
|
117
117
|
id number(11) not null primary key,
|
118
|
-
person_id
|
118
|
+
person_id number(11) default null,
|
119
119
|
person_type varchar(100) default null,
|
120
|
-
hack_id
|
120
|
+
hack_id number(11) default null
|
121
121
|
);
|
122
122
|
|
123
|
+
create sequence hacks_seq start with 1000;
|
124
|
+
|
123
125
|
create table hacks (
|
124
|
-
|
126
|
+
id number(11) not null primary key,
|
127
|
+
name varchar(50) not null
|
125
128
|
);
|
126
129
|
|
127
130
|
create table restaurants (
|
@@ -125,15 +125,18 @@ create sequence public.comments_seq start 1000;
|
|
125
125
|
|
126
126
|
create table comments (
|
127
127
|
id int not null default nextval('public.comments_seq'),
|
128
|
-
person_id
|
128
|
+
person_id int default null,
|
129
129
|
person_type varchar(100) default null,
|
130
|
-
hack_id
|
130
|
+
hack_id int default null,
|
131
131
|
primary key (id)
|
132
132
|
);
|
133
133
|
|
134
|
+
create sequence public.hacks_seq start 1000;
|
135
|
+
|
134
136
|
create table hacks (
|
137
|
+
id int default nextval('public.hacks_seq'),
|
135
138
|
name varchar(50) not null,
|
136
|
-
primary key (
|
139
|
+
primary key (id)
|
137
140
|
);
|
138
141
|
|
139
142
|
create table restaurants (
|
@@ -95,14 +95,15 @@ create table employees (
|
|
95
95
|
);
|
96
96
|
|
97
97
|
create table comments (
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
id integer not null primary key autoincrement,
|
99
|
+
person_id int null,
|
100
|
+
person_type varchar(100) null,
|
101
|
+
hack_id int null
|
102
102
|
);
|
103
103
|
|
104
104
|
create table hacks (
|
105
|
-
|
105
|
+
id integer not null primary key autoincrement,
|
106
|
+
name varchar(50) not null
|
106
107
|
);
|
107
108
|
|
108
109
|
create table restaurants (
|
data/test/fixtures/hack.rb
CHANGED
data/test/fixtures/hacks.yml
CHANGED
data/test/test_associations.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
2
|
|
3
3
|
class TestAssociations < ActiveSupport::TestCase
|
4
4
|
fixtures :articles, :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants,
|
5
5
|
:dorms, :rooms, :room_attributes, :room_attribute_assignments, :students, :room_assignments, :users, :readings,
|
6
|
-
:departments, :memberships
|
6
|
+
:departments, :employees, :memberships, :membership_statuses
|
7
7
|
|
8
8
|
def test_count
|
9
9
|
assert_equal(3, Product.count(:include => :product_tariffs))
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
2
|
|
3
3
|
class TestAttributeMethods < ActiveSupport::TestCase
|
4
|
-
fixtures :reference_types
|
4
|
+
fixtures :reference_types, :reference_codes
|
5
5
|
|
6
6
|
def test_read_attribute_with_single_key
|
7
7
|
rt = ReferenceType.find(1)
|
data/test/test_attributes.rb
CHANGED
data/test/test_create.rb
CHANGED
data/test/test_delete.rb
CHANGED
data/test/test_dup.rb
CHANGED
data/test/test_equal.rb
CHANGED
data/test/test_exists.rb
CHANGED
data/test/test_find.rb
CHANGED
data/test/test_habtm.rb
CHANGED
data/test/test_ids.rb
CHANGED
data/test/test_miscellaneous.rb
CHANGED
data/test/test_pagination.rb
CHANGED
data/test/test_polymorphic.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
2
|
|
3
3
|
class TestPolymorphic < ActiveSupport::TestCase
|
4
4
|
fixtures :users, :employees, :comments, :hacks
|
5
5
|
|
6
6
|
def test_polymorphic_has_many
|
7
|
-
comments = Hack.find(
|
8
|
-
assert_equal
|
7
|
+
comments = Hack.find(7).comments
|
8
|
+
assert_equal 7, comments[0].person_id
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_polymorphic_has_one
|
12
|
-
first_comment = Hack.find(
|
13
|
-
assert_equal
|
12
|
+
first_comment = Hack.find(7).first_comment
|
13
|
+
assert_equal 7, first_comment.person_id
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_has_many_through
|
data/test/test_predicates.rb
CHANGED
data/test/test_santiago.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Test cases devised by Santiago that broke the Composite Primary Keys
|
2
2
|
# code at one point in time. But no more!!!
|
3
|
-
require '
|
3
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
4
4
|
|
5
5
|
class TestSantiago < ActiveSupport::TestCase
|
6
6
|
fixtures :suburbs, :streets, :users, :articles, :readings
|
data/test/test_suite.rb
CHANGED
@@ -1,22 +1,26 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
3
|
+
%w(
|
4
|
+
test_associations
|
5
|
+
test_attribute_methods
|
6
|
+
test_attributes
|
7
|
+
test_composite_arrays
|
8
|
+
test_create
|
9
|
+
test_delete
|
10
|
+
test_dup
|
11
|
+
test_equal
|
12
|
+
test_exists
|
13
|
+
test_find
|
14
|
+
test_habtm
|
15
|
+
test_ids
|
16
|
+
test_miscellaneous
|
17
|
+
test_pagination
|
18
|
+
test_polymorphic
|
19
|
+
test_predicates
|
20
|
+
test_santiago
|
21
|
+
test_tutorial_example
|
22
|
+
test_update
|
23
|
+
test_validations
|
24
|
+
).each do |test|
|
25
|
+
require File.expand_path("../#{test}", __FILE__)
|
26
|
+
end
|
data/test/test_update.rb
CHANGED
data/test/test_validations.rb
CHANGED
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: 4.
|
4
|
+
version: 4.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,19 +10,19 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-11-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
17
|
-
requirement: &
|
17
|
+
requirement: &25587648 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 3.1
|
22
|
+
version: '3.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *25587648
|
26
26
|
description: Composite key support for ActiveRecord 3
|
27
27
|
email:
|
28
28
|
- drnicwilliams@gmail.com
|