composite_primary_keys 8.1.6 → 9.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.rdoc +59 -7
- data/README.rdoc +62 -1
- data/Rakefile +4 -1
- data/lib/composite_primary_keys/arel/in.rb +6 -0
- data/lib/composite_primary_keys/arel/sqlserver.rb +36 -0
- data/lib/composite_primary_keys/arel/to_sql.rb +26 -0
- data/lib/composite_primary_keys/associations/association.rb +14 -12
- data/lib/composite_primary_keys/associations/association_scope.rb +22 -27
- data/lib/composite_primary_keys/associations/collection_association.rb +39 -8
- data/lib/composite_primary_keys/associations/has_many_association.rb +17 -40
- data/lib/composite_primary_keys/associations/has_many_through_association.rb +58 -58
- data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +13 -11
- data/lib/composite_primary_keys/associations/join_dependency.rb +73 -56
- data/lib/composite_primary_keys/associations/preloader/association.rb +75 -73
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +13 -11
- data/lib/composite_primary_keys/attribute_methods/read.rb +18 -15
- data/lib/composite_primary_keys/attribute_methods/write.rb +21 -19
- data/lib/composite_primary_keys/attribute_methods.rb +6 -4
- data/lib/composite_primary_keys/autosave_association.rb +19 -54
- data/lib/composite_primary_keys/base.rb +18 -82
- data/lib/composite_primary_keys/composite_arrays.rb +9 -1
- data/lib/composite_primary_keys/composite_predicates.rb +1 -0
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
- data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +5 -6
- data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +23 -0
- data/lib/composite_primary_keys/core.rb +46 -45
- data/lib/composite_primary_keys/fixtures.rb +19 -17
- data/lib/composite_primary_keys/locking/optimistic.rb +53 -49
- data/lib/composite_primary_keys/nested_attributes.rb +60 -53
- data/lib/composite_primary_keys/persistence.rb +49 -41
- data/lib/composite_primary_keys/relation/batches.rb +35 -32
- data/lib/composite_primary_keys/relation/calculations.rb +3 -7
- data/lib/composite_primary_keys/relation/finder_methods.rb +122 -55
- data/lib/composite_primary_keys/relation/predicate_builder.rb +18 -29
- data/lib/composite_primary_keys/relation/query_methods.rb +25 -36
- data/lib/composite_primary_keys/relation/where_clause.rb +33 -0
- data/lib/composite_primary_keys/relation.rb +96 -43
- data/lib/composite_primary_keys/sanitization.rb +6 -15
- data/lib/composite_primary_keys/version.rb +3 -3
- data/lib/composite_primary_keys.rb +10 -19
- data/scripts/console.rb +48 -48
- data/scripts/txt2html +76 -76
- data/scripts/txt2js +65 -65
- data/tasks/databases/mysql.rake +17 -19
- data/tasks/databases/oracle.rake +29 -15
- data/tasks/databases/postgresql.rake +20 -29
- data/tasks/databases/sqlite.rake +25 -0
- data/tasks/databases/sqlserver.rake +32 -16
- data/tasks/website.rake +18 -18
- data/test/README_tests.rdoc +56 -56
- data/test/abstract_unit.rb +24 -18
- data/test/connections/connection_spec.rb +11 -2
- data/test/connections/databases.ci.yml +5 -4
- data/test/connections/databases.example.yml +19 -4
- data/test/connections/databases.yml +40 -30
- data/test/db_test.rb +52 -52
- data/test/fixtures/article.rb +1 -0
- 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/db_definitions/mysql.sql +16 -17
- data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
- data/test/fixtures/db_definitions/oracle.sql +26 -17
- data/test/fixtures/db_definitions/postgresql.sql +2 -3
- data/test/fixtures/db_definitions/sqlite.sql +0 -1
- data/test/fixtures/db_definitions/sqlserver.sql +20 -35
- data/test/fixtures/department.rb +5 -5
- data/test/fixtures/departments.yml +15 -15
- data/test/fixtures/dorms.yml +4 -4
- data/test/fixtures/employee.rb +5 -7
- data/test/fixtures/employees.yml +1 -5
- 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_type.rb +1 -1
- 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/tariff.rb +1 -1
- data/test/fixtures/tariffs.yml +14 -14
- data/test/fixtures/user.rb +0 -1
- 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 +18 -17
- data/test/test_composite_arrays.rb +24 -24
- data/test/test_counter_cache.rb +30 -30
- data/test/test_create.rb +14 -6
- data/test/test_delete.rb +36 -34
- data/test/test_dup.rb +37 -37
- data/test/test_exists.rb +39 -39
- data/test/test_find.rb +16 -4
- data/test/test_habtm.rb +27 -3
- data/test/test_miscellaneous.rb +32 -32
- data/test/test_nested_attributes.rb +6 -6
- data/test/test_pagination.rb +35 -35
- data/test/test_polymorphic.rb +0 -7
- data/test/test_predicates.rb +20 -20
- data/test/test_preload.rb +94 -0
- data/test/test_suite.rb +1 -1
- data/test/test_update.rb +10 -7
- data/test/test_validations.rb +13 -13
- metadata +30 -39
- data/README_DB2.rdoc +0 -33
- data/lib/composite_primary_keys/arel/visitors/to_sql.rb +0 -36
- data/lib/composite_primary_keys/associations/singular_association.rb +0 -18
- data/lib/composite_primary_keys/attribute_methods/dirty.rb +0 -29
- data/lib/composite_primary_keys/attribute_set/builder.rb +0 -20
- data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +0 -70
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +0 -19
- data/lib/composite_primary_keys/dirty.rb +0 -19
- data/lib/composite_primary_keys/validations/uniqueness.rb +0 -41
- data/tasks/databases/oracle_enhanced.rake +0 -27
- data/tasks/databases/sqlite3.rake +0 -27
- data/test/connections/native_ibm_db/connection.rb +0 -19
- data/test/connections/native_mysql/connection.rb +0 -17
- data/test/connections/native_oracle/connection.rb +0 -11
- data/test/connections/native_oracle_enhanced/connection.rb +0 -16
- data/test/connections/native_postgresql/connection.rb +0 -13
- data/test/connections/native_sqlite3/connection.rb +0 -9
- data/test/connections/native_sqlserver/connection.rb +0 -11
- data/test/fixtures/db_definitions/sqlserver.drop.sql +0 -92
- data/test/test_delete_all.rb +0 -35
- data/test/test_find_in_batches.rb +0 -30
data/scripts/txt2js
CHANGED
@@ -1,65 +1,65 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'redcloth'
|
5
|
-
require 'syntax/convertors/html'
|
6
|
-
require 'erb'
|
7
|
-
require 'active_support'
|
8
|
-
|
9
|
-
version_path = File.join(File.dirname(__FILE__), '..', 'lib', 'composite_primary_keys', 'version.rb')
|
10
|
-
require File.expand_path(version_path)
|
11
|
-
|
12
|
-
version = CompositePrimaryKeys::VERSION::STRING
|
13
|
-
download = 'http://rubygems.org/gems/composite_primary_keys'
|
14
|
-
|
15
|
-
class Fixnum
|
16
|
-
def ordinal
|
17
|
-
# teens
|
18
|
-
return 'th' if (10..19).include?(self % 100)
|
19
|
-
# others
|
20
|
-
case self % 10
|
21
|
-
when 1
|
22
|
-
return 'st'
|
23
|
-
when 2
|
24
|
-
return 'nd'
|
25
|
-
when 3
|
26
|
-
return 'rd'
|
27
|
-
else
|
28
|
-
return 'th'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class Time
|
34
|
-
def pretty
|
35
|
-
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def convert_syntax(syntax, source)
|
40
|
-
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
41
|
-
end
|
42
|
-
|
43
|
-
if ARGV.length >= 1
|
44
|
-
src, template = ARGV
|
45
|
-
template ||= File.dirname(__FILE__) + '/../website/template.js'
|
46
|
-
else
|
47
|
-
puts("Usage: #{File.split($0).last} source.txt [template.js] > output.html")
|
48
|
-
exit!
|
49
|
-
end
|
50
|
-
|
51
|
-
template = ERB.new(File.open(template).read)
|
52
|
-
|
53
|
-
title = nil
|
54
|
-
body = nil
|
55
|
-
File.open(src) do |fsrc|
|
56
|
-
title_text = fsrc.readline
|
57
|
-
body_text = fsrc.read
|
58
|
-
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
59
|
-
body = RedCloth.new(body_text)
|
60
|
-
end
|
61
|
-
stat = File.stat(src)
|
62
|
-
created = stat.ctime
|
63
|
-
modified = stat.mtime
|
64
|
-
|
65
|
-
$stdout << template.result(binding)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'redcloth'
|
5
|
+
require 'syntax/convertors/html'
|
6
|
+
require 'erb'
|
7
|
+
require 'active_support'
|
8
|
+
|
9
|
+
version_path = File.join(File.dirname(__FILE__), '..', 'lib', 'composite_primary_keys', 'version.rb')
|
10
|
+
require File.expand_path(version_path)
|
11
|
+
|
12
|
+
version = CompositePrimaryKeys::VERSION::STRING
|
13
|
+
download = 'http://rubygems.org/gems/composite_primary_keys'
|
14
|
+
|
15
|
+
class Fixnum
|
16
|
+
def ordinal
|
17
|
+
# teens
|
18
|
+
return 'th' if (10..19).include?(self % 100)
|
19
|
+
# others
|
20
|
+
case self % 10
|
21
|
+
when 1
|
22
|
+
return 'st'
|
23
|
+
when 2
|
24
|
+
return 'nd'
|
25
|
+
when 3
|
26
|
+
return 'rd'
|
27
|
+
else
|
28
|
+
return 'th'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Time
|
34
|
+
def pretty
|
35
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert_syntax(syntax, source)
|
40
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
41
|
+
end
|
42
|
+
|
43
|
+
if ARGV.length >= 1
|
44
|
+
src, template = ARGV
|
45
|
+
template ||= File.dirname(__FILE__) + '/../website/template.js'
|
46
|
+
else
|
47
|
+
puts("Usage: #{File.split($0).last} source.txt [template.js] > output.html")
|
48
|
+
exit!
|
49
|
+
end
|
50
|
+
|
51
|
+
template = ERB.new(File.open(template).read)
|
52
|
+
|
53
|
+
title = nil
|
54
|
+
body = nil
|
55
|
+
File.open(src) do |fsrc|
|
56
|
+
title_text = fsrc.readline
|
57
|
+
body_text = fsrc.read
|
58
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
59
|
+
body = RedCloth.new(body_text)
|
60
|
+
end
|
61
|
+
stat = File.stat(src)
|
62
|
+
created = stat.ctime
|
63
|
+
modified = stat.mtime
|
64
|
+
|
65
|
+
$stdout << template.result(binding)
|
data/tasks/databases/mysql.rake
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
2
|
-
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
3
|
-
|
4
1
|
namespace :mysql do
|
5
|
-
|
6
|
-
|
2
|
+
task :setup do
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.require(:default, :mysql)
|
5
|
+
end
|
6
|
+
|
7
|
+
task :create_database => :setup do
|
8
|
+
spec = CompositePrimaryKeys::ConnectionSpec['mysql']
|
7
9
|
ActiveRecord::Base.clear_all_connections!
|
8
|
-
|
9
|
-
|
10
|
-
connection = ActiveRecord::Base.establish_connection(
|
11
|
-
ActiveRecord::Base.connection.create_database(
|
10
|
+
new_spec = spec.dup
|
11
|
+
new_spec.delete('database')
|
12
|
+
connection = ActiveRecord::Base.establish_connection(new_spec)
|
13
|
+
ActiveRecord::Base.connection.create_database(spec['database'])
|
12
14
|
ActiveRecord::Base.clear_all_connections!
|
13
15
|
end
|
14
16
|
|
@@ -19,24 +21,20 @@ namespace :mysql do
|
|
19
21
|
file.read
|
20
22
|
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
#puts %(ActiveRecord::Base.connection.instance_variable_get(:@config)=#{(ActiveRecord::Base.connection.instance_variable_get(:@config)).inspect})
|
24
|
+
spec = CompositePrimaryKeys::ConnectionSpec['mysql']
|
25
|
+
connection = ActiveRecord::Base.establish_connection(spec)
|
25
26
|
sql.split(";").each do |statement|
|
26
27
|
ActiveRecord::Base.connection.execute(statement) unless statement.strip.length == 0
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
31
|
desc 'Drop the MySQL test database'
|
31
|
-
task :drop_database => :
|
32
|
-
|
32
|
+
task :drop_database => :setup do
|
33
|
+
spec = CompositePrimaryKeys::ConnectionSpec['mysql']
|
34
|
+
connection = ActiveRecord::Base.establish_connection(spec)
|
35
|
+
ActiveRecord::Base.connection.drop_database(spec['database'])
|
33
36
|
end
|
34
37
|
|
35
38
|
desc 'Rebuild the MySQL test database'
|
36
39
|
task :rebuild_database => [:drop_database, :build_database]
|
37
|
-
|
38
|
-
task :load_connection do
|
39
|
-
require File.join(PROJECT_ROOT, "test", "connections", "native_mysql", "connection")
|
40
|
-
establish_connection
|
41
|
-
end
|
42
40
|
end
|
data/tasks/databases/oracle.rake
CHANGED
@@ -1,27 +1,41 @@
|
|
1
|
-
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
2
|
-
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
3
|
-
|
4
1
|
namespace :oracle do
|
2
|
+
task :setup do
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.require(:default, :oracle)
|
5
|
+
end
|
6
|
+
|
5
7
|
desc 'Build the Oracle test database'
|
6
|
-
task :build_database => :
|
7
|
-
|
8
|
+
task :build_database => :setup do
|
9
|
+
spec = CompositePrimaryKeys::ConnectionSpec['oracle']
|
10
|
+
ActiveRecord::Base.clear_all_connections!
|
11
|
+
ActiveRecord::Base.establish_connection(spec)
|
12
|
+
|
13
|
+
schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'oracle.sql')
|
14
|
+
sql = File.read(schema)
|
15
|
+
|
16
|
+
sql.split(';').each do |command|
|
17
|
+
ActiveRecord::Base.connection.execute(command) unless command.blank?
|
18
|
+
end
|
8
19
|
|
9
|
-
|
10
|
-
sh %( sqlplus #{options_str} < #{sql} )
|
20
|
+
ActiveRecord::Base.clear_all_connections!
|
11
21
|
end
|
12
22
|
|
13
23
|
desc 'Drop the Oracle test database'
|
14
|
-
task :drop_database => :
|
15
|
-
|
24
|
+
task :drop_database => :setup do
|
25
|
+
spec = CompositePrimaryKeys::ConnectionSpec['oracle']
|
26
|
+
ActiveRecord::Base.clear_all_connections!
|
27
|
+
ActiveRecord::Base.establish_connection(spec)
|
16
28
|
|
17
|
-
|
18
|
-
|
29
|
+
schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'oracle.drop.sql')
|
30
|
+
sql = File.read(schema)
|
31
|
+
|
32
|
+
sql.split(';').each do |command|
|
33
|
+
ActiveRecord::Base.connection.execute(command)
|
34
|
+
end
|
35
|
+
|
36
|
+
ActiveRecord::Base.clear_all_connections!
|
19
37
|
end
|
20
38
|
|
21
39
|
desc 'Rebuild the Oracle test database'
|
22
40
|
task :rebuild_database => [:drop_database, :build_database]
|
23
|
-
|
24
|
-
task :load_connection do
|
25
|
-
require File.join(PROJECT_ROOT, "test", "connections", "native_oracle", "connection")
|
26
|
-
end
|
27
41
|
end
|
@@ -1,48 +1,39 @@
|
|
1
|
-
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
2
|
-
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
3
|
-
|
4
1
|
namespace :postgresql do
|
5
|
-
|
6
|
-
|
2
|
+
task :setup do
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.require(:default, :postgresql)
|
5
|
+
end
|
6
|
+
|
7
|
+
task :create_database => :setup do
|
8
|
+
spec = CompositePrimaryKeys::ConnectionSpec['postgresql']
|
7
9
|
ActiveRecord::Base.clear_all_connections!
|
8
|
-
spec
|
9
|
-
|
10
|
-
spec['database'] = 'postgres'
|
11
|
-
connection = ActiveRecord::Base.establish_connection(spec)
|
12
|
-
ActiveRecord::Base.connection.create_database(database_name)
|
10
|
+
ActiveRecord::Base.establish_connection(spec.dup.merge('database' => 'postgres'))
|
11
|
+
ActiveRecord::Base.connection.create_database(spec['database'])
|
13
12
|
ActiveRecord::Base.clear_all_connections!
|
14
13
|
end
|
15
14
|
|
16
|
-
desc 'Build the
|
17
|
-
task :build_database =>
|
15
|
+
desc 'Build the Postgresql test database'
|
16
|
+
task :build_database => :create_database do
|
17
|
+
spec = CompositePrimaryKeys::ConnectionSpec['postgresql']
|
18
18
|
ActiveRecord::Base.clear_all_connections!
|
19
|
-
spec = CompositePrimaryKeys::ConnectionSpec['postgresql'].dup
|
20
19
|
connection = ActiveRecord::Base.establish_connection(spec)
|
21
20
|
|
22
|
-
|
23
|
-
sql = File.
|
24
|
-
file.read
|
25
|
-
end
|
21
|
+
schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'postgresql.sql')
|
22
|
+
sql = File.read(schema)
|
26
23
|
|
27
|
-
Rake::Task['postgresql:load_connection'].invoke
|
28
24
|
ActiveRecord::Base.connection.execute(sql)
|
25
|
+
ActiveRecord::Base.clear_all_connections!
|
29
26
|
end
|
30
27
|
|
31
|
-
desc 'Drop the
|
32
|
-
task :drop_database
|
28
|
+
desc 'Drop the Postgresql test database'
|
29
|
+
task :drop_database => :setup do
|
30
|
+
spec = CompositePrimaryKeys::ConnectionSpec['postgresql']
|
33
31
|
ActiveRecord::Base.clear_all_connections!
|
34
|
-
|
35
|
-
|
36
|
-
spec['database'] = 'postgres'
|
37
|
-
connection = ActiveRecord::Base.establish_connection(spec)
|
38
|
-
ActiveRecord::Base.connection.drop_database(SPEC['database'])
|
32
|
+
connection = ActiveRecord::Base.establish_connection(spec.merge('database' => 'postgres'))
|
33
|
+
ActiveRecord::Base.connection.drop_database(spec['database'])
|
39
34
|
ActiveRecord::Base.clear_all_connections!
|
40
35
|
end
|
41
36
|
|
42
37
|
desc 'Rebuild the PostgreSQL test database'
|
43
38
|
task :rebuild_database => [:drop_database, :build_database]
|
44
|
-
|
45
|
-
task :load_connection do
|
46
|
-
require File.join(PROJECT_ROOT, "test", "connections", "native_postgresql", "connection")
|
47
|
-
end
|
48
39
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
namespace :sqlite do
|
2
|
+
task :setup do
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.require(:default, :sqlite)
|
5
|
+
end
|
6
|
+
|
7
|
+
desc 'Build the sqlite test database'
|
8
|
+
task :build_database => :setup do
|
9
|
+
spec = CompositePrimaryKeys::ConnectionSpec['sqlite']
|
10
|
+
schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'sqlite.sql')
|
11
|
+
FileUtils.mkdir_p(File.dirname(spec['database']))
|
12
|
+
cmd = "sqlite3 #{spec['database']} < #{schema}"
|
13
|
+
puts cmd
|
14
|
+
sh %{ #{cmd} }
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Drop the sqlite test database'
|
18
|
+
task :drop_database => :setup do
|
19
|
+
spec = CompositePrimaryKeys::ConnectionSpec['sqlite']
|
20
|
+
sh %{ rm -f #{spec['database']} }
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Rebuild the sqlite test database'
|
24
|
+
task :rebuild_database => [:drop_database, :build_database]
|
25
|
+
end
|
@@ -1,27 +1,43 @@
|
|
1
|
-
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
2
|
-
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
3
|
-
|
4
1
|
namespace :sqlserver do
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
task :setup do
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.require(:default, :sqlserver)
|
5
|
+
end
|
6
|
+
|
7
|
+
task :create_database => :setup do
|
8
|
+
spec = CompositePrimaryKeys::ConnectionSpec['sqlserver']
|
9
|
+
database = spec.delete('database')
|
10
|
+
ActiveRecord::Base.clear_all_connections!
|
11
|
+
|
12
|
+
ActiveRecord::Base.establish_connection(spec)
|
13
|
+
ActiveRecord::Base.connection.execute("CREATE DATABASE [#{database}]")
|
14
|
+
ActiveRecord::Base.clear_all_connections!
|
15
|
+
end
|
16
|
+
|
17
|
+
task :build_database => :create_database do
|
18
|
+
spec = CompositePrimaryKeys::ConnectionSpec['sqlserver']
|
19
|
+
ActiveRecord::Base.establish_connection(spec)
|
8
20
|
|
9
21
|
schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'sqlserver.sql')
|
10
|
-
|
22
|
+
sql = File.read(schema)
|
23
|
+
ActiveRecord::Base.connection.execute(sql)
|
24
|
+
ActiveRecord::Base.clear_all_connections!
|
11
25
|
end
|
12
26
|
|
13
27
|
desc 'Drop the SQL Server test database'
|
14
|
-
task :drop_database => :
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
28
|
+
task :drop_database => :setup do
|
29
|
+
spec = CompositePrimaryKeys::ConnectionSpec['sqlserver']
|
30
|
+
ActiveRecord::Base.clear_all_connections!
|
31
|
+
ActiveRecord::Base.establish_connection(spec)
|
32
|
+
database = spec.delete('database')
|
33
|
+
ActiveRecord::Base.connection.execute(<<-SQL)
|
34
|
+
USE master;
|
35
|
+
ALTER DATABASE [#{database}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
|
36
|
+
DROP DATABASE [#{database}];
|
37
|
+
SQL
|
38
|
+
ActiveRecord::Base.clear_all_connections!
|
19
39
|
end
|
20
40
|
|
21
41
|
desc 'Rebuild the SQL Server test database'
|
22
42
|
task :rebuild_database => [:drop_database, :build_database]
|
23
|
-
|
24
|
-
task :load_connection do
|
25
|
-
require File.join(PROJECT_ROOT, "test", "connections", "native_sqlserver", "connection")
|
26
|
-
end
|
27
43
|
end
|
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
|
data/test/abstract_unit.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
spec_name = ENV['ADAPTER'] || 'postgresql'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.require(:default, spec_name.to_sym)
|
2
4
|
|
3
5
|
# To make debugging easier, test within this source tree versus an installed gem
|
4
6
|
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
|
@@ -6,15 +8,19 @@ require 'composite_primary_keys'
|
|
6
8
|
require 'minitest/autorun'
|
7
9
|
require 'active_support/test_case'
|
8
10
|
|
9
|
-
#
|
10
|
-
|
11
|
+
# Require the connection spec
|
12
|
+
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
13
|
+
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
11
14
|
|
12
|
-
spec_name = ENV['ADAPTER'] || 'postgresql'
|
13
15
|
spec = CompositePrimaryKeys::ConnectionSpec[spec_name]
|
16
|
+
puts "Loaded #{spec_name}"
|
14
17
|
|
15
18
|
# And now connect to the database
|
16
|
-
|
17
|
-
|
19
|
+
ActiveRecord::Base.establish_connection(spec)
|
20
|
+
|
21
|
+
if defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter)
|
22
|
+
require 'composite_primary_keys/connection_adapters/sqlite3_adapter'
|
23
|
+
end
|
18
24
|
|
19
25
|
# Tell active record about the configuration
|
20
26
|
ActiveRecord::Base.configurations[:test] = spec
|
@@ -26,17 +32,17 @@ I18n.config.enforce_available_locales = true
|
|
26
32
|
|
27
33
|
class ActiveSupport::TestCase
|
28
34
|
include ActiveRecord::TestFixtures
|
29
|
-
|
30
|
-
self.fixture_path = File.dirname(__FILE__) +
|
35
|
+
|
36
|
+
self.fixture_path = File.dirname(__FILE__) + '/fixtures/'
|
31
37
|
self.use_instantiated_fixtures = false
|
32
|
-
self.
|
38
|
+
self.use_transactional_tests = true
|
33
39
|
self.test_order = :random
|
34
40
|
|
35
41
|
def assert_date_from_db(expected, actual, message = nil)
|
36
|
-
# SQL Server doesn't have a separate column type just for dates,
|
42
|
+
# SQL Server doesn't have a separate column type just for dates,
|
37
43
|
# so the time is in the string and incorrectly formatted
|
38
44
|
if current_adapter?(:SQLServerAdapter)
|
39
|
-
assert_equal expected.strftime(
|
45
|
+
assert_equal expected.strftime('%Y/%m/%d 00:00:00'), actual.strftime('%Y/%m/%d 00:00:00')
|
40
46
|
elsif current_adapter?(:SybaseAdapter)
|
41
47
|
assert_equal expected.to_s, actual.to_date.to_s, message
|
42
48
|
else
|
@@ -54,17 +60,17 @@ class ActiveSupport::TestCase
|
|
54
60
|
ActiveRecord::Base.connection.class.class_eval do
|
55
61
|
alias_method :execute, :execute_without_query_counting
|
56
62
|
end
|
57
|
-
assert_equal num, ActiveRecord::Base.connection.query_count,
|
63
|
+
assert_equal num, ActiveRecord::Base.connection.query_count, '#{ActiveRecord::Base.connection.query_count} instead of #{num} queries were executed.'
|
58
64
|
end
|
59
65
|
|
60
66
|
def assert_no_queries(&block)
|
61
67
|
assert_queries(0, &block)
|
62
68
|
end
|
63
|
-
|
69
|
+
|
64
70
|
cattr_accessor :classes
|
65
71
|
|
66
72
|
protected
|
67
|
-
|
73
|
+
|
68
74
|
def testing_with(&block)
|
69
75
|
classes.keys.each do |key_test|
|
70
76
|
@key_test = key_test
|
@@ -75,19 +81,19 @@ class ActiveSupport::TestCase
|
|
75
81
|
yield
|
76
82
|
end
|
77
83
|
end
|
78
|
-
|
84
|
+
|
79
85
|
def first_id
|
80
86
|
ids = (1..@primary_keys.length).map {|num| 1}
|
81
87
|
composite? ? ids.to_composite_ids : ids.first
|
82
88
|
end
|
83
|
-
|
89
|
+
|
84
90
|
def composite?
|
85
91
|
@key_test != :single
|
86
|
-
end
|
92
|
+
end
|
87
93
|
|
88
94
|
# Oracle metadata is in all caps.
|
89
95
|
def with_quoted_identifiers(s)
|
90
|
-
s.gsub(/
|
96
|
+
s.gsub(/'(\w+)'/) { |m|
|
91
97
|
if ActiveRecord::Base.configurations[:test]['adapter'] =~ /oracle/i
|
92
98
|
m.upcase
|
93
99
|
else
|