composite_primary_keys 8.1.6 → 8.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.rdoc +5 -0
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
- data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +1 -1
- data/lib/composite_primary_keys/relation/batches.rb +1 -1
- data/lib/composite_primary_keys/version.rb +1 -1
- data/scripts/console.rb +48 -48
- data/scripts/txt2html +76 -76
- data/scripts/txt2js +65 -65
- data/tasks/website.rake +18 -18
- data/test/README_tests.rdoc +56 -56
- data/test/connections/databases.yml +39 -30
- data/test/db_test.rb +52 -52
- data/test/fixtures/articles.yml +6 -6
- data/test/fixtures/capitol.rb +3 -3
- data/test/fixtures/capitols.yml +16 -16
- data/test/fixtures/comments.yml +15 -15
- data/test/fixtures/department.rb +5 -5
- data/test/fixtures/departments.yml +15 -15
- data/test/fixtures/dorms.yml +4 -4
- data/test/fixtures/group.rb +2 -2
- data/test/fixtures/groups.yml +6 -6
- data/test/fixtures/hack.rb +4 -4
- data/test/fixtures/hacks.yml +2 -2
- data/test/fixtures/membership_status.rb +2 -2
- data/test/fixtures/product.rb +9 -9
- data/test/fixtures/product_tariff.rb +5 -5
- data/test/fixtures/products.yml +11 -11
- data/test/fixtures/reading.rb +4 -4
- data/test/fixtures/readings.yml +10 -10
- data/test/fixtures/reference_code_using_composite_key_alias.rb +8 -8
- data/test/fixtures/reference_code_using_simple_key_alias.rb +8 -8
- data/test/fixtures/reference_codes.yml +28 -28
- data/test/fixtures/reference_types.yml +9 -9
- data/test/fixtures/restaurant.rb +9 -9
- data/test/fixtures/restaurants.yml +14 -14
- data/test/fixtures/restaurants_suburbs.yml +10 -10
- data/test/fixtures/room.rb +11 -11
- data/test/fixtures/room_assignment.rb +13 -13
- data/test/fixtures/room_assignments.yml +24 -24
- data/test/fixtures/room_attribute.rb +2 -2
- data/test/fixtures/room_attribute_assignment.rb +4 -4
- data/test/fixtures/room_attribute_assignments.yml +4 -4
- data/test/fixtures/room_attributes.yml +2 -2
- data/test/fixtures/rooms.yml +12 -12
- data/test/fixtures/seat.rb +5 -5
- data/test/fixtures/seats.yml +8 -8
- data/test/fixtures/street.rb +2 -2
- data/test/fixtures/streets.yml +16 -16
- data/test/fixtures/student.rb +3 -3
- data/test/fixtures/students.yml +15 -15
- data/test/fixtures/suburbs.yml +14 -14
- data/test/fixtures/tariffs.yml +14 -14
- data/test/plugins/pagination.rb +405 -405
- data/test/plugins/pagination_helper.rb +135 -135
- data/test/setup.rb +50 -50
- data/test/test_aliases.rb +18 -18
- data/test/test_composite_arrays.rb +24 -24
- data/test/test_counter_cache.rb +30 -30
- data/test/test_dup.rb +37 -37
- data/test/test_exists.rb +39 -39
- data/test/test_miscellaneous.rb +32 -32
- data/test/test_pagination.rb +35 -35
- data/test/test_update_all.rb +17 -0
- data/test/test_validations.rb +13 -13
- metadata +5 -4
data/tasks/website.rake
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
desc 'Generate website files'
|
2
|
-
task :website_generate do
|
3
|
-
sh %{ ruby scripts/txt2html website/index.txt > website/index.html }
|
4
|
-
sh %{ ruby scripts/txt2js website/version.txt > website/version.js }
|
5
|
-
sh %{ ruby scripts/txt2js website/version-raw.txt > website/version-raw.js }
|
6
|
-
end
|
7
|
-
|
8
|
-
desc 'Upload website files to rubyforge'
|
9
|
-
task :website_upload do
|
10
|
-
config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
|
11
|
-
host = "#{config["username"]}@rubyforge.org"
|
12
|
-
remote_dir = "/var/www/gforge-projects/compositekeys/"
|
13
|
-
local_dir = 'website'
|
14
|
-
sh %{scp -r #{local_dir}/* #{host}:#{remote_dir}}
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'Generate and upload website files'
|
18
|
-
task :website => [:website_generate, :website_upload]
|
1
|
+
desc 'Generate website files'
|
2
|
+
task :website_generate do
|
3
|
+
sh %{ ruby scripts/txt2html website/index.txt > website/index.html }
|
4
|
+
sh %{ ruby scripts/txt2js website/version.txt > website/version.js }
|
5
|
+
sh %{ ruby scripts/txt2js website/version-raw.txt > website/version-raw.js }
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Upload website files to rubyforge'
|
9
|
+
task :website_upload do
|
10
|
+
config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
|
11
|
+
host = "#{config["username"]}@rubyforge.org"
|
12
|
+
remote_dir = "/var/www/gforge-projects/compositekeys/"
|
13
|
+
local_dir = 'website'
|
14
|
+
sh %{scp -r #{local_dir}/* #{host}:#{remote_dir}}
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Generate and upload website files'
|
18
|
+
task :website => [:website_generate, :website_upload]
|
data/test/README_tests.rdoc
CHANGED
@@ -1,56 +1,56 @@
|
|
1
|
-
= Composite Primary Keys - Testing Readme
|
2
|
-
|
3
|
-
== Testing an adapter
|
4
|
-
|
5
|
-
There are tests available for the following adapters:
|
6
|
-
|
7
|
-
* ibmdb
|
8
|
-
* mysql
|
9
|
-
* oracle
|
10
|
-
* oracle_enhanced
|
11
|
-
* postgresql
|
12
|
-
* sqlite3
|
13
|
-
|
14
|
-
To run the tests for one of the adapters follow these steps (using mysql in the example):
|
15
|
-
|
16
|
-
* You will need the following gems:
|
17
|
-
- rake
|
18
|
-
- activerecord (3.1.0.rc5 or later)
|
19
|
-
- mysql (or the adapter of your choice)
|
20
|
-
|
21
|
-
* Put your database connection settings in test/connections/databases.yml.
|
22
|
-
Look at databases.example.yml for examples.
|
23
|
-
|
24
|
-
mysql:
|
25
|
-
adapter: mysql
|
26
|
-
username: root
|
27
|
-
database: composite_primary_keys_unittest
|
28
|
-
|
29
|
-
* rake -T mysql
|
30
|
-
|
31
|
-
rake mysql:build_database # Build the MySQL test databases
|
32
|
-
rake mysql:drop_database # Drop the MySQL test databases
|
33
|
-
rake mysql:rebuild_database # Rebuild the MySQL test databases
|
34
|
-
rake mysql:test # Run tests using the mysql adapter
|
35
|
-
|
36
|
-
* rake mysql:build_database
|
37
|
-
* rake mysql:test
|
38
|
-
|
39
|
-
== Running tests individually
|
40
|
-
|
41
|
-
You can specify which test you'd like to run on the command line:
|
42
|
-
|
43
|
-
* rake mysql:test TEST=test/test_equal.rb
|
44
|
-
|
45
|
-
If you want to run closer to the metal you can cd into the test/
|
46
|
-
directory and run the tests like so:
|
47
|
-
|
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
|
1
|
+
= Composite Primary Keys - Testing Readme
|
2
|
+
|
3
|
+
== Testing an adapter
|
4
|
+
|
5
|
+
There are tests available for the following adapters:
|
6
|
+
|
7
|
+
* ibmdb
|
8
|
+
* mysql
|
9
|
+
* oracle
|
10
|
+
* oracle_enhanced
|
11
|
+
* postgresql
|
12
|
+
* sqlite3
|
13
|
+
|
14
|
+
To run the tests for one of the adapters follow these steps (using mysql in the example):
|
15
|
+
|
16
|
+
* You will need the following gems:
|
17
|
+
- rake
|
18
|
+
- activerecord (3.1.0.rc5 or later)
|
19
|
+
- mysql (or the adapter of your choice)
|
20
|
+
|
21
|
+
* Put your database connection settings in test/connections/databases.yml.
|
22
|
+
Look at databases.example.yml for examples.
|
23
|
+
|
24
|
+
mysql:
|
25
|
+
adapter: mysql
|
26
|
+
username: root
|
27
|
+
database: composite_primary_keys_unittest
|
28
|
+
|
29
|
+
* rake -T mysql
|
30
|
+
|
31
|
+
rake mysql:build_database # Build the MySQL test databases
|
32
|
+
rake mysql:drop_database # Drop the MySQL test databases
|
33
|
+
rake mysql:rebuild_database # Rebuild the MySQL test databases
|
34
|
+
rake mysql:test # Run tests using the mysql adapter
|
35
|
+
|
36
|
+
* rake mysql:build_database
|
37
|
+
* rake mysql:test
|
38
|
+
|
39
|
+
== Running tests individually
|
40
|
+
|
41
|
+
You can specify which test you'd like to run on the command line:
|
42
|
+
|
43
|
+
* rake mysql:test TEST=test/test_equal.rb
|
44
|
+
|
45
|
+
If you want to run closer to the metal you can cd into the test/
|
46
|
+
directory and run the tests like so:
|
47
|
+
|
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
|
@@ -1,30 +1,39 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
username:
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
+
ibm_db:
|
6
|
+
database: ocdpdev
|
7
|
+
username: db2inst1
|
8
|
+
password: password
|
9
|
+
host: localhost
|
10
|
+
|
11
|
+
mysql:
|
12
|
+
adapter: mysql2
|
13
|
+
username: root
|
14
|
+
database: composite_primary_keys_unittest
|
15
|
+
|
16
|
+
oracle:
|
17
|
+
adapter: oracle_enhanced
|
18
|
+
database: xe
|
19
|
+
username: SYSTEM
|
20
|
+
password: oracle
|
21
|
+
host: localhost
|
22
|
+
|
23
|
+
postgresql:
|
24
|
+
adapter: postgresql
|
25
|
+
database: composite_primary_keys_unittest
|
26
|
+
username: postgres
|
27
|
+
host: localhost
|
28
|
+
|
29
|
+
sqlite:
|
30
|
+
adapter: sqlite3
|
31
|
+
database: <%= File.join(project_root, 'db', 'composite_primary_keys_unittest.sqlite') %>
|
32
|
+
|
33
|
+
sqlserver:
|
34
|
+
adapter: sqlserver
|
35
|
+
username: cpk
|
36
|
+
password: cpk
|
37
|
+
database: composite_primary_keys_unittest
|
38
|
+
host: localhost
|
39
|
+
port: 1433
|
data/test/db_test.rb
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
# assoc_test.rb
|
2
|
-
|
3
|
-
path = File.expand_path(File.join(File.basename(__FILE__), "..", "lib", "composite_primary_keys"))
|
4
|
-
puts path
|
5
|
-
|
6
|
-
require File.join(path)
|
7
|
-
require 'active_record'
|
8
|
-
|
9
|
-
$configuration = {
|
10
|
-
:adapter => 'postgresql',
|
11
|
-
:database => 'cpk_test',
|
12
|
-
:username => 'postgres'
|
13
|
-
}
|
14
|
-
|
15
|
-
ActiveRecord::Base.establish_connection($configuration) unless ActiveRecord::Base.connected?
|
16
|
-
|
17
|
-
module GlobePG
|
18
|
-
class PGBase < ActiveRecord::Base
|
19
|
-
self.abstract_class = true
|
20
|
-
# establish_connection($configuration) unless connected?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module GlobePG
|
25
|
-
class TeacherToSchool < PGBase
|
26
|
-
set_table_name 'teacher_to_school'
|
27
|
-
self.primary_keys = ['teacherid', 'schoolid']
|
28
|
-
|
29
|
-
belongs_to :globe_teacher, :foreign_key => 'teacherid'
|
30
|
-
belongs_to :globe_school, :foreign_key => 'schoolid'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module GlobePG
|
35
|
-
class GlobeSchool < PGBase
|
36
|
-
set_table_name 'globe_school'
|
37
|
-
self.primary_key = 'schoolid'
|
38
|
-
has_many :teacher_to_schools, :foreign_key => :schoolid
|
39
|
-
has_many :globe_teachers, :through => :teacher_to_schools
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
module GlobePG
|
44
|
-
class GlobeTeacher < PGBase
|
45
|
-
set_table_name 'globe_teacher'
|
46
|
-
self.primary_key = 'teacherid'
|
47
|
-
has_many :teacher_to_schools, :foreign_key => :teacherid
|
48
|
-
has_many :globe_schools, :through => :teacher_to_schools
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
teacher = GlobePG::GlobeTeacher.find_by_teacherid('ZZGLOBEY')
|
1
|
+
# assoc_test.rb
|
2
|
+
|
3
|
+
path = File.expand_path(File.join(File.basename(__FILE__), "..", "lib", "composite_primary_keys"))
|
4
|
+
puts path
|
5
|
+
|
6
|
+
require File.join(path)
|
7
|
+
require 'active_record'
|
8
|
+
|
9
|
+
$configuration = {
|
10
|
+
:adapter => 'postgresql',
|
11
|
+
:database => 'cpk_test',
|
12
|
+
:username => 'postgres'
|
13
|
+
}
|
14
|
+
|
15
|
+
ActiveRecord::Base.establish_connection($configuration) unless ActiveRecord::Base.connected?
|
16
|
+
|
17
|
+
module GlobePG
|
18
|
+
class PGBase < ActiveRecord::Base
|
19
|
+
self.abstract_class = true
|
20
|
+
# establish_connection($configuration) unless connected?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module GlobePG
|
25
|
+
class TeacherToSchool < PGBase
|
26
|
+
set_table_name 'teacher_to_school'
|
27
|
+
self.primary_keys = ['teacherid', 'schoolid']
|
28
|
+
|
29
|
+
belongs_to :globe_teacher, :foreign_key => 'teacherid'
|
30
|
+
belongs_to :globe_school, :foreign_key => 'schoolid'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module GlobePG
|
35
|
+
class GlobeSchool < PGBase
|
36
|
+
set_table_name 'globe_school'
|
37
|
+
self.primary_key = 'schoolid'
|
38
|
+
has_many :teacher_to_schools, :foreign_key => :schoolid
|
39
|
+
has_many :globe_teachers, :through => :teacher_to_schools
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module GlobePG
|
44
|
+
class GlobeTeacher < PGBase
|
45
|
+
set_table_name 'globe_teacher'
|
46
|
+
self.primary_key = 'teacherid'
|
47
|
+
has_many :teacher_to_schools, :foreign_key => :teacherid
|
48
|
+
has_many :globe_schools, :through => :teacher_to_schools
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
teacher = GlobePG::GlobeTeacher.find_by_teacherid('ZZGLOBEY')
|
53
53
|
p teacher.globe_schools
|
data/test/fixtures/articles.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
first:
|
2
|
-
id: 1
|
3
|
-
name: Article One
|
4
|
-
|
5
|
-
second:
|
6
|
-
id: 2
|
1
|
+
first:
|
2
|
+
id: 1
|
3
|
+
name: Article One
|
4
|
+
|
5
|
+
second:
|
6
|
+
id: 2
|
7
7
|
name: Article Two
|
data/test/fixtures/capitol.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class Capitol < ActiveRecord::Base
|
2
|
-
self.primary_keys = :country, :city
|
3
|
-
end
|
1
|
+
class Capitol < ActiveRecord::Base
|
2
|
+
self.primary_keys = :country, :city
|
3
|
+
end
|
data/test/fixtures/capitols.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
netherlands:
|
2
|
-
country: The Netherlands
|
3
|
-
city: Amsterdam
|
4
|
-
|
5
|
-
france:
|
6
|
-
country: France
|
7
|
-
city: Paris
|
8
|
-
|
9
|
-
canada:
|
10
|
-
country: Canada
|
11
|
-
city: Ottawa
|
12
|
-
|
13
|
-
mexico:
|
14
|
-
country: Mexico
|
15
|
-
city: Mexico City
|
16
|
-
|
1
|
+
netherlands:
|
2
|
+
country: The Netherlands
|
3
|
+
city: Amsterdam
|
4
|
+
|
5
|
+
france:
|
6
|
+
country: France
|
7
|
+
city: Paris
|
8
|
+
|
9
|
+
canada:
|
10
|
+
country: Canada
|
11
|
+
city: Ottawa
|
12
|
+
|
13
|
+
mexico:
|
14
|
+
country: Mexico
|
15
|
+
city: Mexico City
|
16
|
+
|
data/test/fixtures/comments.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
comment1:
|
2
|
-
id: 1
|
3
|
-
person_id: 1
|
4
|
-
person_type: Employee
|
5
|
-
|
6
|
-
comment2:
|
7
|
-
id: 2
|
8
|
-
person_id: 1
|
9
|
-
person_type: User
|
10
|
-
hack_id: 7
|
11
|
-
|
12
|
-
comment3:
|
13
|
-
id: 3
|
14
|
-
person_id: 7
|
15
|
-
person_type: Hack
|
1
|
+
comment1:
|
2
|
+
id: 1
|
3
|
+
person_id: 1
|
4
|
+
person_type: Employee
|
5
|
+
|
6
|
+
comment2:
|
7
|
+
id: 2
|
8
|
+
person_id: 1
|
9
|
+
person_type: User
|
10
|
+
hack_id: 7
|
11
|
+
|
12
|
+
comment3:
|
13
|
+
id: 3
|
14
|
+
person_id: 7
|
15
|
+
person_type: Hack
|
16
16
|
|
data/test/fixtures/department.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
class Department < ActiveRecord::Base
|
2
|
-
self.primary_keys = :department_id, :location_id
|
3
|
-
has_many :employees, :foreign_key => [:department_id, :location_id]
|
4
|
-
has_one :head, :class_name => 'Employee', :foreign_key => [:department_id, :location_id], :dependent => :delete
|
5
|
-
end
|
1
|
+
class Department < ActiveRecord::Base
|
2
|
+
self.primary_keys = :department_id, :location_id
|
3
|
+
has_many :employees, :foreign_key => [:department_id, :location_id]
|
4
|
+
has_one :head, :class_name => 'Employee', :foreign_key => [:department_id, :location_id], :dependent => :delete
|
5
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
accounting:
|
2
|
-
department_id: 1
|
3
|
-
location_id: 1
|
4
|
-
|
5
|
-
engineering:
|
6
|
-
department_id: 2
|
7
|
-
location_id: 1
|
8
|
-
|
9
|
-
human_resources:
|
10
|
-
department_id: 3
|
11
|
-
location_id: 2
|
12
|
-
|
13
|
-
offsite_accounting:
|
14
|
-
department_id: 1
|
15
|
-
location_id: 2
|
1
|
+
accounting:
|
2
|
+
department_id: 1
|
3
|
+
location_id: 1
|
4
|
+
|
5
|
+
engineering:
|
6
|
+
department_id: 2
|
7
|
+
location_id: 1
|
8
|
+
|
9
|
+
human_resources:
|
10
|
+
department_id: 3
|
11
|
+
location_id: 2
|
12
|
+
|
13
|
+
offsite_accounting:
|
14
|
+
department_id: 1
|
15
|
+
location_id: 2
|