activerecord-jdbc-adapter 1.3.0.beta1 → 1.3.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -11
- data/.travis.yml +36 -7
- data/Appraisals +3 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +13 -6
- data/History.txt +64 -0
- data/README.md +8 -1
- data/Rakefile +3 -1
- data/gemfiles/rails23.gemfile +1 -1
- data/gemfiles/rails23.gemfile.lock +6 -5
- data/gemfiles/rails30.gemfile +1 -1
- data/gemfiles/rails30.gemfile.lock +7 -6
- data/gemfiles/rails31.gemfile +1 -1
- data/gemfiles/rails31.gemfile.lock +6 -5
- data/gemfiles/rails32.gemfile +1 -1
- data/gemfiles/rails32.gemfile.lock +6 -5
- data/gemfiles/rails40.gemfile +2 -4
- data/gemfiles/rails40.gemfile.lock +37 -51
- data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +1 -1
- data/lib/arel/visitors/db2.rb +5 -1
- data/lib/arel/visitors/hsqldb.rb +1 -0
- data/lib/arel/visitors/sql_server.rb +55 -13
- data/lib/arjdbc/db2/adapter.rb +197 -227
- data/lib/arjdbc/db2/as400.rb +124 -0
- data/lib/arjdbc/db2/connection_methods.rb +20 -1
- data/lib/arjdbc/derby/adapter.rb +17 -85
- data/lib/arjdbc/derby/connection_methods.rb +2 -1
- data/lib/arjdbc/discover.rb +55 -47
- data/lib/arjdbc/h2/adapter.rb +52 -18
- data/lib/arjdbc/h2/connection_methods.rb +10 -2
- data/lib/arjdbc/hsqldb/adapter.rb +33 -9
- data/lib/arjdbc/hsqldb/connection_methods.rb +10 -2
- data/lib/arjdbc/informix.rb +2 -1
- data/lib/arjdbc/jdbc.rb +5 -1
- data/lib/arjdbc/jdbc/adapter.rb +167 -89
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
- data/lib/arjdbc/jdbc/base_ext.rb +25 -3
- data/lib/arjdbc/jdbc/callbacks.rb +9 -8
- data/lib/arjdbc/jdbc/column.rb +8 -20
- data/lib/arjdbc/jdbc/connection.rb +69 -80
- data/lib/arjdbc/jdbc/extension.rb +6 -8
- data/lib/arjdbc/jdbc/jdbc.rake +3 -141
- data/lib/arjdbc/jdbc/rake_tasks.rb +3 -10
- data/lib/arjdbc/mssql/adapter.rb +108 -34
- data/lib/arjdbc/mssql/connection_methods.rb +3 -1
- data/lib/arjdbc/mssql/limit_helpers.rb +3 -2
- data/lib/arjdbc/mssql/lock_helpers.rb +5 -1
- data/lib/arjdbc/mysql/adapter.rb +127 -70
- data/lib/arjdbc/mysql/connection_methods.rb +5 -2
- data/lib/arjdbc/oracle/adapter.rb +124 -94
- data/lib/arjdbc/oracle/connection_methods.rb +2 -1
- data/lib/arjdbc/postgresql/adapter.rb +99 -67
- data/lib/arjdbc/postgresql/column_cast.rb +3 -5
- data/lib/arjdbc/postgresql/connection_methods.rb +6 -6
- data/lib/arjdbc/railtie.rb +3 -1
- data/lib/arjdbc/sqlite3/adapter.rb +60 -43
- data/lib/arjdbc/sqlite3/connection_methods.rb +9 -9
- data/lib/arjdbc/sybase.rb +1 -1
- data/lib/arjdbc/tasks.rb +13 -0
- data/lib/arjdbc/tasks/database_tasks.rb +50 -0
- data/lib/arjdbc/tasks/databases.rake +89 -0
- data/lib/arjdbc/tasks/databases3.rake +203 -0
- data/lib/arjdbc/tasks/databases4.rake +39 -0
- data/lib/arjdbc/tasks/db2_database_tasks.rb +104 -0
- data/lib/arjdbc/tasks/derby_database_tasks.rb +95 -0
- data/lib/arjdbc/tasks/h2_database_tasks.rb +29 -0
- data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
- data/lib/arjdbc/tasks/jdbc_database_tasks.rb +122 -0
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +36 -0
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +297 -0
- data/lib/arjdbc/tasks/oracle_database_tasks.rb +62 -0
- data/lib/arjdbc/version.rb +1 -1
- data/pom.xml +11 -12
- data/rails_generators/jdbc_generator.rb +1 -1
- data/rails_generators/templates/config/initializers/jdbc.rb +8 -5
- data/rails_generators/templates/lib/tasks/jdbc.rake +7 -4
- data/rakelib/02-test.rake +42 -15
- data/rakelib/compile.rake +29 -2
- data/rakelib/db.rake +2 -1
- data/rakelib/rails.rake +23 -6
- data/src/java/arjdbc/ArJdbcModule.java +175 -0
- data/src/java/arjdbc/db2/DB2Module.java +2 -1
- data/src/java/arjdbc/derby/DerbyModule.java +5 -24
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +3 -2
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +3 -46
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1001 -259
- data/src/java/arjdbc/mssql/MSSQLModule.java +2 -1
- data/src/java/arjdbc/mysql/MySQLModule.java +4 -3
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +12 -7
- data/src/java/arjdbc/oracle/OracleModule.java +2 -1
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +2 -1
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +12 -0
- data/test/db/db2.rb +14 -7
- data/test/db/db2/rake_test.rb +82 -0
- data/test/db/db2/rake_test_data.sql +35 -0
- data/test/db/db2/simple_test.rb +20 -0
- data/test/db/db2/unit_test.rb +3 -1
- data/test/db/derby.rb +7 -5
- data/test/db/derby/rake_test.rb +96 -0
- data/test/db/derby/simple_test.rb +10 -2
- data/test/db/h2.rb +6 -8
- data/test/db/h2/identity_column_test.rb +35 -0
- data/test/db/h2/offset_test.rb +49 -0
- data/test/db/h2/rake_test.rb +98 -0
- data/test/db/h2/schema_dump_test.rb +5 -1
- data/test/db/hsqldb.rb +6 -10
- data/test/db/hsqldb/rake_test.rb +101 -0
- data/test/db/hsqldb/schema_dump_test.rb +5 -1
- data/test/db/hsqldb/simple_test.rb +8 -0
- data/test/db/jndi_config.rb +1 -3
- data/test/db/jndi_pooled_config.rb +1 -3
- data/test/db/mssql/limit_offset_test.rb +23 -14
- data/test/db/mssql/rake_test.rb +143 -0
- data/test/db/mysql/_rails_test_mysql.32.out +1069 -1252
- data/test/db/mysql/nonstandard_primary_key_test.rb +21 -24
- data/test/db/mysql/rake_test.rb +97 -0
- data/test/db/mysql/schema_dump_test.rb +11 -11
- data/test/db/mysql/simple_test.rb +52 -3
- data/test/db/mysql/statement_escaping_test.rb +46 -0
- data/test/db/oracle/rake_test.rb +100 -0
- data/test/db/oracle/simple_test.rb +48 -0
- data/test/db/postgres/_rails_test_postgres.32.out +998 -1370
- data/test/db/postgres/active_schema_unit_test.rb +68 -0
- data/test/db/postgres/connection_test.rb +10 -2
- data/test/db/postgres/data_types_test.rb +2 -2
- data/test/db/postgres/ltree_test.rb +6 -5
- data/test/db/postgres/native_types_test.rb +1 -5
- data/test/db/postgres/rake_test.rb +117 -0
- data/test/db/postgres/schema_dump_test.rb +9 -2
- data/test/db/postgres/schema_test.rb +4 -2
- data/test/db/postgres/simple_test.rb +57 -16
- data/test/db/sqlite3.rb +3 -10
- data/test/db/sqlite3/_rails_test_sqlite3.32.out +1070 -1298
- data/test/db/sqlite3/rake_test.rb +71 -0
- data/test/db/sqlite3/simple_test.rb +9 -9
- data/test/has_many_through.rb +4 -1
- data/test/jdbc/db2.rb +14 -1
- data/test/jdbc_column_test.rb +23 -0
- data/test/{generic_jdbc_connection_test.rb → jdbc_connection_test.rb} +22 -17
- data/test/jndi_callbacks_test.rb +26 -28
- data/test/jndi_test.rb +7 -16
- data/test/models/data_types.rb +2 -1
- data/test/models/thing.rb +1 -0
- data/test/rails/mysql.rb +13 -0
- data/test/rails/sqlite3/version.rb +6 -0
- data/test/rails_stub.rb +31 -0
- data/test/rake_test_support.rb +298 -0
- data/test/serialize.rb +2 -4
- data/test/{helper.rb → shared_helper.rb} +0 -0
- data/test/simple.rb +167 -93
- data/test/test_helper.rb +52 -16
- metadata +388 -354
- data/lib/pg.rb +0 -26
- data/test/abstract_db_create.rb +0 -139
- data/test/activerecord/connection_adapters/type_conversion_test.rb +0 -36
- data/test/db/mssql/db_create_test.rb +0 -29
- data/test/db/mysql/db_create_test.rb +0 -33
- data/test/db/postgres/db_create_test.rb +0 -44
- data/test/db/postgres/db_drop_test.rb +0 -17
data/test/db/h2.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
config = {
|
4
|
-
:adapter => 'h2',
|
5
|
-
:database => 'test.db'
|
6
|
-
}
|
3
|
+
config = { :adapter => 'h2', :database => 'test' } # adds .h2.db suffix
|
7
4
|
|
8
5
|
ActiveRecord::Base.establish_connection(config)
|
9
6
|
|
10
|
-
at_exit
|
11
|
-
|
12
|
-
Dir['test.db
|
13
|
-
}
|
7
|
+
at_exit do
|
8
|
+
Dir['*test.h2.db'].each { |f| FileUtils.rm(f) }
|
9
|
+
Dir['*test.lock.db'].each { |f| FileUtils.rm(f) }
|
10
|
+
Dir['*test.trace.db'].each { |f| FileUtils.rm(f) }
|
11
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'db/h2'
|
3
|
+
|
4
|
+
class H2IdentityColumnTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class Persona < ActiveRecord::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
class CreatePersonasTable < ActiveRecord::Migration
|
10
|
+
def self.up
|
11
|
+
create_table :personas do |t|
|
12
|
+
t.string :firstname
|
13
|
+
t.string :lastname
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.down
|
18
|
+
drop_table :personas
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup
|
23
|
+
CreatePersonasTable.up
|
24
|
+
Persona.create(:firstname => "John", :lastname => "Smith")
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
CreatePersonasTable.down
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_auto_increment
|
32
|
+
assert_equal 1, Persona.all[0].id, "H2 auto increment initially should start at ID 1, not 0"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'db/h2'
|
3
|
+
|
4
|
+
class H2OffsetTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class Persona < ActiveRecord::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
class CreatePersonasTable < ActiveRecord::Migration
|
10
|
+
def self.up
|
11
|
+
create_table :personas do |t|
|
12
|
+
t.string :firstname
|
13
|
+
t.string :lastname
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.down
|
18
|
+
drop_table :personas
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup
|
23
|
+
CreatePersonasTable.up
|
24
|
+
Persona.create(:firstname => "John", :lastname => "Smith")
|
25
|
+
Persona.create(:firstname => "Jill", :lastname => "Smith")
|
26
|
+
Persona.create(:firstname => "Joan", :lastname => "Smith")
|
27
|
+
Persona.create(:firstname => "Jason", :lastname => "Smith")
|
28
|
+
Persona.create(:firstname => "Jack", :lastname => "Smith")
|
29
|
+
Persona.create(:firstname => "Jenssen", :lastname => "Smith")
|
30
|
+
Persona.create(:firstname => "Joe", :lastname => "Smith")
|
31
|
+
Persona.create(:firstname => "Johanna", :lastname => "Smith")
|
32
|
+
Persona.create(:firstname => "James", :lastname => "Smith")
|
33
|
+
Persona.create(:firstname => "Jim", :lastname => "Smith")
|
34
|
+
Persona.create(:firstname => "Jody", :lastname => "Smith")
|
35
|
+
end
|
36
|
+
|
37
|
+
def teardown
|
38
|
+
CreatePersonasTable.down
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_offset
|
42
|
+
query = Arel::Table.new(:persons).skip(3)
|
43
|
+
assert_nothing_raised do
|
44
|
+
sql = query.to_sql
|
45
|
+
assert_equal "SELECT LIMIT 3", sql[0..13], "SQL statement was not generated, properly"
|
46
|
+
end
|
47
|
+
end if ar_version('3.0')
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'rake_test_support'
|
2
|
+
require 'db/h2'
|
3
|
+
|
4
|
+
class H2RakeTest < Test::Unit::TestCase
|
5
|
+
include RakeTestSupport
|
6
|
+
|
7
|
+
def db_name; 'mem:rake-test'; end
|
8
|
+
|
9
|
+
def do_teardown
|
10
|
+
drop_rake_test_database(:silence)
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'rake db:create (and db:drop)' do
|
14
|
+
@db_name = 'rake-create-test'
|
15
|
+
Rake::Task["db:create"].invoke
|
16
|
+
assert_true File.exists?("#{@db_name}.h2.db"), "db file: #{@db_name}.h2.db is missing"
|
17
|
+
|
18
|
+
Rake::Task["db:drop"].invoke
|
19
|
+
assert_false File.exists?("#{@db_name}.h2.db"), "db file: #{@db_name}.h2.db not deleted"
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'rake db:create (and db:drop) in memory db' do
|
23
|
+
Rake::Task["db:create"].invoke
|
24
|
+
# assert_true File.exists?("#{db_name}.lck")
|
25
|
+
|
26
|
+
Rake::Task["db:drop"].invoke
|
27
|
+
# assert_false File.exists?("#{db_name}.lck")
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'rake db:test:purge' do
|
31
|
+
# Rake::Task["db:create"].invoke
|
32
|
+
create_rake_test_database do |connection|
|
33
|
+
connection.create_table('loosers') { |t| t.string :name }
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::Task["db:test:purge"].invoke
|
37
|
+
|
38
|
+
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
39
|
+
assert_false ActiveRecord::Base.connection.table_exists?('loosers')
|
40
|
+
ActiveRecord::Base.connection.disconnect!
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'rake db:structure:dump (and db:structure:load)' do
|
44
|
+
db_name = @db_name = 'test-dump-rake'
|
45
|
+
create_rake_test_database(db_name) do |connection|
|
46
|
+
create_schema_migrations_table(connection)
|
47
|
+
connection.create_table('loosers') { |t| t.string :name; t.timestamps }
|
48
|
+
end
|
49
|
+
|
50
|
+
structure_sql = File.join('db', structure_sql_filename)
|
51
|
+
begin
|
52
|
+
Dir.mkdir 'db' # db/structure.sql
|
53
|
+
Rake::Task["db:structure:dump"].invoke
|
54
|
+
|
55
|
+
assert File.exists?(structure_sql)
|
56
|
+
# CREATE CACHED TABLE PUBLIC.LOOSERS
|
57
|
+
assert_match /CREATE .*? TABLE PUBLIC.LOOSERS/i, File.read(structure_sql)
|
58
|
+
|
59
|
+
# db:structure:load
|
60
|
+
drop_rake_test_database(:silence)
|
61
|
+
Rake::Task["db:structure:load"].invoke
|
62
|
+
|
63
|
+
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
64
|
+
assert ActiveRecord::Base.connection.table_exists?('loosers')
|
65
|
+
ActiveRecord::Base.connection.disconnect!
|
66
|
+
ensure
|
67
|
+
File.delete(structure_sql) if File.exists?(structure_sql)
|
68
|
+
Dir.rmdir 'db'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# test 'rake db:charset' do
|
73
|
+
# expect_rake_output('UTF-8')
|
74
|
+
# Rake::Task["db:charset"].invoke
|
75
|
+
# end
|
76
|
+
|
77
|
+
def create_rake_test_database(db_name = self.db_name)
|
78
|
+
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
79
|
+
if block_given?
|
80
|
+
yield ActiveRecord::Base.connection
|
81
|
+
end
|
82
|
+
ActiveRecord::Base.connection.disconnect!
|
83
|
+
end
|
84
|
+
|
85
|
+
def drop_rake_test_database(silence = nil)
|
86
|
+
# ActiveRecord::Base.establish_connection db_config.merge :database => @db_name
|
87
|
+
# ActiveRecord::Base.connection.disconnect!
|
88
|
+
|
89
|
+
File.delete("#{@db_name}.lock.db") if File.exist? "#{@db_name}.lock.db"
|
90
|
+
File.delete("#{@db_name}.trace.db") if File.exist? "#{@db_name}.trace.db"
|
91
|
+
if silence
|
92
|
+
File.delete("#{@db_name}.h2.db") if File.exist? "#{@db_name}.h2.db"
|
93
|
+
else
|
94
|
+
File.delete("#{@db_name}.h2.db")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -19,7 +19,11 @@ class H2SchemaDumpTest < Test::Unit::TestCase
|
|
19
19
|
def test_schema_dump_decimal_when_scale_specified
|
20
20
|
output = standard_dump(StringIO.new, [/^[^d]/]) # keep db_types
|
21
21
|
# t.column :sample_small_decimal, :decimal, :precision => 3, :scale => 2, :default => 3.14
|
22
|
-
|
22
|
+
if ar_version('4.0')
|
23
|
+
assert_match %r{t.decimal\s+"sample_small_decimal",\s+precision: 3,\s+scale: 2}, output
|
24
|
+
else
|
25
|
+
assert_match %r{t.decimal\s+"sample_small_decimal",\s+:precision => 3,\s+:scale => 2}, output
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
29
|
end
|
data/test/db/hsqldb.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
config = {
|
4
|
-
:adapter => 'hsqldb',
|
5
|
-
:database => 'test.db'
|
6
|
-
}
|
3
|
+
config = { :adapter => 'hsqldb', :database => 'test.hsqldb' }
|
7
4
|
|
8
5
|
ActiveRecord::Base.establish_connection(config)
|
9
6
|
|
10
|
-
at_exit
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
7
|
+
at_exit do
|
8
|
+
Dir['*test.hsqldb*'].each do |f|
|
9
|
+
FileUtils.rm_rf(f); File.delete(f) if File.exist?(f)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'rake_test_support'
|
2
|
+
require 'db/hsqldb'
|
3
|
+
|
4
|
+
class HSQLDBRakeTest < Test::Unit::TestCase
|
5
|
+
include RakeTestSupport
|
6
|
+
|
7
|
+
def db_name; 'mem:rake-test.hsqldb'; end
|
8
|
+
|
9
|
+
def do_teardown
|
10
|
+
drop_rake_test_database
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'rake db:create (and db:drop)' do
|
14
|
+
@db_name = 'rake-create-test.hsqldb'
|
15
|
+
Rake::Task["db:create"].invoke
|
16
|
+
assert_true File.exists?("#{@db_name}.lck")
|
17
|
+
|
18
|
+
Rake::Task["db:drop"].invoke
|
19
|
+
assert_false File.exists?("#{@db_name}.lck")
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'rake db:create (and db:drop) in memory db' do
|
23
|
+
Rake::Task["db:create"].invoke
|
24
|
+
# assert_true File.exists?("#{db_name}.lck")
|
25
|
+
|
26
|
+
Rake::Task["db:drop"].invoke
|
27
|
+
# assert_false File.exists?("#{db_name}.lck")
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'rake db:test:purge' do
|
31
|
+
# Rake::Task["db:create"].invoke
|
32
|
+
create_rake_test_database do |connection|
|
33
|
+
connection.create_table('loosers') { |t| t.string :name }
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::Task["db:test:purge"].invoke
|
37
|
+
|
38
|
+
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
39
|
+
assert_false ActiveRecord::Base.connection.table_exists?('loosers')
|
40
|
+
ActiveRecord::Base.connection.disconnect!
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'rake db:structure:dump (and db:structure:load)' do
|
44
|
+
db_name = @db_name = 'test-dump-rake.hsqldb'
|
45
|
+
create_rake_test_database(db_name) do |connection|
|
46
|
+
create_schema_migrations_table(connection)
|
47
|
+
connection.create_table('loosers') { |t| t.string :name; t.timestamps }
|
48
|
+
end
|
49
|
+
|
50
|
+
structure_sql = File.join('db', structure_sql_filename)
|
51
|
+
begin
|
52
|
+
Dir.mkdir 'db' # db/structure.sql
|
53
|
+
Rake::Task["db:structure:dump"].invoke
|
54
|
+
|
55
|
+
assert File.exists?(structure_sql)
|
56
|
+
# CREATE MEMORY TABLE PUBLIC.LOOSERS
|
57
|
+
assert_match /CREATE .*? TABLE PUBLIC.LOOSERS/i, File.read(structure_sql)
|
58
|
+
|
59
|
+
# db:structure:load
|
60
|
+
drop_rake_test_database(:silence)
|
61
|
+
Rake::Task["db:structure:load"].invoke
|
62
|
+
|
63
|
+
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
64
|
+
assert ActiveRecord::Base.connection.table_exists?('loosers')
|
65
|
+
ActiveRecord::Base.connection.disconnect!
|
66
|
+
ensure
|
67
|
+
File.delete(structure_sql) if File.exists?(structure_sql)
|
68
|
+
Dir.rmdir 'db'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# test 'rake db:charset' do
|
73
|
+
# expect_rake_output('UTF-8')
|
74
|
+
# Rake::Task["db:charset"].invoke
|
75
|
+
# end
|
76
|
+
|
77
|
+
def create_rake_test_database(db_name = self.db_name)
|
78
|
+
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
79
|
+
if block_given?
|
80
|
+
yield ActiveRecord::Base.connection
|
81
|
+
end
|
82
|
+
ActiveRecord::Base.connection.shutdown
|
83
|
+
ActiveRecord::Base.connection.disconnect!
|
84
|
+
end
|
85
|
+
|
86
|
+
def drop_rake_test_database(silence = nil)
|
87
|
+
ActiveRecord::Base.establish_connection db_config.merge :database => @db_name
|
88
|
+
ActiveRecord::Base.connection.shutdown
|
89
|
+
ActiveRecord::Base.connection.disconnect!
|
90
|
+
|
91
|
+
Dir.glob("#{@db_name}*").each do |f|
|
92
|
+
if silence
|
93
|
+
FileUtils.rm_rf(f) if File.exists?(f)
|
94
|
+
else
|
95
|
+
FileUtils.rm_rf(f)
|
96
|
+
end
|
97
|
+
FileUtils.rmdir(f) if File.directory?(f)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -9,7 +9,11 @@ class HSQLDBSchemaDumpTest < Test::Unit::TestCase
|
|
9
9
|
def test_schema_dump_decimal_when_scale_specified
|
10
10
|
output = standard_dump(StringIO.new, [/^[^d]/]) # keep db_types
|
11
11
|
# t.column :sample_small_decimal, :decimal, :precision => 3, :scale => 2, :default => 3.14
|
12
|
-
|
12
|
+
if ar_version('4.0')
|
13
|
+
assert_match %r{t.decimal\s+"sample_small_decimal",\s+precision: 3,\s+scale: 2}, output
|
14
|
+
else
|
15
|
+
assert_match %r{t.decimal\s+"sample_small_decimal",\s+:precision => 3,\s+:scale => 2}, output
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
end
|
@@ -6,4 +6,12 @@ class HsqldbSimpleTest < Test::Unit::TestCase
|
|
6
6
|
include ExplainSupportTestMethods if ar_version("3.1")
|
7
7
|
include ActiveRecord3TestMethods
|
8
8
|
include CustomSelectTestMethods
|
9
|
+
|
10
|
+
# @override
|
11
|
+
def test_empty_insert_statement
|
12
|
+
# "INSERT INTO table DEFAULT VALUES" only works if all columns have defaults
|
13
|
+
pend if ar_version('4.0')
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
9
17
|
end
|
data/test/db/jndi_config.rb
CHANGED
@@ -97,9 +97,9 @@ class MSSQLLimitOffsetTest < Test::Unit::TestCase
|
|
97
97
|
|
98
98
|
def test_limit_with_no_id_column_available
|
99
99
|
NoIdViking.create!(:name => 'Erik')
|
100
|
-
assert_nothing_raised(ActiveRecord::StatementInvalid) do
|
100
|
+
#assert_nothing_raised(ActiveRecord::StatementInvalid) do
|
101
101
|
NoIdViking.first
|
102
|
-
end
|
102
|
+
#end
|
103
103
|
end
|
104
104
|
|
105
105
|
def test_limit_with_alternate_named_primary_key
|
@@ -140,12 +140,15 @@ class MSSQLLimitOffsetTest < Test::Unit::TestCase
|
|
140
140
|
skei.vikings.create!(:name => "Bob")
|
141
141
|
skei.vikings.create!(:name => "Ben")
|
142
142
|
skei.vikings.create!(:name => "Basil")
|
143
|
-
|
143
|
+
if ar_version('4.0')
|
144
|
+
ships = Viking.includes(:long_ship).offset(1).limit(2) #.all
|
145
|
+
else
|
146
|
+
ships = Viking.find(:all, :include => :long_ship, :offset => 1, :limit => 2)
|
147
|
+
end
|
144
148
|
assert_equal(2, ships.size)
|
145
149
|
end
|
146
150
|
|
147
151
|
def test_limit_and_offset_with_include_and_order
|
148
|
-
|
149
152
|
boat1 = LongShip.create!(:name => "1-Skei")
|
150
153
|
boat2 = LongShip.create!(:name => "2-Skei")
|
151
154
|
|
@@ -153,29 +156,35 @@ class MSSQLLimitOffsetTest < Test::Unit::TestCase
|
|
153
156
|
boat2.vikings.create!(:name => "Ben")
|
154
157
|
boat1.vikings.create!(:name => "Carl")
|
155
158
|
boat2.vikings.create!(:name => "Donald")
|
156
|
-
|
157
|
-
vikings = Viking.find(:all, :include => :long_ship, :order => "long_ships.name, vikings.name", :offset => 0, :limit => 3)
|
158
|
-
assert_equal(["Adam", "Carl", "Ben"], vikings.map(&:name))
|
159
159
|
|
160
|
+
if ar_version('4.0')
|
161
|
+
vikings = Viking.includes(:long_ship).order('long_ships.name, vikings.name').references(:long_ship).offset(0).limit(3)
|
162
|
+
else
|
163
|
+
vikings = Viking.find(:all, :include => :long_ship, :order => "long_ships.name, vikings.name", :offset => 0, :limit => 3)
|
164
|
+
end
|
165
|
+
assert_equal ["Adam", "Carl", "Ben"], vikings.map(&:name)
|
160
166
|
end
|
161
167
|
|
162
168
|
def test_offset_without_limit
|
163
|
-
%w(
|
169
|
+
%w( egy keto harom negy ot hat het nyolc ).each do |name|
|
164
170
|
LongShip.create!(:name => name)
|
165
171
|
end
|
166
172
|
error = assert_raise ActiveRecord::ActiveRecordError do
|
167
|
-
|
173
|
+
if ar_version('3.0')
|
174
|
+
LongShip.select(:name).offset(2).all
|
175
|
+
else
|
176
|
+
LongShip.find(:all, :select => 'name', :offset => 2)
|
177
|
+
end
|
168
178
|
end
|
169
|
-
assert_equal
|
179
|
+
assert_equal "You must specify :limit with :offset.", error.message
|
170
180
|
end
|
171
181
|
|
172
182
|
def test_limit_with_group_by
|
173
|
-
%w(one two three four five six seven eight).each do |name|
|
183
|
+
%w( one two three four five six seven eight ).each do |name|
|
174
184
|
LongShip.create!(:name => name)
|
175
185
|
end
|
176
|
-
|
177
|
-
|
178
|
-
asset_equal(['one', 'two'], ships.map(&:name))
|
186
|
+
ships = LongShip.select(:name).group(:name).limit(2).all
|
187
|
+
assert_equal ['one', 'two'], ships.map(&:name)
|
179
188
|
end if ar_version('3.0')
|
180
189
|
|
181
190
|
end
|