composite_primary_keys 9.0.10 → 10.0.0
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.
- checksums.yaml +5 -5
- data/History.rdoc +4 -9
- data/README.rdoc +10 -9
- data/lib/composite_primary_keys.rb +6 -5
- data/lib/composite_primary_keys/arel/sqlserver.rb +2 -1
- data/lib/composite_primary_keys/associations/association_scope.rb +4 -4
- data/lib/composite_primary_keys/associations/collection_association.rb +1 -1
- data/lib/composite_primary_keys/associations/preloader/association.rb +2 -2
- data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +2 -2
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +14 -1
- data/lib/composite_primary_keys/attribute_methods/write.rb +14 -0
- data/lib/composite_primary_keys/attribute_set/builder.rb +22 -0
- data/lib/composite_primary_keys/base.rb +6 -5
- data/lib/composite_primary_keys/composite_predicates.rb +4 -0
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
- data/lib/composite_primary_keys/connection_adapters/postgresql/database_statements.rb +26 -0
- data/lib/composite_primary_keys/core.rb +9 -12
- data/lib/composite_primary_keys/locking/optimistic.rb +7 -7
- data/lib/composite_primary_keys/nested_attributes.rb +1 -1
- data/lib/composite_primary_keys/relation.rb +1 -6
- data/lib/composite_primary_keys/relation/predicate_builder/association_query_handler.rb +33 -0
- data/lib/composite_primary_keys/version.rb +2 -2
- 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 +30 -40
- 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_associations.rb +0 -10
- 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_find.rb +9 -3
- data/test/test_miscellaneous.rb +32 -32
- data/test/test_pagination.rb +35 -35
- data/test/test_validations.rb +13 -13
- metadata +8 -13
- data/lib/composite_primary_keys/autosave_association.rb +0 -32
- data/lib/composite_primary_keys/relation/predicate_builder.rb +0 -26
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,40 +1,30 @@
|
|
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
|
-
adapter:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
adapter: sqlite3
|
32
|
-
database: <%= File.join(project_root, 'db', 'composite_primary_keys_unittest.sqlite') %>
|
33
|
-
|
34
|
-
sqlserver:
|
35
|
-
adapter: sqlserver
|
36
|
-
username: cpk
|
37
|
-
password: cpk
|
38
|
-
database: composite_primary_keys_unittest
|
39
|
-
host: localhost
|
40
|
-
port: 1433
|
1
|
+
mysql:
|
2
|
+
adapter: mysql2
|
3
|
+
username: root
|
4
|
+
password: mysql
|
5
|
+
database: composite_primary_keys_unittest
|
6
|
+
|
7
|
+
oracle:
|
8
|
+
adapter: oracle_enhanced
|
9
|
+
database: xe
|
10
|
+
username: SYSTEM
|
11
|
+
password: oracle
|
12
|
+
host: localhost
|
13
|
+
|
14
|
+
postgresql:
|
15
|
+
adapter: postgresql
|
16
|
+
database: composite_primary_keys_unittest
|
17
|
+
username: postgres
|
18
|
+
host: localhost
|
19
|
+
|
20
|
+
sqlite:
|
21
|
+
adapter: sqlite3
|
22
|
+
database: <%= File.join(project_root, 'db', 'composite_primary_keys_unittest.sqlite') %>
|
23
|
+
|
24
|
+
sqlserver:
|
25
|
+
adapter: sqlserver
|
26
|
+
username: cpk
|
27
|
+
password: cpk
|
28
|
+
database: composite_primary_keys_unittest
|
29
|
+
host: localhost
|
30
|
+
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
|