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 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
- * Sync release with Rails 3.1
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,7 @@ See http://compositekeys.rubyforge.org for more.
24
24
 
25
25
  == Running Tests
26
26
 
27
- See test/README.tests.txt
27
+ See test/README_tests.txt
28
28
 
29
29
  == Url
30
30
 
@@ -24,7 +24,12 @@ module ActiveRecord
24
24
  end
25
25
 
26
26
  if reflection.source_macro == :belongs_to
27
- key = reflection.association_primary_key
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
@@ -1,8 +1,8 @@
1
1
  module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 4
4
- MINOR = 0
5
- TINY = 0
4
+ MINOR = 1
5
+ TINY = 1
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -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 mysql connection settings to test/connections/databases.yml
22
- look into databases.example.sql for reference,
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
@@ -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 "./hash_tricks"
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
- #require 'composite_primary_keys'
9
- require File.join(PROJECT_ROOT, "lib", "composite_primary_keys")
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
- config = CompositePrimaryKeys::ConnectionSpec.config
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,6 +1,6 @@
1
1
  # To run tests:
2
- # 1. Copy this file to databases.yml
3
- # 2. Delete all the specs except one
2
+ # 1. Copy this file to test/connections/databases.yml.
3
+ # 2. Update to match the databases you want to test against.
4
4
 
5
5
  mysql:
6
6
  adapter: mysql
@@ -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
@@ -7,10 +7,10 @@ comment2:
7
7
  id: 2
8
8
  person_id: 1
9
9
  person_type: User
10
- hack_id: andrew
10
+ hack_id: 7
11
11
 
12
12
  comment3:
13
13
  id: 3
14
- person_id: andrew
14
+ person_id: 7
15
15
  person_type: Hack
16
16
 
@@ -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 varchar(100) default null,
108
+ person_id int(11) default null,
109
109
  person_type varchar(100) default null,
110
- hack_id varchar(100) default null,
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 (name)
117
+ primary key (id)
117
118
  ) type=InnoDB;
118
119
 
119
120
  create table restaurants (
@@ -25,6 +25,7 @@ drop sequence employees_seq;
25
25
  drop table comments;
26
26
  drop sequence comments_seq;
27
27
  drop table hacks;
28
+ drop sequence hacks_seq;
28
29
  drop table restaurants;
29
30
  drop table restaurants_suburbs;
30
31
  drop table dorms;
@@ -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 varchar(100) default null,
118
+ person_id number(11) default null,
119
119
  person_type varchar(100) default null,
120
- hack_id varchar(100) default null
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
- name varchar(50) not null primary key
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 varchar(100) default null,
128
+ person_id int default null,
129
129
  person_type varchar(100) default null,
130
- hack_id varchar(100) default null,
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 (name)
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
- id integer not null primary key autoincrement,
99
- person_id varchar(100) null,
100
- person_type varchar(100) null,
101
- hack_id varchar(100) null
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
- name varchar(50) not null primary key
105
+ id integer not null primary key autoincrement,
106
+ name varchar(50) not null
106
107
  );
107
108
 
108
109
  create table restaurants (
@@ -1,5 +1,4 @@
1
1
  class Hack < ActiveRecord::Base
2
- set_primary_keys :name
3
2
  has_many :comments, :as => :person
4
3
 
5
4
  has_one :first_comment, :as => :person, :class_name => "Comment"
@@ -1,2 +1,3 @@
1
1
  andrew:
2
+ id: 7
2
3
  name: andrew
@@ -7,6 +7,5 @@ class ReferenceType < ActiveRecord::Base
7
7
 
8
8
  before_destroy do |record|
9
9
  a = record
10
- puts a
11
10
  end
12
11
  end
@@ -1,9 +1,9 @@
1
- require './abstract_unit'
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 './abstract_unit'
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)
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestAttributes < ActiveSupport::TestCase
4
4
  fixtures :reference_types, :reference_codes, :products, :tariffs, :product_tariffs
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class CompositeArraysTest < ActiveSupport::TestCase
4
4
 
data/test/test_create.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestCreate < ActiveSupport::TestCase
4
4
  fixtures :reference_types, :reference_codes, :streets, :suburbs
data/test/test_delete.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestDelete < ActiveSupport::TestCase
4
4
  fixtures :departments, :employees, :products, :product_tariffs,
data/test/test_dup.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestClone < ActiveSupport::TestCase
4
4
  fixtures :reference_types, :reference_codes
data/test/test_equal.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestEqual < ActiveSupport::TestCase
4
4
  fixtures :capitols
data/test/test_exists.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestExists < ActiveSupport::TestCase
4
4
  fixtures :articles, :departments
data/test/test_find.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  # Testing the find action on composite ActiveRecords with two primary keys
4
4
  class TestFind < ActiveSupport::TestCase
data/test/test_habtm.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestHabtm < ActiveSupport::TestCase
4
4
  fixtures :suburbs, :restaurants, :restaurants_suburbs, :products
data/test/test_ids.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestIds < ActiveSupport::TestCase
4
4
  fixtures :reference_types, :reference_codes
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestMiscellaneous < ActiveSupport::TestCase
4
4
  fixtures :reference_types, :reference_codes, :products
@@ -1,4 +1,4 @@
1
- #require './abstract_unit'
1
+ #require File.expand_path('../abstract_unit', __FILE__)
2
2
  #require 'plugins/pagination'
3
3
  #
4
4
  #class TestPagination < ActiveSupport::TestCase
@@ -1,16 +1,16 @@
1
- require './abstract_unit'
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('andrew').comments
8
- assert_equal 'andrew', comments[0].person_id
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('andrew').first_comment
13
- assert_equal 'andrew', first_comment.person_id
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
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestEqual < ActiveSupport::TestCase
4
4
  fixtures :departments
@@ -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 './abstract_unit'
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
- require './test_associations'
4
- require './test_attribute_methods'
5
- require './test_attributes'
6
- require './test_composite_arrays'
7
- require './test_create'
8
- require './test_delete'
9
- require './test_dup'
10
- require './test_equal'
11
- require './test_exists'
12
- require './test_find'
13
- require './test_habtm'
14
- require './test_ids'
15
- require './test_miscellaneous'
16
- require './test_pagination'
17
- require './test_polymorphic'
18
- require './test_predicates'
19
- require './test_santiago'
20
- require './test_tutorial_example'
21
- require './test_update'
22
- require './test_validations'
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
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestTutorialExample < ActiveSupport::TestCase
4
4
  fixtures :users, :groups, :memberships, :membership_statuses
data/test/test_update.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestUpdate < ActiveSupport::TestCase
4
4
  fixtures :reference_types, :reference_codes
@@ -1,4 +1,4 @@
1
- require './abstract_unit'
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestValidations < ActiveSupport::TestCase
4
4
  fixtures :seats
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.0.0
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-08-31 00:00:00.000000000 Z
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: &3179784 !ruby/object:Gem::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.0
22
+ version: '3.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *3179784
25
+ version_requirements: *25587648
26
26
  description: Composite key support for ActiveRecord 3
27
27
  email:
28
28
  - drnicwilliams@gmail.com