activerecord-jdbc-adapter 1.0.3-java → 50.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +33 -0
- data/.travis.yml +79 -0
- data/.yardopts +4 -0
- data/CONTRIBUTING.md +50 -0
- data/Gemfile +91 -0
- data/History.md +1191 -0
- data/LICENSE.txt +22 -17
- data/README.md +169 -0
- data/RUNNING_TESTS.md +127 -0
- data/Rakefile +294 -5
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +55 -0
- data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +0 -5
- data/lib/arel/visitors/compat.rb +60 -0
- data/lib/arel/visitors/db2.rb +128 -6
- data/lib/arel/visitors/derby.rb +103 -10
- data/lib/arel/visitors/firebird.rb +79 -0
- data/lib/arel/visitors/h2.rb +25 -0
- data/lib/arel/visitors/hsqldb.rb +18 -10
- data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
- data/lib/arel/visitors/sql_server.rb +225 -0
- data/lib/arel/visitors/sql_server/ng42.rb +293 -0
- data/lib/arjdbc.rb +11 -21
- data/lib/arjdbc/abstract/connection_management.rb +35 -0
- data/lib/arjdbc/abstract/core.rb +64 -0
- data/lib/arjdbc/abstract/database_statements.rb +64 -0
- data/lib/arjdbc/abstract/statement_cache.rb +58 -0
- data/lib/arjdbc/abstract/transaction_support.rb +86 -0
- data/lib/arjdbc/db2.rb +3 -1
- data/lib/arjdbc/db2/adapter.rb +630 -250
- data/lib/arjdbc/db2/as400.rb +130 -0
- data/lib/arjdbc/db2/column.rb +167 -0
- data/lib/arjdbc/db2/connection_methods.rb +44 -0
- data/lib/arjdbc/derby.rb +1 -5
- data/lib/arjdbc/derby/active_record_patch.rb +13 -0
- data/lib/arjdbc/derby/adapter.rb +409 -217
- data/lib/arjdbc/derby/connection_methods.rb +16 -14
- data/lib/arjdbc/derby/schema_creation.rb +15 -0
- data/lib/arjdbc/discover.rb +62 -50
- data/lib/arjdbc/firebird.rb +3 -1
- data/lib/arjdbc/firebird/adapter.rb +365 -62
- data/lib/arjdbc/firebird/connection_methods.rb +23 -0
- data/lib/arjdbc/h2.rb +2 -3
- data/lib/arjdbc/h2/adapter.rb +273 -6
- data/lib/arjdbc/h2/connection_methods.rb +23 -8
- data/lib/arjdbc/hsqldb.rb +2 -3
- data/lib/arjdbc/hsqldb/adapter.rb +204 -77
- data/lib/arjdbc/hsqldb/connection_methods.rb +24 -10
- data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
- data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
- data/lib/arjdbc/informix.rb +4 -2
- data/lib/arjdbc/informix/adapter.rb +78 -54
- data/lib/arjdbc/informix/connection_methods.rb +8 -9
- data/lib/arjdbc/jdbc.rb +59 -2
- data/lib/arjdbc/jdbc/adapter.rb +356 -166
- 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 +15 -0
- data/lib/arjdbc/jdbc/callbacks.rb +27 -18
- data/lib/arjdbc/jdbc/column.rb +79 -20
- data/lib/arjdbc/jdbc/connection.rb +5 -119
- data/lib/arjdbc/jdbc/connection_methods.rb +32 -4
- data/lib/arjdbc/jdbc/error.rb +65 -0
- data/lib/arjdbc/jdbc/extension.rb +41 -29
- data/lib/arjdbc/jdbc/java.rb +5 -6
- data/lib/arjdbc/jdbc/jdbc.rake +3 -126
- data/lib/arjdbc/jdbc/railtie.rb +2 -9
- data/lib/arjdbc/jdbc/rake_tasks.rb +3 -10
- data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -0
- data/lib/arjdbc/jdbc/type_cast.rb +166 -0
- data/lib/arjdbc/jdbc/type_converter.rb +35 -19
- data/lib/arjdbc/mssql.rb +6 -3
- data/lib/arjdbc/mssql/adapter.rb +630 -298
- data/lib/arjdbc/mssql/column.rb +200 -0
- data/lib/arjdbc/mssql/connection_methods.rb +66 -17
- data/lib/arjdbc/mssql/explain_support.rb +99 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +189 -50
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/types.rb +343 -0
- data/lib/arjdbc/mssql/utils.rb +82 -0
- data/lib/arjdbc/mysql.rb +2 -3
- data/lib/arjdbc/mysql/adapter.rb +86 -356
- data/lib/arjdbc/mysql/connection_methods.rb +159 -23
- data/lib/arjdbc/oracle/adapter.rb +714 -263
- data/lib/arjdbc/postgresql.rb +2 -3
- data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +24 -0
- data/lib/arjdbc/postgresql/adapter.rb +570 -400
- data/lib/arjdbc/postgresql/base/array_decoder.rb +26 -0
- data/lib/arjdbc/postgresql/base/array_encoder.rb +25 -0
- data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
- data/lib/arjdbc/postgresql/base/pgconn.rb +11 -0
- data/lib/arjdbc/postgresql/column.rb +51 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +57 -18
- data/lib/arjdbc/postgresql/name.rb +24 -0
- data/lib/arjdbc/postgresql/oid_types.rb +192 -0
- data/lib/arjdbc/railtie.rb +11 -0
- data/lib/arjdbc/sqlite3.rb +2 -3
- data/lib/arjdbc/sqlite3/adapter.rb +518 -198
- data/lib/arjdbc/sqlite3/connection_methods.rb +49 -24
- data/lib/arjdbc/sybase.rb +2 -2
- data/lib/arjdbc/sybase/adapter.rb +7 -6
- data/lib/arjdbc/tasks.rb +13 -0
- data/lib/arjdbc/tasks/database_tasks.rb +52 -0
- data/lib/arjdbc/tasks/databases.rake +91 -0
- data/lib/arjdbc/tasks/databases3.rake +215 -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 +31 -0
- data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
- data/lib/arjdbc/tasks/jdbc_database_tasks.rb +169 -0
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +46 -0
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/serialized_attributes.rb +98 -0
- data/lib/arjdbc/util/table_copier.rb +110 -0
- data/lib/arjdbc/version.rb +1 -6
- data/lib/generators/jdbc/USAGE +9 -0
- data/lib/generators/jdbc/jdbc_generator.rb +8 -0
- data/lib/jdbc_adapter.rb +1 -1
- data/lib/jdbc_adapter/rake_tasks.rb +3 -2
- data/lib/jdbc_adapter/version.rb +2 -1
- data/pom.xml +114 -0
- 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/01-tomcat.rake +51 -0
- data/rakelib/02-test.rake +132 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/compile.rake +67 -22
- data/rakelib/db.rake +61 -0
- data/rakelib/rails.rake +204 -29
- data/src/java/arjdbc/ArJdbcModule.java +286 -0
- data/src/java/arjdbc/db2/DB2Module.java +76 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +126 -0
- data/src/java/arjdbc/derby/DerbyModule.java +99 -243
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +152 -0
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +174 -0
- data/src/java/arjdbc/{jdbc/JdbcConnectionFactory.java → h2/H2Module.java} +20 -6
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +27 -12
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +73 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +7 -29
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/ConnectionFactory.java +132 -0
- data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +157 -0
- data/src/java/arjdbc/jdbc/DriverConnectionFactory.java +63 -0
- data/src/java/arjdbc/jdbc/DriverWrapper.java +119 -0
- data/src/java/arjdbc/jdbc/JdbcResult.java +130 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +3622 -948
- data/src/java/arjdbc/mssql/MSSQLModule.java +90 -0
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +181 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +99 -81
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +294 -0
- data/src/java/arjdbc/oracle/OracleModule.java +80 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +387 -17
- data/src/java/arjdbc/postgresql/ByteaUtils.java +157 -0
- data/src/java/arjdbc/postgresql/PgResultSetMetaDataWrapper.java +23 -0
- data/src/java/arjdbc/postgresql/PostgreSQLModule.java +77 -0
- data/src/java/arjdbc/postgresql/PostgreSQLResult.java +184 -0
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +952 -0
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +73 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +525 -0
- data/src/java/arjdbc/util/CallResultSet.java +826 -0
- data/src/java/arjdbc/util/DateTimeUtils.java +580 -0
- data/src/java/arjdbc/util/ObjectSupport.java +65 -0
- data/src/java/arjdbc/util/QuotingUtils.java +138 -0
- data/src/java/arjdbc/util/StringCache.java +63 -0
- data/src/java/arjdbc/util/StringHelper.java +159 -0
- metadata +245 -268
- data/History.txt +0 -369
- data/Manifest.txt +0 -180
- data/README.txt +0 -181
- data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -1
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
- data/lib/arel/visitors/mssql.rb +0 -44
- data/lib/arjdbc/jdbc/compatibility.rb +0 -51
- data/lib/arjdbc/jdbc/core_ext.rb +0 -24
- data/lib/arjdbc/jdbc/discover.rb +0 -18
- data/lib/arjdbc/jdbc/driver.rb +0 -44
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -87
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +0 -28
- data/lib/arjdbc/jdbc/require_driver.rb +0 -16
- data/lib/arjdbc/mimer.rb +0 -2
- data/lib/arjdbc/mimer/adapter.rb +0 -142
- data/lib/arjdbc/mssql/tsql_helper.rb +0 -61
- data/lib/arjdbc/oracle.rb +0 -3
- data/lib/arjdbc/oracle/connection_methods.rb +0 -11
- data/lib/pg.rb +0 -4
- data/rakelib/package.rake +0 -92
- data/rakelib/test.rake +0 -81
- data/src/java/arjdbc/jdbc/SQLBlock.java +0 -48
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +0 -127
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +0 -57
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +0 -64
- data/test/abstract_db_create.rb +0 -117
- data/test/activerecord/connection_adapters/type_conversion_test.rb +0 -31
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
- data/test/db/db2.rb +0 -11
- data/test/db/derby.rb +0 -12
- data/test/db/h2.rb +0 -11
- data/test/db/hsqldb.rb +0 -13
- data/test/db/informix.rb +0 -11
- data/test/db/jdbc.rb +0 -11
- data/test/db/jndi_config.rb +0 -40
- data/test/db/logger.rb +0 -3
- data/test/db/mssql.rb +0 -9
- data/test/db/mysql.rb +0 -10
- data/test/db/oracle.rb +0 -34
- data/test/db/postgres.rb +0 -9
- data/test/db/sqlite3.rb +0 -11
- data/test/db2_simple_test.rb +0 -66
- data/test/derby_migration_test.rb +0 -68
- data/test/derby_multibyte_test.rb +0 -12
- data/test/derby_simple_test.rb +0 -99
- data/test/generic_jdbc_connection_test.rb +0 -29
- data/test/h2_simple_test.rb +0 -41
- data/test/has_many_through.rb +0 -79
- data/test/helper.rb +0 -5
- data/test/hsqldb_simple_test.rb +0 -6
- data/test/informix_simple_test.rb +0 -48
- data/test/jdbc_common.rb +0 -25
- data/test/jndi_callbacks_test.rb +0 -40
- data/test/jndi_test.rb +0 -25
- data/test/manualTestDatabase.rb +0 -191
- data/test/models/add_not_null_column_to_table.rb +0 -12
- data/test/models/auto_id.rb +0 -18
- data/test/models/data_types.rb +0 -28
- data/test/models/entry.rb +0 -43
- data/test/models/mixed_case.rb +0 -25
- data/test/models/reserved_word.rb +0 -18
- data/test/models/string_id.rb +0 -18
- data/test/models/validates_uniqueness_of_string.rb +0 -19
- data/test/mssql_db_create_test.rb +0 -26
- data/test/mssql_identity_insert_test.rb +0 -19
- data/test/mssql_legacy_types_test.rb +0 -58
- data/test/mssql_limit_offset_test.rb +0 -136
- data/test/mssql_multibyte_test.rb +0 -18
- data/test/mssql_simple_test.rb +0 -55
- data/test/mysql_db_create_test.rb +0 -27
- data/test/mysql_info_test.rb +0 -113
- data/test/mysql_multibyte_test.rb +0 -10
- data/test/mysql_nonstandard_primary_key_test.rb +0 -42
- data/test/mysql_simple_test.rb +0 -49
- data/test/oracle_simple_test.rb +0 -18
- data/test/oracle_specific_test.rb +0 -83
- data/test/pick_rails_version.rb +0 -3
- data/test/postgres_db_create_test.rb +0 -32
- data/test/postgres_drop_db_test.rb +0 -16
- data/test/postgres_mixed_case_test.rb +0 -29
- data/test/postgres_nonseq_pkey_test.rb +0 -38
- data/test/postgres_reserved_test.rb +0 -22
- data/test/postgres_schema_search_path_test.rb +0 -44
- data/test/postgres_simple_test.rb +0 -51
- data/test/postgres_table_alias_length_test.rb +0 -15
- data/test/simple.rb +0 -546
- data/test/sqlite3_simple_test.rb +0 -233
- data/test/sybase_jtds_simple_test.rb +0 -28
|
@@ -1,29 +0,0 @@
|
|
|
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
|
|
@@ -1,38 +0,0 @@
|
|
|
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
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
|
@@ -1,44 +0,0 @@
|
|
|
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')
|
|
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
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
end
|
|
14
|
-
|
|
15
|
-
class PostgresDeserializationTest < Test::Unit::TestCase
|
|
16
|
-
def setup
|
|
17
|
-
DbTypeMigration.up
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def teardown
|
|
21
|
-
DbTypeMigration.down
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def test_should_keep_float_precision
|
|
25
|
-
expected = DbType.create(:sample_float => 7.3)
|
|
26
|
-
actual = DbType.find(expected.id)
|
|
27
|
-
|
|
28
|
-
assert_equal expected.sample_float, actual.sample_float
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
class PostgresSchemaDumperTest < Test::Unit::TestCase
|
|
33
|
-
def setup
|
|
34
|
-
DbTypeMigration.up
|
|
35
|
-
@connection = ActiveRecord::Base.connection
|
|
36
|
-
strio = StringIO.new
|
|
37
|
-
ActiveRecord::SchemaDumper::dump(ActiveRecord::Base.connection, strio)
|
|
38
|
-
@dump = strio.string
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def teardown
|
|
42
|
-
DbTypeMigration.down
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# http://kenai.com/jira/browse/ACTIVERECORD_JDBC-135
|
|
46
|
-
def test_schema_dump_should_not_have_limits_on_boolean
|
|
47
|
-
lines = @dump.grep(/boolean/)
|
|
48
|
-
assert !lines.empty?
|
|
49
|
-
lines.each {|line| assert line !~ /limit/ }
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,546 +0,0 @@
|
|
|
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_indexes
|
|
260
|
-
# Only test indexes if we have implemented it for the particular adapter
|
|
261
|
-
if @connection.respond_to?(:indexes)
|
|
262
|
-
indexes = @connection.indexes(:entries)
|
|
263
|
-
assert_equal(0, indexes.size)
|
|
264
|
-
|
|
265
|
-
index_name = "entries_index"
|
|
266
|
-
@connection.add_index(:entries, :updated_on, :name => index_name)
|
|
267
|
-
|
|
268
|
-
indexes = @connection.indexes(:entries)
|
|
269
|
-
assert_equal(1, indexes.size)
|
|
270
|
-
assert_equal "entries", indexes.first.table.to_s
|
|
271
|
-
assert_equal index_name, indexes.first.name
|
|
272
|
-
assert !indexes.first.unique
|
|
273
|
-
assert_equal ["updated_on"], indexes.first.columns
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
def test_dumping_schema
|
|
278
|
-
require 'active_record/schema_dumper'
|
|
279
|
-
@connection.add_index :entries, :title
|
|
280
|
-
StringIO.open do |io|
|
|
281
|
-
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, io)
|
|
282
|
-
assert_match(/add_index "entries",/, io.string)
|
|
283
|
-
end
|
|
284
|
-
@connection.remove_index :entries, :title
|
|
285
|
-
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
def test_nil_values
|
|
289
|
-
test = AutoId.create('value' => '')
|
|
290
|
-
assert_nil AutoId.find(test.id).value
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
# These should make no difference, but might due to the wacky regexp SQL rewriting we do.
|
|
294
|
-
def test_save_value_containing_sql
|
|
295
|
-
e = DbType.first
|
|
296
|
-
e.save
|
|
297
|
-
|
|
298
|
-
e.sample_string = e.sample_text = "\n\nselect from nothing where id = 'foo'"
|
|
299
|
-
e.save
|
|
300
|
-
end
|
|
301
|
-
|
|
302
|
-
def test_invalid
|
|
303
|
-
e = Entry.new(:title => @title, :content => @content, :rating => ' ')
|
|
304
|
-
assert e.valid?
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
def test_reconnect
|
|
308
|
-
assert_equal 1, Entry.count
|
|
309
|
-
@connection.reconnect!
|
|
310
|
-
assert_equal 1, Entry.count
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
if jruby?
|
|
314
|
-
def test_connection_valid
|
|
315
|
-
assert_raises(ActiveRecord::JDBCError) do
|
|
316
|
-
@connection.raw_connection.with_connection_retry_guard do |c|
|
|
317
|
-
begin
|
|
318
|
-
stmt = c.createStatement
|
|
319
|
-
stmt.execute "bogus sql"
|
|
320
|
-
ensure
|
|
321
|
-
stmt.close rescue nil
|
|
322
|
-
end
|
|
323
|
-
end
|
|
324
|
-
end
|
|
325
|
-
end
|
|
326
|
-
|
|
327
|
-
class Animal < ActiveRecord::Base; end
|
|
328
|
-
|
|
329
|
-
# ENEBO: Is this really ar-jdbc-specific or a bug in our adapter?
|
|
330
|
-
def test_fetching_columns_for_nonexistent_table_should_raise
|
|
331
|
-
assert_raises(ActiveRecord::JDBCError) do
|
|
332
|
-
Animal.columns
|
|
333
|
-
end
|
|
334
|
-
end
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
def test_disconnect
|
|
338
|
-
assert_equal 1, Entry.count
|
|
339
|
-
ActiveRecord::Base.clear_active_connections!
|
|
340
|
-
ActiveRecord::Base.connection_pool.disconnect! if ActiveRecord::Base.respond_to?(:connection_pool)
|
|
341
|
-
assert !ActiveRecord::Base.connected?
|
|
342
|
-
assert_equal 1, Entry.count
|
|
343
|
-
assert ActiveRecord::Base.connected?
|
|
344
|
-
end
|
|
345
|
-
|
|
346
|
-
def test_add_not_null_column_to_table
|
|
347
|
-
AddNotNullColumnToTable.up
|
|
348
|
-
AddNotNullColumnToTable.down
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
def test_add_null_column_with_default
|
|
352
|
-
Entry.connection.add_column :entries, :color, :string, :null => false, :default => "blue"
|
|
353
|
-
created_columns = Entry.connection.columns('entries')
|
|
354
|
-
|
|
355
|
-
color = created_columns.detect { |c| c.name == 'color' }
|
|
356
|
-
assert !color.null
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
def test_add_null_column_with_no_default
|
|
360
|
-
# You must specify a default value with most databases
|
|
361
|
-
if ActiveRecord::Base.connection.adapter_name =~ /mysql/i
|
|
362
|
-
Entry.connection.add_column :entries, :color, :string, :null => false
|
|
363
|
-
created_columns = Entry.connection.columns('entries')
|
|
364
|
-
|
|
365
|
-
color = created_columns.detect { |c| c.name == 'color' }
|
|
366
|
-
assert !color.null
|
|
367
|
-
end
|
|
368
|
-
end
|
|
369
|
-
|
|
370
|
-
def test_add_null_column_with_nil_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, :default => nil
|
|
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_validates_uniqueness_of_strings_case_sensitive
|
|
382
|
-
name_lower = ValidatesUniquenessOfString.new(:cs_string => "name", :ci_string => '1')
|
|
383
|
-
name_lower.save!
|
|
384
|
-
|
|
385
|
-
name_upper = ValidatesUniquenessOfString.new(:cs_string => "NAME", :ci_string => '2')
|
|
386
|
-
assert_nothing_raised do
|
|
387
|
-
name_upper.save!
|
|
388
|
-
end
|
|
389
|
-
|
|
390
|
-
name_lower_collision = ValidatesUniquenessOfString.new(:cs_string => "name", :ci_string => '3')
|
|
391
|
-
assert_raise ActiveRecord::RecordInvalid do
|
|
392
|
-
name_lower_collision.save!
|
|
393
|
-
end
|
|
394
|
-
|
|
395
|
-
name_upper_collision = ValidatesUniquenessOfString.new(:cs_string => "NAME", :ci_string => '4')
|
|
396
|
-
assert_raise ActiveRecord::RecordInvalid do
|
|
397
|
-
name_upper_collision.save!
|
|
398
|
-
end
|
|
399
|
-
end
|
|
400
|
-
|
|
401
|
-
def test_validates_uniqueness_of_strings_case_insensitive
|
|
402
|
-
name_lower = ValidatesUniquenessOfString.new(:cs_string => '1', :ci_string => "name")
|
|
403
|
-
name_lower.save!
|
|
404
|
-
|
|
405
|
-
name_upper = ValidatesUniquenessOfString.new(:cs_string => '2', :ci_string => "NAME")
|
|
406
|
-
assert_raise ActiveRecord::RecordInvalid do
|
|
407
|
-
name_upper.save!
|
|
408
|
-
end
|
|
409
|
-
|
|
410
|
-
name_lower_collision = ValidatesUniquenessOfString.new(:cs_string => '3', :ci_string => "name")
|
|
411
|
-
assert_raise ActiveRecord::RecordInvalid do
|
|
412
|
-
name_lower_collision.save!
|
|
413
|
-
end
|
|
414
|
-
|
|
415
|
-
alternate_name_upper = ValidatesUniquenessOfString.new(:cs_string => '4', :ci_string => "ALTERNATE_NAME")
|
|
416
|
-
assert_nothing_raised do
|
|
417
|
-
alternate_name_upper.save!
|
|
418
|
-
end
|
|
419
|
-
|
|
420
|
-
alternate_name_upper_collision = ValidatesUniquenessOfString.new(:cs_string => '5', :ci_string => "ALTERNATE_NAME")
|
|
421
|
-
assert_raise ActiveRecord::RecordInvalid do
|
|
422
|
-
alternate_name_upper_collision.save!
|
|
423
|
-
end
|
|
424
|
-
|
|
425
|
-
alternate_name_lower = ValidatesUniquenessOfString.new(:cs_string => '6', :ci_string => "alternate_name")
|
|
426
|
-
assert_raise ActiveRecord::RecordInvalid do
|
|
427
|
-
alternate_name_lower.save!
|
|
428
|
-
end
|
|
429
|
-
end
|
|
430
|
-
|
|
431
|
-
class ChangeEntriesTable < ActiveRecord::Migration
|
|
432
|
-
def self.up
|
|
433
|
-
change_table :entries do |t|
|
|
434
|
-
t.string :author
|
|
435
|
-
end if respond_to?(:change_table)
|
|
436
|
-
end
|
|
437
|
-
def self.down
|
|
438
|
-
change_table :entries do |t|
|
|
439
|
-
t.remove :author
|
|
440
|
-
end if respond_to?(:change_table)
|
|
441
|
-
end
|
|
442
|
-
end
|
|
443
|
-
def test_change_table
|
|
444
|
-
ChangeEntriesTable.up
|
|
445
|
-
ChangeEntriesTable.down
|
|
446
|
-
end
|
|
447
|
-
|
|
448
|
-
def test_string_id
|
|
449
|
-
f = StringId.new
|
|
450
|
-
f.id = "some_string"
|
|
451
|
-
f.save
|
|
452
|
-
f = StringId.first #reload is essential
|
|
453
|
-
assert_equal "some_string", f.id
|
|
454
|
-
end
|
|
455
|
-
end
|
|
456
|
-
|
|
457
|
-
module MultibyteTestMethods
|
|
458
|
-
include MigrationSetup
|
|
459
|
-
|
|
460
|
-
if defined?(JRUBY_VERSION)
|
|
461
|
-
def setup
|
|
462
|
-
super
|
|
463
|
-
config = ActiveRecord::Base.connection.config
|
|
464
|
-
jdbc_driver = ActiveRecord::ConnectionAdapters::JdbcDriver.new(config[:driver])
|
|
465
|
-
jdbc_driver.load
|
|
466
|
-
@java_con = jdbc_driver.connection(config[:url], config[:username], config[:password])
|
|
467
|
-
@java_con.setAutoCommit(true)
|
|
468
|
-
end
|
|
469
|
-
|
|
470
|
-
def teardown
|
|
471
|
-
@java_con.close
|
|
472
|
-
super
|
|
473
|
-
end
|
|
474
|
-
|
|
475
|
-
def test_select_multibyte_string
|
|
476
|
-
@java_con.createStatement().execute("insert into entries (id, title, content) values (1, 'テスト', '本文')")
|
|
477
|
-
entry = Entry.find(:first)
|
|
478
|
-
assert_equal "テスト", entry.title
|
|
479
|
-
assert_equal "本文", entry.content
|
|
480
|
-
assert_equal entry, Entry.find_by_title("テスト")
|
|
481
|
-
end
|
|
482
|
-
|
|
483
|
-
def test_update_multibyte_string
|
|
484
|
-
Entry.create!(:title => "テスト", :content => "本文")
|
|
485
|
-
rs = @java_con.createStatement().executeQuery("select title, content from entries")
|
|
486
|
-
assert rs.next
|
|
487
|
-
assert_equal "テスト", rs.getString(1)
|
|
488
|
-
assert_equal "本文", rs.getString(2)
|
|
489
|
-
end
|
|
490
|
-
end
|
|
491
|
-
|
|
492
|
-
def test_multibyte_aliasing
|
|
493
|
-
str = "テスト"
|
|
494
|
-
quoted_alias = Entry.connection.quote_column_name(str)
|
|
495
|
-
sql = "SELECT title AS #{quoted_alias} from entries"
|
|
496
|
-
records = Entry.connection.select_all(sql)
|
|
497
|
-
records.each do |rec|
|
|
498
|
-
rec.keys.each do |key|
|
|
499
|
-
assert_equal str, key
|
|
500
|
-
end
|
|
501
|
-
end
|
|
502
|
-
end
|
|
503
|
-
|
|
504
|
-
def test_chinese_word
|
|
505
|
-
chinese_word = '中文'
|
|
506
|
-
new_entry = Entry.create(:title => chinese_word)
|
|
507
|
-
new_entry.reload
|
|
508
|
-
assert_equal chinese_word, new_entry.title
|
|
509
|
-
end
|
|
510
|
-
end
|
|
511
|
-
|
|
512
|
-
module NonUTF8EncodingMethods
|
|
513
|
-
def setup
|
|
514
|
-
@connection = ActiveRecord::Base.remove_connection
|
|
515
|
-
latin2_connection = @connection.dup
|
|
516
|
-
latin2_connection[:encoding] = 'latin2'
|
|
517
|
-
latin2_connection.delete(:url) # pre-gen url gets stashed; remove to re-gen
|
|
518
|
-
ActiveRecord::Base.establish_connection latin2_connection
|
|
519
|
-
CreateEntries.up
|
|
520
|
-
end
|
|
521
|
-
|
|
522
|
-
def teardown
|
|
523
|
-
CreateEntries.down
|
|
524
|
-
ActiveRecord::Base.establish_connection @connection
|
|
525
|
-
end
|
|
526
|
-
|
|
527
|
-
def test_nonutf8_encoding_in_entry
|
|
528
|
-
prague_district = 'hradčany'
|
|
529
|
-
new_entry = Entry.create :title => prague_district
|
|
530
|
-
new_entry.reload
|
|
531
|
-
assert_equal prague_district, new_entry.title
|
|
532
|
-
end
|
|
533
|
-
end
|
|
534
|
-
|
|
535
|
-
module ActiveRecord3TestMethods
|
|
536
|
-
def self.included(base)
|
|
537
|
-
base.send :include, Tests if ActiveRecord::VERSION::MAJOR == 3
|
|
538
|
-
end
|
|
539
|
-
|
|
540
|
-
module Tests
|
|
541
|
-
def test_where
|
|
542
|
-
entries = Entry.where(:title => @entry.title)
|
|
543
|
-
assert_equal @entry, entries.first
|
|
544
|
-
end
|
|
545
|
-
end
|
|
546
|
-
end
|