c3-activerecord-jdbc-adapter 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +452 -0
- data/LICENSE.txt +21 -0
- data/Manifest.txt +194 -0
- data/README.txt +181 -0
- data/Rakefile +10 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/teradata_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +8 -0
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
- data/lib/arel/visitors/compat.rb +13 -0
- data/lib/arel/visitors/db2.rb +17 -0
- data/lib/arel/visitors/derby.rb +21 -0
- data/lib/arel/visitors/firebird.rb +17 -0
- data/lib/arel/visitors/hsqldb.rb +26 -0
- data/lib/arel/visitors/sql_server.rb +44 -0
- data/lib/arjdbc.rb +29 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/arjdbc/db2/adapter.rb +421 -0
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/arjdbc/derby/adapter.rb +352 -0
- data/lib/arjdbc/derby/connection_methods.rb +18 -0
- data/lib/arjdbc/discover.rb +99 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/arjdbc/firebird/adapter.rb +136 -0
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +36 -0
- data/lib/arjdbc/h2/connection_methods.rb +12 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/arjdbc/hsqldb/adapter.rb +182 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/arjdbc/informix/adapter.rb +138 -0
- data/lib/arjdbc/informix/connection_methods.rb +10 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +283 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +47 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +130 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
- data/lib/arjdbc/jdbc/core_ext.rb +24 -0
- data/lib/arjdbc/jdbc/discover.rb +18 -0
- data/lib/arjdbc/jdbc/driver.rb +35 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/arjdbc/jdbc/jdbc.rake +131 -0
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +87 -0
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/arjdbc/jdbc/railtie.rb +9 -0
- data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +126 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/arjdbc/mimer/adapter.rb +142 -0
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mssql/adapter.rb +472 -0
- data/lib/arjdbc/mssql/connection_methods.rb +30 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +98 -0
- data/lib/arjdbc/mssql/tsql_helper.rb +61 -0
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +425 -0
- data/lib/arjdbc/mysql/connection_methods.rb +27 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/arjdbc/oracle/adapter.rb +418 -0
- data/lib/arjdbc/oracle/connection_methods.rb +11 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/arjdbc/postgresql/adapter.rb +598 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/arjdbc/sqlite3/adapter.rb +381 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +34 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +46 -0
- data/lib/arjdbc/teradata.rb +3 -0
- data/lib/arjdbc/teradata/adapter.rb +81 -0
- data/lib/arjdbc/teradata/connection_methods.rb +11 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/jdbc_generator.rb +9 -0
- data/lib/jdbc_adapter.rb +2 -0
- data/lib/jdbc_adapter/rake_tasks.rb +3 -0
- data/lib/jdbc_adapter/version.rb +3 -0
- data/lib/pg.rb +26 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
- data/rakelib/compile.rake +25 -0
- data/rakelib/db.rake +19 -0
- data/rakelib/package.rake +92 -0
- data/rakelib/rails.rake +41 -0
- data/rakelib/test.rake +81 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +62 -0
- data/src/java/arjdbc/derby/DerbyModule.java +322 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +74 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +70 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +36 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1328 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +134 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +87 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +57 -0
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
- data/src/java/arjdbc/teradata/TeradataRubyJdbcConnection.java +62 -0
- data/test/abstract_db_create.rb +128 -0
- data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
- data/test/db/db2.rb +11 -0
- data/test/db/derby.rb +12 -0
- data/test/db/h2.rb +11 -0
- data/test/db/hsqldb.rb +13 -0
- data/test/db/informix.rb +11 -0
- data/test/db/jdbc.rb +11 -0
- data/test/db/jndi_config.rb +40 -0
- data/test/db/logger.rb +3 -0
- data/test/db/mssql.rb +9 -0
- data/test/db/mysql.rb +10 -0
- data/test/db/oracle.rb +34 -0
- data/test/db/postgres.rb +9 -0
- data/test/db/sqlite3.rb +11 -0
- data/test/db2_simple_test.rb +66 -0
- data/test/derby_migration_test.rb +68 -0
- data/test/derby_multibyte_test.rb +12 -0
- data/test/derby_simple_test.rb +99 -0
- data/test/generic_jdbc_connection_test.rb +29 -0
- data/test/h2_simple_test.rb +41 -0
- data/test/has_many_through.rb +79 -0
- data/test/helper.rb +5 -0
- data/test/hsqldb_simple_test.rb +6 -0
- data/test/informix_simple_test.rb +48 -0
- data/test/jdbc_common.rb +25 -0
- data/test/jndi_callbacks_test.rb +40 -0
- data/test/jndi_test.rb +25 -0
- data/test/manualTestDatabase.rb +191 -0
- data/test/models/add_not_null_column_to_table.rb +9 -0
- data/test/models/auto_id.rb +15 -0
- data/test/models/data_types.rb +30 -0
- data/test/models/entry.rb +40 -0
- data/test/models/mixed_case.rb +22 -0
- data/test/models/reserved_word.rb +15 -0
- data/test/models/string_id.rb +15 -0
- data/test/models/validates_uniqueness_of_string.rb +19 -0
- data/test/mssql_db_create_test.rb +26 -0
- data/test/mssql_identity_insert_test.rb +19 -0
- data/test/mssql_legacy_types_test.rb +58 -0
- data/test/mssql_limit_offset_test.rb +136 -0
- data/test/mssql_multibyte_test.rb +18 -0
- data/test/mssql_simple_test.rb +55 -0
- data/test/mysql_db_create_test.rb +27 -0
- data/test/mysql_info_test.rb +123 -0
- data/test/mysql_multibyte_test.rb +10 -0
- data/test/mysql_nonstandard_primary_key_test.rb +42 -0
- data/test/mysql_simple_test.rb +49 -0
- data/test/oracle_simple_test.rb +18 -0
- data/test/oracle_specific_test.rb +83 -0
- data/test/pick_rails_version.rb +3 -0
- data/test/postgres_db_create_test.rb +32 -0
- data/test/postgres_drop_db_test.rb +16 -0
- data/test/postgres_information_schema_leak_test.rb +29 -0
- data/test/postgres_mixed_case_test.rb +29 -0
- data/test/postgres_native_type_mapping_test.rb +84 -0
- data/test/postgres_nonseq_pkey_test.rb +38 -0
- data/test/postgres_reserved_test.rb +22 -0
- data/test/postgres_schema_search_path_test.rb +48 -0
- data/test/postgres_simple_test.rb +90 -0
- data/test/postgres_table_alias_length_test.rb +15 -0
- data/test/simple.rb +557 -0
- data/test/sqlite3_simple_test.rb +233 -0
- data/test/sybase_jtds_simple_test.rb +28 -0
- metadata +273 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'models/entry'
|
3
|
+
require 'models/mixed_case'
|
4
|
+
|
5
|
+
class MixedCaseTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Migration::MixedCase.up
|
8
|
+
@table_name = User.table_name
|
9
|
+
User.table_name = 'tblUsers'
|
10
|
+
User.reset_column_information
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
User.table_name = @table_name
|
15
|
+
User.reset_column_information
|
16
|
+
Migration::MixedCase.down
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_create
|
20
|
+
mixed_case = MixedCase.create :SOME_value => 'some value'
|
21
|
+
assert_equal 'some value', mixed_case.SOME_value
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_find_mixed_table_name
|
25
|
+
User.create :firstName => "Nick", :lastName => "Sieger"
|
26
|
+
u = User.find :first
|
27
|
+
assert_equal "Nick Sieger", "#{u.firstName} #{u.lastName}"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'db/postgres'
|
3
|
+
|
4
|
+
class CreateNativeTypeMappingTestSchema < ActiveRecord::Migration
|
5
|
+
def self.up
|
6
|
+
execute "DROP SEQUENCE IF EXISTS seq_pk_customers"
|
7
|
+
execute "CREATE SEQUENCE seq_pk_customers"
|
8
|
+
execute %q{
|
9
|
+
CREATE TABLE customers (
|
10
|
+
bigint_serial_should_be_integer bigint default nextval('seq_pk_customers'),
|
11
|
+
integer_serial_should_be_integer integer default nextval('seq_pk_customers'),
|
12
|
+
varchar_should_be_string varchar(2),
|
13
|
+
timestamp_should_be_datetime timestamp,
|
14
|
+
bytea_should_be_binary bytea,
|
15
|
+
double_precision_should_be_float double precision,
|
16
|
+
real_should_be_float real,
|
17
|
+
bool_should_be_boolean bool,
|
18
|
+
interval_should_be_string interval,
|
19
|
+
bigint_should_be_integer bigint
|
20
|
+
)}
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.down
|
24
|
+
execute "DROP TABLE customers"
|
25
|
+
execute "DROP SEQUENCE IF EXISTS seq_pk_customers"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Customer < ActiveRecord::Base
|
30
|
+
end
|
31
|
+
|
32
|
+
class PostgresNativeTypeMappingTest < Test::Unit::TestCase
|
33
|
+
def setup
|
34
|
+
CreateNativeTypeMappingTestSchema.up
|
35
|
+
end
|
36
|
+
|
37
|
+
def teardown
|
38
|
+
CreateNativeTypeMappingTestSchema.down
|
39
|
+
end
|
40
|
+
|
41
|
+
def column_type(column_name)
|
42
|
+
Customer.columns.detect { |c| c.name == column_name }.type
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_bigint_serial_should_be_mapped_to_integer
|
46
|
+
assert_equal :integer, column_type("bigint_serial_should_be_integer")
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_integer_serial_should_be_mapped_to_integer
|
50
|
+
assert_equal :integer, column_type("integer_serial_should_be_integer")
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_varchar_should_be_mapped_to_string
|
54
|
+
assert_equal :string, column_type("varchar_should_be_string")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_timestamp_should_be_mapped_to_datetime
|
58
|
+
assert_equal :datetime, column_type("timestamp_should_be_datetime")
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_bytea_should_be_mapped_to_binary
|
62
|
+
assert_equal :binary, column_type("bytea_should_be_binary")
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_double_precision_should_be_mapped_to_float
|
66
|
+
assert_equal :float, column_type("double_precision_should_be_float")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_real_should_be_mapped_to_float
|
70
|
+
assert_equal :float, column_type("real_should_be_float")
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_bool_should_be_mapped_to_boolean
|
74
|
+
assert_equal :boolean, column_type("bool_should_be_boolean")
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_interval_should_be_mapped_to_string
|
78
|
+
assert_equal :string, column_type("interval_should_be_string")
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_bigint_should_be_mapped_to_integer
|
82
|
+
assert_equal :integer, column_type("bigint_should_be_integer")
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'db/postgres'
|
3
|
+
|
4
|
+
class CreateUrls < ActiveRecord::Migration
|
5
|
+
def self.up
|
6
|
+
create_table 'urls', :id => false do |t|
|
7
|
+
t.text :uhash, :null => false
|
8
|
+
t.text :url, :null => false
|
9
|
+
end
|
10
|
+
execute "ALTER TABLE urls ADD PRIMARY KEY (uhash)"
|
11
|
+
end
|
12
|
+
def self.down
|
13
|
+
drop_table 'urls'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Url < ActiveRecord::Base
|
18
|
+
set_primary_key :uhash
|
19
|
+
#Shouldn't be needed: set_sequence_name nil
|
20
|
+
end
|
21
|
+
|
22
|
+
class PostgresNonSeqPKey < Test::Unit::TestCase
|
23
|
+
def setup
|
24
|
+
CreateUrls.up
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
CreateUrls.down
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create
|
32
|
+
url = Url.create! do |u|
|
33
|
+
u.uhash = 'uhash'
|
34
|
+
u.url = 'http://url'
|
35
|
+
end
|
36
|
+
assert_equal( 'uhash', url.uhash )
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'db/postgres'
|
3
|
+
require 'models/reserved_word'
|
4
|
+
|
5
|
+
class PostgresReservedWordsTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
CreateReservedWords.up
|
8
|
+
end
|
9
|
+
def teardown
|
10
|
+
CreateReservedWords.down
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_quote_reserved_word_column
|
14
|
+
columns = ReservedWord.column_names - ["id"]
|
15
|
+
ReservedWord.connection.add_index :reserved_words, columns
|
16
|
+
indexes = ReservedWord.connection.indexes("reserved_words")
|
17
|
+
assert_equal 1, indexes.size
|
18
|
+
columns.each do |c|
|
19
|
+
assert indexes[0].columns.include?(c), "#{indexes[0].columns.inspect} does not include #{c.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'db/postgres'
|
3
|
+
|
4
|
+
class CreateSchema < ActiveRecord::Migration
|
5
|
+
def self.up
|
6
|
+
execute "CREATE SCHEMA test"
|
7
|
+
execute "CREATE TABLE test.people (id serial, name text)"
|
8
|
+
execute "INSERT INTO test.people (name) VALUES ('Alex')"
|
9
|
+
execute "CREATE TABLE public.people (id serial, wrongname text)"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
execute "DROP SCHEMA test CASCADE"
|
14
|
+
execute "DROP TABLE people"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Person < ActiveRecord::Base
|
19
|
+
establish_connection POSTGRES_CONFIG.merge(:schema_search_path => 'test,public')
|
20
|
+
end
|
21
|
+
|
22
|
+
class PostgresSchemaSearchPathTest < Test::Unit::TestCase
|
23
|
+
def setup
|
24
|
+
CreateSchema.up
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
CreateSchema.down
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_columns
|
32
|
+
assert_equal(%w{id name}, Person.column_names)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_find_right
|
36
|
+
assert_not_nil Person.find_by_name("Alex")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_find_wrong
|
40
|
+
assert_raise NoMethodError do
|
41
|
+
Person.find_by_wrongname("Alex")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
def test_column_information
|
45
|
+
assert Person.columns.map{|col| col.name}.include?("name")
|
46
|
+
assert !Person.columns.map{|col| col.name}.include?("wrongname")
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# To run this script, set up the following postgres user and database:
|
2
|
+
#
|
3
|
+
# sudo -u postgres createuser -D -A -P blog
|
4
|
+
# sudo -u postgres createdb -O blog weblog_development
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'jdbc_common'
|
8
|
+
require 'db/postgres'
|
9
|
+
|
10
|
+
class PostgresSimpleTest < Test::Unit::TestCase
|
11
|
+
include SimpleTestMethods
|
12
|
+
include ActiveRecord3TestMethods
|
13
|
+
|
14
|
+
def test_multi_statement_support
|
15
|
+
results = @connection.execute "SELECT title from entries; SELECT login from users"
|
16
|
+
assert_equal 2, results.length
|
17
|
+
assert_equal ["title"], results[0].first.keys
|
18
|
+
assert_equal ["login"], results[1].first.keys
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class PostgresDeserializationTest < Test::Unit::TestCase
|
23
|
+
def setup
|
24
|
+
DbTypeMigration.up
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
DbTypeMigration.down
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_keep_float_precision
|
32
|
+
expected = DbType.create(:sample_float => 7.3)
|
33
|
+
actual = DbType.find(expected.id)
|
34
|
+
|
35
|
+
assert_equal expected.sample_float, actual.sample_float
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class PostgresSchemaDumperTest < Test::Unit::TestCase
|
40
|
+
def setup
|
41
|
+
DbTypeMigration.up
|
42
|
+
@connection = ActiveRecord::Base.connection
|
43
|
+
strio = StringIO.new
|
44
|
+
ActiveRecord::SchemaDumper::dump(ActiveRecord::Base.connection, strio)
|
45
|
+
@dump = strio.string
|
46
|
+
end
|
47
|
+
|
48
|
+
def teardown
|
49
|
+
DbTypeMigration.down
|
50
|
+
end
|
51
|
+
|
52
|
+
# http://kenai.com/jira/browse/ACTIVERECORD_JDBC-135
|
53
|
+
def test_schema_dump_should_not_have_limits_on_boolean
|
54
|
+
lines = @dump.grep(/boolean/)
|
55
|
+
assert !lines.empty?
|
56
|
+
lines.each {|line| assert line !~ /limit/ }
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def test_schema_dump_should_not_have_limits_on_binaries
|
61
|
+
lines = @dump.grep(/binary/)
|
62
|
+
assert !lines.empty?, 'no binary type definitions found'
|
63
|
+
lines.each {|line| assert line !~ /limit/, 'binary definition contains limit' }
|
64
|
+
end
|
65
|
+
|
66
|
+
# http://kenai.com/jira/browse/ACTIVERECORD_JDBC-139
|
67
|
+
def test_schema_dump_should_not_have_limits_on_text_or_date
|
68
|
+
lines = @dump.grep(/date|text/)
|
69
|
+
assert !lines.empty?
|
70
|
+
lines.each {|line| assert line !~ /limit/ }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_schema_dump_integer_with_no_limit_should_have_no_limit
|
74
|
+
lines = @dump.grep(/sample_integer_no_limit/)
|
75
|
+
assert !lines.empty?
|
76
|
+
lines.each {|line| assert line !~ /:limit/ }
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_schema_dump_integer_with_limit_2_should_have_limit_2
|
80
|
+
lines = @dump.grep(/sample_integer_with_limit_2/)
|
81
|
+
assert !lines.empty?
|
82
|
+
lines.each {|line| assert line =~ /limit => 2/ }
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_schema_dump_integer_with_limit_8_should_have_limit_8
|
86
|
+
lines = @dump.grep(/sample_integer_with_limit_8/)
|
87
|
+
assert !lines.empty?
|
88
|
+
lines.each {|line| assert line =~ /limit => 8/ }
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'jdbc_common'
|
2
|
+
require 'db/postgres'
|
3
|
+
|
4
|
+
class PostgresTableAliasLengthTest < Test::Unit::TestCase
|
5
|
+
def test_table_alias_length
|
6
|
+
result = ActiveRecord::Base.connection.select_one("SELECT 1 AS " + "a" * 2048)
|
7
|
+
|
8
|
+
actual_table_alias_length = result.keys.first.size
|
9
|
+
actual_table_alias_length = 0 if actual_table_alias_length == 2048
|
10
|
+
|
11
|
+
assert_equal(actual_table_alias_length,
|
12
|
+
ActiveRecord::Base.connection.table_alias_length)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
data/test/simple.rb
ADDED
@@ -0,0 +1,557 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
ActiveRecord::Schema.verbose = false
|
3
|
+
ActiveRecord::Base.time_zone_aware_attributes = true if ActiveRecord::Base.respond_to?(:time_zone_aware_attributes)
|
4
|
+
ActiveRecord::Base.default_timezone = :utc
|
5
|
+
#just a random zone, unlikely to be local, and not utc
|
6
|
+
Time.zone = 'Moscow' if Time.respond_to?(:zone)
|
7
|
+
|
8
|
+
module MigrationSetup
|
9
|
+
def setup
|
10
|
+
DbTypeMigration.up
|
11
|
+
CreateStringIds.up
|
12
|
+
CreateEntries.up
|
13
|
+
CreateUsers.up
|
14
|
+
CreateAutoIds.up
|
15
|
+
CreateValidatesUniquenessOf.up
|
16
|
+
|
17
|
+
@connection = ActiveRecord::Base.connection
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
DbTypeMigration.down
|
22
|
+
CreateStringIds.down
|
23
|
+
CreateEntries.down
|
24
|
+
CreateUsers.down
|
25
|
+
CreateAutoIds.down
|
26
|
+
CreateValidatesUniquenessOf.down
|
27
|
+
ActiveRecord::Base.clear_active_connections!
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module FixtureSetup
|
32
|
+
include MigrationSetup
|
33
|
+
def setup
|
34
|
+
super
|
35
|
+
@title = "First post!"
|
36
|
+
@content = "Hello from JRuby on Rails!"
|
37
|
+
@new_title = "First post updated title"
|
38
|
+
@rating = 205.76
|
39
|
+
@user = User.create :login=>"something"
|
40
|
+
@entry = Entry.create :title => @title, :content => @content, :rating => @rating, :user=>@user
|
41
|
+
DbType.create
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module SimpleTestMethods
|
46
|
+
include FixtureSetup
|
47
|
+
|
48
|
+
def test_entries_created
|
49
|
+
assert ActiveRecord::Base.connection.tables.find{|t| t =~ /^entries$/i}, "entries not created"
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_users_created
|
53
|
+
assert ActiveRecord::Base.connection.tables.find{|t| t =~ /^users$/i}, "users not created"
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_entries_empty
|
57
|
+
Entry.delete_all
|
58
|
+
assert_equal 0, Entry.count
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_find_with_string_slug
|
62
|
+
new_entry = Entry.create(:title => "Blah")
|
63
|
+
entry = Entry.find(new_entry.to_param)
|
64
|
+
assert_equal new_entry.id, entry.id
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_insert_returns_id
|
68
|
+
unless ActiveRecord::Base.connection.adapter_name =~ /oracle/i
|
69
|
+
value = ActiveRecord::Base.connection.insert("INSERT INTO entries (title, content, rating) VALUES('insert_title', 'some content', 1)")
|
70
|
+
assert !value.nil?
|
71
|
+
entry = Entry.find_by_title('insert_title')
|
72
|
+
assert_equal entry.id, value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_create_new_entry
|
77
|
+
Entry.delete_all
|
78
|
+
|
79
|
+
post = Entry.new
|
80
|
+
post.title = @title
|
81
|
+
post.content = @content
|
82
|
+
post.rating = @rating
|
83
|
+
post.save
|
84
|
+
|
85
|
+
assert_equal 1, Entry.count
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_create_partial_new_entry
|
89
|
+
new_entry = Entry.create(:title => "Blah")
|
90
|
+
new_entry2 = Entry.create(:title => "Bloh")
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_find_and_update_entry
|
94
|
+
post = Entry.find(:first)
|
95
|
+
assert_equal @title, post.title
|
96
|
+
assert_equal @content, post.content
|
97
|
+
assert_equal @rating, post.rating
|
98
|
+
|
99
|
+
post.title = @new_title
|
100
|
+
post.save
|
101
|
+
|
102
|
+
post = Entry.find(:first)
|
103
|
+
assert_equal @new_title, post.title
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_destroy_entry
|
107
|
+
prev_count = Entry.count
|
108
|
+
post = Entry.find(:first)
|
109
|
+
post.destroy
|
110
|
+
|
111
|
+
assert_equal prev_count - 1, Entry.count
|
112
|
+
end
|
113
|
+
|
114
|
+
if Entry.respond_to?(:limit)
|
115
|
+
def test_limit
|
116
|
+
Entry.limit(10).to_a
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_count_with_limit
|
120
|
+
assert_equal Entry.count, Entry.limit(10).count
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
if Time.respond_to?(:zone)
|
125
|
+
def test_save_time_with_utc
|
126
|
+
current_zone = Time.zone
|
127
|
+
default_zone = ActiveRecord::Base.default_timezone
|
128
|
+
ActiveRecord::Base.default_timezone = Time.zone = :utc
|
129
|
+
now = Time.now
|
130
|
+
my_time = Time.local now.year, now.month, now.day, now.hour, now.min, now.sec
|
131
|
+
m = DbType.create! :sample_datetime => my_time
|
132
|
+
m.reload
|
133
|
+
assert_equal my_time, m.sample_datetime
|
134
|
+
rescue
|
135
|
+
Time.zone = current_zone
|
136
|
+
ActiveRecord::Base.default_timezone = default_zone
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_save_time
|
140
|
+
t = Time.now
|
141
|
+
#precision will only be expected to the second.
|
142
|
+
time = Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec)
|
143
|
+
e = DbType.find(:first)
|
144
|
+
e.sample_datetime = time
|
145
|
+
e.save!
|
146
|
+
e = DbType.find(:first)
|
147
|
+
assert_equal time.in_time_zone, e.sample_datetime
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_save_date_time
|
151
|
+
t = Time.now
|
152
|
+
#precision will only be expected to the second.
|
153
|
+
time = Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec)
|
154
|
+
datetime = time.to_datetime
|
155
|
+
e = DbType.find(:first)
|
156
|
+
e.sample_datetime = datetime
|
157
|
+
e.save!
|
158
|
+
e = DbType.find(:first)
|
159
|
+
assert_equal time, e.sample_datetime.localtime
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_save_time_with_zone
|
163
|
+
t = Time.now
|
164
|
+
#precision will only be expected to the second.
|
165
|
+
original_time = Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec)
|
166
|
+
time = original_time.in_time_zone
|
167
|
+
e = DbType.find(:first)
|
168
|
+
e.sample_datetime = time
|
169
|
+
e.save!
|
170
|
+
e = DbType.find(:first)
|
171
|
+
assert_equal time, e.sample_datetime
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_save_float
|
176
|
+
e = DbType.find(:first)
|
177
|
+
e.sample_float = 12.0
|
178
|
+
e.save!
|
179
|
+
|
180
|
+
e = DbType.find(:first)
|
181
|
+
assert_equal(12.0, e.sample_float)
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_save_date
|
185
|
+
date = Date.new(2007)
|
186
|
+
e = DbType.find(:first)
|
187
|
+
e.sample_date = date
|
188
|
+
e.save!
|
189
|
+
e = DbType.find(:first)
|
190
|
+
if DbType.columns_hash["sample_date"].type == :datetime
|
191
|
+
# Oracle doesn't distinguish btw date/datetime
|
192
|
+
assert_equal date, e.sample_date.to_date
|
193
|
+
else
|
194
|
+
assert_equal date, e.sample_date
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_boolean
|
199
|
+
# An unset boolean should default to nil
|
200
|
+
e = DbType.find(:first)
|
201
|
+
assert_equal(nil, e.sample_boolean)
|
202
|
+
|
203
|
+
e.sample_boolean = true
|
204
|
+
e.save!
|
205
|
+
|
206
|
+
e = DbType.find(:first)
|
207
|
+
assert_equal(true, e.sample_boolean)
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_integer
|
211
|
+
# An unset boolean should default to nil
|
212
|
+
e = DbType.find(:first)
|
213
|
+
assert_equal(nil, e.sample_integer)
|
214
|
+
|
215
|
+
e.sample_integer = 10
|
216
|
+
e.save!
|
217
|
+
|
218
|
+
e = DbType.find(:first)
|
219
|
+
assert_equal(10, e.sample_integer)
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_text
|
223
|
+
# An unset boolean should default to nil
|
224
|
+
e = DbType.find(:first)
|
225
|
+
|
226
|
+
# Oracle adapter initializes all CLOB fields with empty_clob() function,
|
227
|
+
# so they all have a initial value of an empty string ''
|
228
|
+
assert_equal(nil, e.sample_text) unless ActiveRecord::Base.connection.adapter_name =~ /oracle/i
|
229
|
+
|
230
|
+
e.sample_text = "ooop"
|
231
|
+
e.save!
|
232
|
+
|
233
|
+
e = DbType.find(:first)
|
234
|
+
assert_equal("ooop", e.sample_text)
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_string
|
238
|
+
e = DbType.find(:first)
|
239
|
+
|
240
|
+
# An empty string is treated as a null value in Oracle: http://www.techonthenet.com/oracle/questions/empty_null.php
|
241
|
+
assert_equal('', e.sample_string) unless ActiveRecord::Base.connection.adapter_name =~ /oracle/i
|
242
|
+
e.sample_string = "ooop"
|
243
|
+
e.save!
|
244
|
+
|
245
|
+
e = DbType.find(:first)
|
246
|
+
assert_equal("ooop", e.sample_string)
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_save_binary
|
250
|
+
#string is 60_000 bytes
|
251
|
+
binary_string = "\000ABCDEFGHIJKLMNOPQRSTUVWXYZ'\001\003"*1#2_000
|
252
|
+
e = DbType.find(:first)
|
253
|
+
e.sample_binary = binary_string
|
254
|
+
e.save!
|
255
|
+
e = DbType.find(:first)
|
256
|
+
assert_equal binary_string, e.sample_binary
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_default_decimal_should_keep_fractional_part
|
260
|
+
expected = 7.3
|
261
|
+
actual = DbType.create(:sample_default_decimal => expected).sample_default_decimal
|
262
|
+
assert_equal expected, actual
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_negative_default_value
|
266
|
+
assert_equal -1, DbType.columns_hash['sample_integer_negative_default'].default
|
267
|
+
assert_equal -1, DbType.new.sample_integer_negative_default
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_indexes
|
271
|
+
# Only test indexes if we have implemented it for the particular adapter
|
272
|
+
if @connection.respond_to?(:indexes)
|
273
|
+
indexes = @connection.indexes(:entries)
|
274
|
+
assert_equal(0, indexes.size)
|
275
|
+
|
276
|
+
index_name = "entries_index"
|
277
|
+
@connection.add_index(:entries, :updated_on, :name => index_name)
|
278
|
+
|
279
|
+
indexes = @connection.indexes(:entries)
|
280
|
+
assert_equal(1, indexes.size)
|
281
|
+
assert_equal "entries", indexes.first.table.to_s
|
282
|
+
assert_equal index_name, indexes.first.name
|
283
|
+
assert !indexes.first.unique
|
284
|
+
assert_equal ["updated_on"], indexes.first.columns
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_dumping_schema
|
289
|
+
require 'active_record/schema_dumper'
|
290
|
+
@connection.add_index :entries, :title
|
291
|
+
StringIO.open do |io|
|
292
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, io)
|
293
|
+
assert_match(/add_index "entries",/, io.string)
|
294
|
+
end
|
295
|
+
@connection.remove_index :entries, :title
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_nil_values
|
300
|
+
test = AutoId.create('value' => '')
|
301
|
+
assert_nil AutoId.find(test.id).value
|
302
|
+
end
|
303
|
+
|
304
|
+
# These should make no difference, but might due to the wacky regexp SQL rewriting we do.
|
305
|
+
def test_save_value_containing_sql
|
306
|
+
e = DbType.first
|
307
|
+
e.save
|
308
|
+
|
309
|
+
e.sample_string = e.sample_text = "\n\nselect from nothing where id = 'foo'"
|
310
|
+
e.save
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_invalid
|
314
|
+
e = Entry.new(:title => @title, :content => @content, :rating => ' ')
|
315
|
+
assert e.valid?
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_reconnect
|
319
|
+
assert_equal 1, Entry.count
|
320
|
+
@connection.reconnect!
|
321
|
+
assert_equal 1, Entry.count
|
322
|
+
end
|
323
|
+
|
324
|
+
if jruby?
|
325
|
+
def test_connection_valid
|
326
|
+
assert_raises(ActiveRecord::JDBCError) do
|
327
|
+
@connection.raw_connection.with_connection_retry_guard do |c|
|
328
|
+
begin
|
329
|
+
stmt = c.createStatement
|
330
|
+
stmt.execute "bogus sql"
|
331
|
+
ensure
|
332
|
+
stmt.close rescue nil
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
class Animal < ActiveRecord::Base; end
|
339
|
+
|
340
|
+
# ENEBO: Is this really ar-jdbc-specific or a bug in our adapter?
|
341
|
+
def test_fetching_columns_for_nonexistent_table_should_raise
|
342
|
+
assert_raises(ActiveRecord::JDBCError) do
|
343
|
+
Animal.columns
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_disconnect
|
349
|
+
assert_equal 1, Entry.count
|
350
|
+
ActiveRecord::Base.clear_active_connections!
|
351
|
+
ActiveRecord::Base.connection_pool.disconnect! if ActiveRecord::Base.respond_to?(:connection_pool)
|
352
|
+
assert !ActiveRecord::Base.connected?
|
353
|
+
assert_equal 1, Entry.count
|
354
|
+
assert ActiveRecord::Base.connected?
|
355
|
+
end
|
356
|
+
|
357
|
+
def test_add_not_null_column_to_table
|
358
|
+
AddNotNullColumnToTable.up
|
359
|
+
AddNotNullColumnToTable.down
|
360
|
+
end
|
361
|
+
|
362
|
+
def test_add_null_column_with_default
|
363
|
+
Entry.connection.add_column :entries, :color, :string, :null => false, :default => "blue"
|
364
|
+
created_columns = Entry.connection.columns('entries')
|
365
|
+
|
366
|
+
color = created_columns.detect { |c| c.name == 'color' }
|
367
|
+
assert !color.null
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_add_null_column_with_no_default
|
371
|
+
# You must specify a default value with most databases
|
372
|
+
if ActiveRecord::Base.connection.adapter_name =~ /mysql/i
|
373
|
+
Entry.connection.add_column :entries, :color, :string, :null => false
|
374
|
+
created_columns = Entry.connection.columns('entries')
|
375
|
+
|
376
|
+
color = created_columns.detect { |c| c.name == 'color' }
|
377
|
+
assert !color.null
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_add_null_column_with_nil_default
|
382
|
+
# You must specify a default value with most databases
|
383
|
+
if ActiveRecord::Base.connection.adapter_name =~ /mysql/i
|
384
|
+
Entry.connection.add_column :entries, :color, :string, :null => false, :default => nil
|
385
|
+
created_columns = Entry.connection.columns('entries')
|
386
|
+
|
387
|
+
color = created_columns.detect { |c| c.name == 'color' }
|
388
|
+
assert !color.null
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
def test_validates_uniqueness_of_strings_case_sensitive
|
393
|
+
name_lower = ValidatesUniquenessOfString.new(:cs_string => "name", :ci_string => '1')
|
394
|
+
name_lower.save!
|
395
|
+
|
396
|
+
name_upper = ValidatesUniquenessOfString.new(:cs_string => "NAME", :ci_string => '2')
|
397
|
+
assert_nothing_raised do
|
398
|
+
name_upper.save!
|
399
|
+
end
|
400
|
+
|
401
|
+
name_lower_collision = ValidatesUniquenessOfString.new(:cs_string => "name", :ci_string => '3')
|
402
|
+
assert_raise ActiveRecord::RecordInvalid do
|
403
|
+
name_lower_collision.save!
|
404
|
+
end
|
405
|
+
|
406
|
+
name_upper_collision = ValidatesUniquenessOfString.new(:cs_string => "NAME", :ci_string => '4')
|
407
|
+
assert_raise ActiveRecord::RecordInvalid do
|
408
|
+
name_upper_collision.save!
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
def test_validates_uniqueness_of_strings_case_insensitive
|
413
|
+
name_lower = ValidatesUniquenessOfString.new(:cs_string => '1', :ci_string => "name")
|
414
|
+
name_lower.save!
|
415
|
+
|
416
|
+
name_upper = ValidatesUniquenessOfString.new(:cs_string => '2', :ci_string => "NAME")
|
417
|
+
assert_raise ActiveRecord::RecordInvalid do
|
418
|
+
name_upper.save!
|
419
|
+
end
|
420
|
+
|
421
|
+
name_lower_collision = ValidatesUniquenessOfString.new(:cs_string => '3', :ci_string => "name")
|
422
|
+
assert_raise ActiveRecord::RecordInvalid do
|
423
|
+
name_lower_collision.save!
|
424
|
+
end
|
425
|
+
|
426
|
+
alternate_name_upper = ValidatesUniquenessOfString.new(:cs_string => '4', :ci_string => "ALTERNATE_NAME")
|
427
|
+
assert_nothing_raised do
|
428
|
+
alternate_name_upper.save!
|
429
|
+
end
|
430
|
+
|
431
|
+
alternate_name_upper_collision = ValidatesUniquenessOfString.new(:cs_string => '5', :ci_string => "ALTERNATE_NAME")
|
432
|
+
assert_raise ActiveRecord::RecordInvalid do
|
433
|
+
alternate_name_upper_collision.save!
|
434
|
+
end
|
435
|
+
|
436
|
+
alternate_name_lower = ValidatesUniquenessOfString.new(:cs_string => '6', :ci_string => "alternate_name")
|
437
|
+
assert_raise ActiveRecord::RecordInvalid do
|
438
|
+
alternate_name_lower.save!
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
class ChangeEntriesTable < ActiveRecord::Migration
|
443
|
+
def self.up
|
444
|
+
change_table :entries do |t|
|
445
|
+
t.string :author
|
446
|
+
end if respond_to?(:change_table)
|
447
|
+
end
|
448
|
+
def self.down
|
449
|
+
change_table :entries do |t|
|
450
|
+
t.remove :author
|
451
|
+
end if respond_to?(:change_table)
|
452
|
+
end
|
453
|
+
end
|
454
|
+
def test_change_table
|
455
|
+
ChangeEntriesTable.up
|
456
|
+
ChangeEntriesTable.down
|
457
|
+
end
|
458
|
+
|
459
|
+
def test_string_id
|
460
|
+
f = StringId.new
|
461
|
+
f.id = "some_string"
|
462
|
+
f.save
|
463
|
+
f = StringId.first #reload is essential
|
464
|
+
assert_equal "some_string", f.id
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
module MultibyteTestMethods
|
469
|
+
include MigrationSetup
|
470
|
+
|
471
|
+
if defined?(JRUBY_VERSION)
|
472
|
+
def setup
|
473
|
+
super
|
474
|
+
config = ActiveRecord::Base.connection.config
|
475
|
+
@jdbc_driver = ActiveRecord::ConnectionAdapters::JdbcDriver.new(config[:driver])
|
476
|
+
@java_con = @jdbc_driver.connection(config[:url], config[:username], config[:password])
|
477
|
+
@java_con.setAutoCommit(true)
|
478
|
+
end
|
479
|
+
|
480
|
+
def teardown
|
481
|
+
@java_con.close
|
482
|
+
@jdbc_driver = nil
|
483
|
+
super
|
484
|
+
end
|
485
|
+
|
486
|
+
def test_select_multibyte_string
|
487
|
+
@java_con.createStatement().execute("insert into entries (id, title, content) values (1, 'テスト', '本文')")
|
488
|
+
entry = Entry.find(:first)
|
489
|
+
assert_equal "テスト", entry.title
|
490
|
+
assert_equal "本文", entry.content
|
491
|
+
assert_equal entry, Entry.find_by_title("テスト")
|
492
|
+
end
|
493
|
+
|
494
|
+
def test_update_multibyte_string
|
495
|
+
Entry.create!(:title => "テスト", :content => "本文")
|
496
|
+
rs = @java_con.createStatement().executeQuery("select title, content from entries")
|
497
|
+
assert rs.next
|
498
|
+
assert_equal "テスト", rs.getString(1)
|
499
|
+
assert_equal "本文", rs.getString(2)
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
def test_multibyte_aliasing
|
504
|
+
str = "テスト"
|
505
|
+
quoted_alias = Entry.connection.quote_column_name(str)
|
506
|
+
sql = "SELECT title AS #{quoted_alias} from entries"
|
507
|
+
records = Entry.connection.select_all(sql)
|
508
|
+
records.each do |rec|
|
509
|
+
rec.keys.each do |key|
|
510
|
+
assert_equal str, key
|
511
|
+
end
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
515
|
+
def test_chinese_word
|
516
|
+
chinese_word = '中文'
|
517
|
+
new_entry = Entry.create(:title => chinese_word)
|
518
|
+
new_entry.reload
|
519
|
+
assert_equal chinese_word, new_entry.title
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
module NonUTF8EncodingMethods
|
524
|
+
def setup
|
525
|
+
@connection = ActiveRecord::Base.remove_connection
|
526
|
+
latin2_connection = @connection.dup
|
527
|
+
latin2_connection[:encoding] = 'latin2'
|
528
|
+
latin2_connection.delete(:url) # pre-gen url gets stashed; remove to re-gen
|
529
|
+
ActiveRecord::Base.establish_connection latin2_connection
|
530
|
+
CreateEntries.up
|
531
|
+
end
|
532
|
+
|
533
|
+
def teardown
|
534
|
+
CreateEntries.down
|
535
|
+
ActiveRecord::Base.establish_connection @connection
|
536
|
+
end
|
537
|
+
|
538
|
+
def test_nonutf8_encoding_in_entry
|
539
|
+
prague_district = 'hradčany'
|
540
|
+
new_entry = Entry.create :title => prague_district
|
541
|
+
new_entry.reload
|
542
|
+
assert_equal prague_district, new_entry.title
|
543
|
+
end
|
544
|
+
end
|
545
|
+
|
546
|
+
module ActiveRecord3TestMethods
|
547
|
+
def self.included(base)
|
548
|
+
base.send :include, Tests if ActiveRecord::VERSION::MAJOR == 3
|
549
|
+
end
|
550
|
+
|
551
|
+
module Tests
|
552
|
+
def test_where
|
553
|
+
entries = Entry.where(:title => @entry.title)
|
554
|
+
assert_equal @entry, entries.first
|
555
|
+
end
|
556
|
+
end
|
557
|
+
end
|