activerecord-jdbc-adapter 1.2.9.1 → 1.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -0
- data/Appraisals +12 -4
- data/Gemfile +3 -3
- data/Gemfile.lock +19 -19
- data/History.txt +90 -16
- data/LICENSE.txt +2 -1
- data/README.md +14 -1
- data/activerecord-jdbc-adapter.gemspec +2 -2
- data/gemfiles/rails23.gemfile +5 -5
- data/gemfiles/rails23.gemfile.lock +27 -27
- data/gemfiles/rails30.gemfile +3 -3
- data/gemfiles/rails30.gemfile.lock +8 -8
- data/gemfiles/rails31.gemfile +4 -4
- data/gemfiles/rails31.gemfile.lock +18 -18
- data/gemfiles/rails32.gemfile +4 -4
- data/gemfiles/rails32.gemfile.lock +17 -17
- data/gemfiles/rails40.gemfile +17 -0
- data/gemfiles/rails40.gemfile.lock +126 -0
- data/lib/activerecord-jdbc-adapter.rb +0 -7
- data/lib/arjdbc.rb +6 -5
- data/lib/arjdbc/db2.rb +1 -1
- data/lib/arjdbc/db2/adapter.rb +52 -29
- data/lib/arjdbc/db2/connection_methods.rb +13 -14
- data/lib/arjdbc/derby.rb +1 -1
- data/lib/arjdbc/derby/adapter.rb +29 -9
- data/lib/arjdbc/derby/connection_methods.rb +17 -20
- data/lib/arjdbc/firebird.rb +1 -1
- data/lib/arjdbc/h2.rb +2 -2
- data/lib/arjdbc/h2/adapter.rb +1 -1
- data/lib/arjdbc/h2/connection_methods.rb +12 -16
- data/lib/arjdbc/hsqldb.rb +1 -1
- data/lib/arjdbc/hsqldb/connection_methods.rb +13 -16
- data/lib/arjdbc/informix.rb +1 -1
- data/lib/arjdbc/informix/connection_methods.rb +8 -10
- data/lib/arjdbc/jdbc.rb +1 -1
- data/lib/arjdbc/jdbc/adapter.rb +125 -53
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/base_ext.rb +34 -9
- data/lib/arjdbc/jdbc/column.rb +15 -2
- data/lib/arjdbc/jdbc/connection.rb +0 -2
- data/lib/arjdbc/jdbc/connection_methods.rb +10 -3
- data/lib/arjdbc/jdbc/driver.rb +2 -2
- data/lib/arjdbc/jdbc/extension.rb +35 -21
- data/lib/arjdbc/jdbc/java.rb +0 -2
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +35 -25
- data/lib/arjdbc/jdbc/railtie.rb +2 -9
- data/lib/arjdbc/mimer.rb +1 -1
- data/lib/arjdbc/mssql.rb +2 -2
- data/lib/arjdbc/mssql/adapter.rb +271 -92
- data/lib/arjdbc/mssql/connection_methods.rb +30 -32
- data/lib/arjdbc/mssql/explain_support.rb +107 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +48 -18
- data/lib/arjdbc/mysql.rb +1 -1
- data/lib/arjdbc/mysql/adapter.rb +63 -14
- data/lib/arjdbc/mysql/connection_methods.rb +22 -24
- data/lib/arjdbc/mysql/explain_support.rb +2 -5
- data/lib/arjdbc/oracle.rb +1 -1
- data/lib/arjdbc/oracle/adapter.rb +78 -38
- data/lib/arjdbc/oracle/connection_methods.rb +9 -10
- data/lib/arjdbc/postgresql.rb +1 -1
- data/lib/arjdbc/postgresql/adapter.rb +964 -380
- data/lib/arjdbc/postgresql/column_cast.rb +136 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +19 -21
- data/lib/arjdbc/postgresql/explain_support.rb +3 -6
- data/lib/arjdbc/railtie.rb +9 -0
- data/lib/arjdbc/sqlite3.rb +1 -1
- data/lib/arjdbc/sqlite3/adapter.rb +73 -26
- data/lib/arjdbc/sqlite3/connection_methods.rb +27 -28
- data/lib/arjdbc/sqlite3/explain_support.rb +2 -5
- data/lib/arjdbc/sybase.rb +1 -1
- data/lib/arjdbc/version.rb +5 -4
- data/pom.xml +8 -0
- data/rakelib/02-test.rake +57 -51
- data/rakelib/compile.rake +17 -5
- data/rakelib/rails.rake +42 -31
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +4 -3
- data/src/java/arjdbc/derby/DerbyModule.java +98 -85
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +70 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +0 -4
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +26 -15
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +10 -2
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1675 -834
- data/src/java/arjdbc/jdbc/SQLBlock.java +9 -3
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +73 -36
- data/src/java/arjdbc/mysql/MySQLModule.java +11 -10
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +86 -80
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +27 -7
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +214 -0
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +25 -67
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +52 -49
- data/src/java/arjdbc/util/QuotingUtils.java +6 -6
- data/test/abstract_db_create.rb +11 -11
- data/test/activerecord/connection_adapters/type_conversion_test.rb +18 -12
- data/test/db/db2.rb +1 -1
- data/test/{db2_binary_test.rb → db/db2/binary_test.rb} +0 -0
- data/test/db/db2/has_many_through_test.rb +6 -0
- data/test/{db2_reset_column_information_test.rb → db/db2/reset_column_information_test.rb} +1 -2
- data/test/{db2_serialize_test.rb → db/db2/serialize_test.rb} +0 -0
- data/test/{db2_simple_test.rb → db/db2/simple_test.rb} +1 -8
- data/test/db/db2/test_helper.rb +6 -0
- data/test/{db2_test.rb → db/db2/unit_test.rb} +1 -1
- data/test/db/derby.rb +1 -1
- data/test/{derby_binary_test.rb → db/derby/binary_test.rb} +0 -0
- data/test/{derby_migration_test.rb → db/derby/migration_test.rb} +0 -0
- data/test/{derby_reset_column_information_test.rb → db/derby/reset_column_information_test.rb} +0 -0
- data/test/{derby_row_locking_test.rb → db/derby/row_locking_test.rb} +1 -4
- data/test/db/derby/schema_dump_test.rb +5 -0
- data/test/{derby_serialize_test.rb → db/derby/serialize_test.rb} +0 -0
- data/test/{derby_simple_test.rb → db/derby/simple_test.rb} +23 -38
- data/test/db/derby/test_helper.rb +6 -0
- data/test/db/derby/unit_test.rb +32 -0
- data/test/db/derby/xml_column_test.rb +17 -0
- data/test/db/h2.rb +1 -1
- data/test/{h2_binary_test.rb → db/h2/binary_test.rb} +0 -0
- data/test/{h2_change_column_test.rb → db/h2/change_column_test.rb} +1 -0
- data/test/{h2_schema_dump_test.rb → db/h2/schema_dump_test.rb} +0 -0
- data/test/{h2_serialize_test.rb → db/h2/serialize_test.rb} +0 -0
- data/test/{h2_simple_test.rb → db/h2/simple_test.rb} +3 -1
- data/test/db/hsqldb.rb +1 -1
- data/test/{hsqldb_binary_test.rb → db/hsqldb/binary_test.rb} +0 -0
- data/test/{hsqldb_schema_dump_test.rb → db/hsqldb/schema_dump_test.rb} +0 -0
- data/test/{hsqldb_serialize_test.rb → db/hsqldb/serialize_test.rb} +0 -0
- data/test/{hsqldb_simple_test.rb → db/hsqldb/simple_test.rb} +3 -1
- data/test/db/informix.rb +1 -1
- data/test/db/jdbc.rb +3 -2
- data/test/db/jdbc_derby.rb +1 -1
- data/test/db/jdbc_h2.rb +1 -1
- data/test/db/jdbc_mysql.rb +1 -1
- data/test/db/jdbc_postgres.rb +1 -1
- data/test/db/jndi_config.rb +1 -2
- data/test/db/jndi_pooled_config.rb +2 -3
- data/test/db/mssql.rb +2 -2
- data/test/{mssql_binary_test.rb → db/mssql/binary_test.rb} +0 -0
- data/test/{mssql_db_create_test.rb → db/mssql/db_create_test.rb} +1 -1
- data/test/db/mssql/exec_proc_test.rb +46 -0
- data/test/{mssql_identity_insert_test.rb → db/mssql/identity_insert_test.rb} +0 -0
- data/test/db/mssql/ignore_system_views_test.rb +40 -0
- data/test/{mssql_limit_offset_test.rb → db/mssql/limit_offset_test.rb} +10 -1
- data/test/{mssql_multibyte_test.rb → db/mssql/multibyte_test.rb} +0 -0
- data/test/db/mssql/multiple_connections_test.rb +71 -0
- data/test/{mssql_reset_column_information_test.rb → db/mssql/reset_column_information_test.rb} +0 -0
- data/test/{mssql_row_locking_test.rb → db/mssql/row_locking_test.rb} +0 -0
- data/test/{mssql_serialize_test.rb → db/mssql/serialize_test.rb} +1 -1
- data/test/db/mssql/simple_test.rb +140 -0
- data/test/db/mssql/transaction_test.rb +6 -0
- data/test/db/mssql/types_test.rb +205 -0
- data/test/{mssql_test.rb → db/mssql/unit_test.rb} +2 -2
- data/test/db/mysql.rb +1 -2
- data/test/db/mysql/_rails_test_mysql.32.out +6768 -0
- data/test/{mysql_binary_test.rb → db/mysql/binary_test.rb} +0 -0
- data/test/db/mysql/connection_test.rb +51 -0
- data/test/{mysql_db_create_test.rb → db/mysql/db_create_test.rb} +0 -0
- data/test/{mysql_index_length_test.rb → db/mysql/index_length_test.rb} +0 -0
- data/test/{mysql_multibyte_test.rb → db/mysql/multibyte_test.rb} +0 -0
- data/test/{mysql_nonstandard_primary_key_test.rb → db/mysql/nonstandard_primary_key_test.rb} +0 -0
- data/test/{mysql_reset_column_information_test.rb → db/mysql/reset_column_information_test.rb} +0 -0
- data/test/{mysql_schema_dump_test.rb → db/mysql/schema_dump_test.rb} +9 -1
- data/test/{mysql_serialize_test.rb → db/mysql/serialize_test.rb} +0 -0
- data/test/{mysql_simple_test.rb → db/mysql/simple_test.rb} +16 -8
- data/test/db/mysql/transaction_test.rb +6 -0
- data/test/db/mysql/types_test.rb +30 -0
- data/test/{mysql_test.rb → db/mysql/unit_test.rb} +1 -1
- data/test/db/mysql_config.rb +1 -1
- data/test/db/oracle.rb +1 -1
- data/test/{oracle_binary_test.rb → db/oracle/binary_test.rb} +0 -0
- data/test/{oracle_limit_test.rb → db/oracle/limit_test.rb} +0 -0
- data/test/db/oracle/multibyte_test.rb +22 -0
- data/test/{oracle_reset_column_information_test.rb → db/oracle/reset_column_information_test.rb} +0 -0
- data/test/{oracle_serialize_test.rb → db/oracle/serialize_test.rb} +0 -0
- data/test/{oracle_simple_test.rb → db/oracle/simple_test.rb} +14 -19
- data/test/{oracle_specific_test.rb → db/oracle/specific_test.rb} +62 -16
- data/test/db/oracle/transaction_test.rb +31 -0
- data/test/db/oracle/unit_test.rb +31 -0
- data/test/db/postgres.rb +1 -1
- data/test/db/postgres/_rails_test_postgres.32.out +6777 -0
- data/test/db/postgres/a_custom_primary_key_test.rb +50 -0
- data/test/db/postgres/array_type_test.rb +101 -0
- data/test/{postgres_binary_test.rb → db/postgres/binary_test.rb} +0 -0
- data/test/db/postgres/connection_test.rb +55 -0
- data/test/db/postgres/data_types_test.rb +703 -0
- data/test/{postgres_db_create_test.rb → db/postgres/db_create_test.rb} +1 -1
- data/test/{postgres_drop_db_test.rb → db/postgres/db_drop_test.rb} +2 -0
- data/test/db/postgres/hstore_test.rb +200 -0
- data/test/db/postgres/information_schema_leak_test.rb +30 -0
- data/test/db/postgres/json_test.rb +86 -0
- data/test/db/postgres/ltree_test.rb +50 -0
- data/test/{postgres_mixed_case_test.rb → db/postgres/mixed_case_test.rb} +0 -0
- data/test/db/postgres/native_types_test.rb +128 -0
- data/test/{postgres_reserved_test.rb → db/postgres/reserved_test.rb} +0 -0
- data/test/{postgres_reset_column_information_test.rb → db/postgres/reset_column_information_test.rb} +0 -0
- data/test/{postgres_row_locking_test.rb → db/postgres/row_locking_test.rb} +0 -0
- data/test/{postgres_schema_dump_test.rb → db/postgres/schema_dump_test.rb} +4 -4
- data/test/db/postgres/schema_test.rb +113 -0
- data/test/{postgres_simple_test.rb → db/postgres/simple_test.rb} +48 -8
- data/test/{postgres_table_alias_length_test.rb → db/postgres/table_alias_length_test.rb} +2 -1
- data/test/db/postgres/transaction_test.rb +6 -0
- data/test/{postgres_test.rb → db/postgres/unit_test.rb} +3 -3
- data/test/db/sqlite3.rb +1 -1
- data/test/db/sqlite3/_rails_test_sqlite3.32.out +6502 -0
- data/test/db/sqlite3/has_many_though_test.rb +6 -0
- data/test/{sqlite3_reset_column_information_test.rb → db/sqlite3/reset_column_information_test.rb} +0 -0
- data/test/{sqlite3_schema_dump_test.rb → db/sqlite3/schema_dump_test.rb} +0 -0
- data/test/{sqlite3_serialize_test.rb → db/sqlite3/serialize_test.rb} +0 -0
- data/test/{sqlite3_simple_test.rb → db/sqlite3/simple_test.rb} +63 -63
- data/test/db/sqlite3/transaction_test.rb +32 -0
- data/test/{sqlite3_type_conversion_test.rb → db/sqlite3/type_conversion_test.rb} +0 -0
- data/test/has_many_through.rb +29 -64
- data/test/jdbc/oracle.rb +11 -0
- data/test/jndi_test.rb +16 -4
- data/test/models/auto_id.rb +1 -1
- data/test/models/rights_and_roles.rb +57 -0
- data/test/row_locking.rb +3 -0
- data/test/schema_dump.rb +24 -10
- data/test/simple.rb +359 -104
- data/test/test_helper.rb +4 -2
- data/test/transaction.rb +109 -0
- metadata +119 -86
- 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/test/derby_schema_dump_test.rb +0 -9
- data/test/mssql_ignore_system_views_test.rb +0 -30
- data/test/mssql_legacy_types_test.rb +0 -58
- data/test/mssql_null_test.rb +0 -14
- data/test/mssql_simple_test.rb +0 -51
- data/test/postgres_information_schema_leak_test.rb +0 -28
- data/test/postgres_native_type_mapping_test.rb +0 -93
- data/test/postgres_nonseq_pkey_test.rb +0 -38
- data/test/postgres_schema_search_path_test.rb +0 -48
- data/test/postgres_type_conversion_test.rb +0 -33
data/test/models/auto_id.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
class CreateRightsAndRoles < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :role_assignments do |t|
|
4
|
+
t.column :role_id, :integer
|
5
|
+
t.column :user_id, :integer
|
6
|
+
end
|
7
|
+
|
8
|
+
create_table :roles do |t|
|
9
|
+
t.column :name, :string
|
10
|
+
t.column :description, :string
|
11
|
+
end
|
12
|
+
|
13
|
+
create_table :permission_groups do |t|
|
14
|
+
t.column :right_id, :integer, :null => false
|
15
|
+
t.column :role_id, :integer, :null => false
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table :rights do |t|
|
19
|
+
t.column :name, :string
|
20
|
+
t.column :controller_name, :string
|
21
|
+
t.column :actions, :string
|
22
|
+
t.column :hours, :float, :null => false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.down
|
27
|
+
drop_table :role_assignments
|
28
|
+
drop_table :roles
|
29
|
+
drop_table :permission_groups
|
30
|
+
drop_table :rights
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Right < ActiveRecord::Base
|
35
|
+
has_many :permission_groups, :dependent => :destroy
|
36
|
+
has_many :roles, :through => :permission_groups
|
37
|
+
end
|
38
|
+
|
39
|
+
class Role < ActiveRecord::Base
|
40
|
+
has_many :permission_groups, :dependent => :destroy
|
41
|
+
has_many :rights, :through => :permission_groups
|
42
|
+
has_many :role_assignments, :dependent => :destroy
|
43
|
+
|
44
|
+
def has_right?(right)
|
45
|
+
rights.include? right
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class PermissionGroup < ActiveRecord::Base
|
50
|
+
belongs_to :right
|
51
|
+
belongs_to :role
|
52
|
+
end
|
53
|
+
|
54
|
+
class RoleAssignment < ActiveRecord::Base
|
55
|
+
belongs_to :user
|
56
|
+
belongs_to :role
|
57
|
+
end
|
data/test/row_locking.rb
CHANGED
data/test/schema_dump.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'stringio'
|
2
|
+
require 'test_helper'
|
3
|
+
require 'simple' # due MigrationSetup
|
2
4
|
require 'active_record/schema_dumper'
|
3
5
|
|
4
6
|
module SchemaDumpTestMethods
|
@@ -70,9 +72,9 @@ module SchemaDumpTestMethods
|
|
70
72
|
|
71
73
|
def test_arguments_line_up
|
72
74
|
column_definition_lines.each do |column_set|
|
73
|
-
assert_line_up(column_set,
|
74
|
-
assert_line_up(column_set,
|
75
|
-
assert_line_up(column_set,
|
75
|
+
assert_line_up(column_set, /(:default => )|(default: )/)
|
76
|
+
assert_line_up(column_set, /(:limit => )|(limit: )/)
|
77
|
+
assert_line_up(column_set, /(:null => )|(null: )/)
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
@@ -83,7 +85,7 @@ module SchemaDumpTestMethods
|
|
83
85
|
|
84
86
|
def test_schema_dump_includes_not_null_columns
|
85
87
|
output = standard_dump(StringIO.new, [/^[^u]/]) # keep users
|
86
|
-
assert_match %r{:null => false}, output
|
88
|
+
assert_match %r{(:null => false)|(null: false)}, output
|
87
89
|
end
|
88
90
|
|
89
91
|
def test_schema_dump_with_string_ignored_table
|
@@ -108,19 +110,27 @@ module SchemaDumpTestMethods
|
|
108
110
|
output = standard_dump
|
109
111
|
match = output.match(%r{create_table "custom_pk_names"(.*)do})
|
110
112
|
assert_not_nil(match, "nonstandardpk table not found")
|
111
|
-
assert_match %r(:primary_key => "custom_id"), match[1], "non-standard primary key not preserved"
|
113
|
+
assert_match %r((:primary_key => "custom_id")|(primary_key: "custom_id")), match[1], "non-standard primary key not preserved"
|
112
114
|
end
|
113
115
|
|
114
116
|
def test_schema_dump_includes_decimal_options
|
115
117
|
output = standard_dump(StringIO.new, [/^[^d]/]) # keep db_types
|
116
118
|
# t.column :sample_small_decimal, :decimal, :precision => 3, :scale => 2, :default => 3.14
|
117
|
-
|
119
|
+
if ar_version('4.0')
|
120
|
+
assert_match %r{precision: 3,[[:space:]]+scale: 2,[[:space:]]+default: 3.14}, output
|
121
|
+
else
|
122
|
+
assert_match %r{:precision => 3,[[:space:]]+:scale => 2,[[:space:]]+:default => 3.14}, output
|
123
|
+
end
|
118
124
|
end
|
119
125
|
|
120
126
|
def test_schema_dump_keeps_large_precision_integer_columns_as_decimal
|
121
127
|
output = standard_dump
|
122
128
|
precision = DbTypeMigration.big_decimal_precision
|
123
|
-
|
129
|
+
if ar_version('4.0')
|
130
|
+
assert_match %r{t.decimal\s+"big_decimal",\s+precision: #{precision},\s+scale: 0}, output
|
131
|
+
else
|
132
|
+
assert_match %r{t.decimal\s+"big_decimal",\s+:precision => #{precision},\s+:scale => 0}, output
|
133
|
+
end
|
124
134
|
end if Test::Unit::TestCase.ar_version('3.0') # does not work in 2.3 :
|
125
135
|
# t.integer "big_decimal", :limit => 38, :precision => 38, :scale => 0
|
126
136
|
|
@@ -128,13 +138,17 @@ module SchemaDumpTestMethods
|
|
128
138
|
output = standard_dump
|
129
139
|
match = output.match(%r{create_table "string_ids"(.*)do.*\n(.*)\n})
|
130
140
|
assert_not_nil(match, "string_ids table not found")
|
131
|
-
assert_match %r(:id => false), match[1], "no table id not preserved"
|
132
|
-
|
141
|
+
assert_match %r((:id => false)|(id: false)), match[1], "no table id not preserved"
|
142
|
+
if ar_version('4.0')
|
143
|
+
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+null: false$}, match[2], "non-primary key id column not preserved"
|
144
|
+
else
|
145
|
+
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+:null => false$}, match[2], "non-primary key id column not preserved"
|
146
|
+
end
|
133
147
|
end
|
134
148
|
|
135
149
|
def test_schema_dump_keeps_id_false_when_id_is_false_and_unique_not_null_column_added
|
136
150
|
output = standard_dump
|
137
|
-
assert_match %r{create_table "things", :id => false}, output
|
151
|
+
assert_match %r{create_table "things", (:id => false)|(id: false)}, output
|
138
152
|
end
|
139
153
|
|
140
154
|
class CreateDogMigration < ActiveRecord::Migration
|
data/test/simple.rb
CHANGED
@@ -1,12 +1,23 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
require 'set'
|
5
|
+
|
6
|
+
require 'models/data_types'
|
7
|
+
require 'models/entry'
|
8
|
+
require 'models/auto_id'
|
9
|
+
require 'models/string_id'
|
10
|
+
require 'models/thing'
|
11
|
+
require 'models/custom_pk_name'
|
12
|
+
require 'models/validates_uniqueness_of_string'
|
13
|
+
require 'models/add_not_null_column_to_table'
|
14
|
+
|
2
15
|
ActiveRecord::Schema.verbose = false
|
3
16
|
ActiveRecord::Base.time_zone_aware_attributes = true if ActiveRecord::Base.respond_to?(:time_zone_aware_attributes)
|
4
17
|
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
18
|
|
8
19
|
module MigrationSetup
|
9
|
-
|
20
|
+
|
10
21
|
def setup
|
11
22
|
setup!
|
12
23
|
end
|
@@ -50,19 +61,27 @@ end
|
|
50
61
|
module FixtureSetup
|
51
62
|
include MigrationSetup
|
52
63
|
|
64
|
+
@@_time_zone = Time.respond_to?(:zone) ? Time.zone : nil
|
65
|
+
|
53
66
|
def setup
|
54
67
|
super
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
68
|
+
#
|
69
|
+
# just a random zone, unlikely to be local, and not utc
|
70
|
+
Time.zone = 'Moscow' if Time.respond_to?(:zone)
|
71
|
+
#
|
72
|
+
DbType.create!
|
73
|
+
end
|
74
|
+
|
75
|
+
def teardown
|
76
|
+
super
|
77
|
+
#
|
78
|
+
Time.zone = @@_time_zone if Time.respond_to?(:zone)
|
62
79
|
end
|
80
|
+
|
63
81
|
end
|
64
82
|
|
65
83
|
module ColumnNameQuotingTests
|
84
|
+
|
66
85
|
def self.included(base)
|
67
86
|
base.class_eval do
|
68
87
|
@@column_quote_char = "\""
|
@@ -80,16 +99,16 @@ module ColumnNameQuotingTests
|
|
80
99
|
end
|
81
100
|
|
82
101
|
protected
|
102
|
+
|
83
103
|
def column_quote_char
|
84
104
|
@@column_quote_char || "\""
|
85
105
|
end
|
106
|
+
|
86
107
|
end
|
87
108
|
|
88
109
|
module DirtyAttributeTests
|
89
110
|
|
90
111
|
def test_partial_update_with_updated_at
|
91
|
-
#ActiveRecord::Base.logger.level = Logger::DEBUG
|
92
|
-
|
93
112
|
user = User.create!(:login => 'cicina')
|
94
113
|
old_updated_at = 61.minutes.ago.in_time_zone
|
95
114
|
|
@@ -108,12 +127,9 @@ module DirtyAttributeTests
|
|
108
127
|
assert_queries(1) { user.login = 'cicinbrus'; user.save! }
|
109
128
|
assert_datetime_not_equal old_updated_at, user.reload.updated_at
|
110
129
|
end
|
111
|
-
ensure
|
112
|
-
#ActiveRecord::Base.logger.level = Logger::WARN
|
113
130
|
end
|
114
131
|
|
115
132
|
def test_partial_update_with_updated_on
|
116
|
-
#ActiveRecord::Base.logger.level = Logger::DEBUG
|
117
133
|
entry = Entry.create!(:title => 'foo')
|
118
134
|
old_updated_on = 25.hours.ago.beginning_of_day.in_time_zone
|
119
135
|
|
@@ -121,9 +137,10 @@ module DirtyAttributeTests
|
|
121
137
|
|
122
138
|
with_partial_updates Entry, false do
|
123
139
|
assert_queries(2) { 2.times { entry.save! } }
|
124
|
-
Entry.update_all({ :updated_on => old_updated_on }, :id => entry.id)
|
125
140
|
end
|
126
141
|
|
142
|
+
Entry.update_all({ :updated_on => old_updated_on }, :id => entry.id)
|
143
|
+
|
127
144
|
with_partial_updates Entry, true do
|
128
145
|
assert_queries(0) { 2.times { entry.save! } }
|
129
146
|
assert_date_equal old_updated_on, entry.reload.updated_on
|
@@ -131,11 +148,10 @@ module DirtyAttributeTests
|
|
131
148
|
assert_queries(1) { entry.title = 'bar'; entry.save! }
|
132
149
|
assert_date_not_equal old_updated_on, entry.reload.updated_on
|
133
150
|
end
|
134
|
-
ensure
|
135
|
-
#ActiveRecord::Base.logger.level = Logger::WARN
|
136
151
|
end
|
137
|
-
|
152
|
+
|
138
153
|
private
|
154
|
+
|
139
155
|
def with_partial_updates(klass, on = true)
|
140
156
|
old = klass.partial_updates?
|
141
157
|
klass.partial_updates = on
|
@@ -143,17 +159,22 @@ module DirtyAttributeTests
|
|
143
159
|
ensure
|
144
160
|
klass.partial_updates = old
|
145
161
|
end
|
162
|
+
|
146
163
|
end
|
147
164
|
|
148
165
|
module SimpleTestMethods
|
149
166
|
include FixtureSetup
|
150
167
|
|
151
|
-
def
|
152
|
-
|
168
|
+
def test_tables
|
169
|
+
assert_not_empty ActiveRecord::Base.connection.tables
|
170
|
+
tables = ActiveRecord::Base.connection.tables
|
171
|
+
assert tables.find { |t| t =~ /^entries$/i }, "entries not created: #{tables.inspect}"
|
172
|
+
assert tables.map(&:downcase).include?('users'), "users table not found: #{tables.inspect}"
|
153
173
|
end
|
154
174
|
|
155
|
-
def
|
156
|
-
|
175
|
+
def test_table_exists?
|
176
|
+
assert_true ActiveRecord::Base.connection.table_exists? 'entries'
|
177
|
+
assert_false ActiveRecord::Base.connection.table_exists? 'blahbls'
|
157
178
|
end
|
158
179
|
|
159
180
|
def test_entries_empty
|
@@ -168,33 +189,35 @@ module SimpleTestMethods
|
|
168
189
|
end
|
169
190
|
|
170
191
|
def test_insert_returns_id
|
171
|
-
|
172
|
-
|
192
|
+
value = ActiveRecord::Base.connection.insert("INSERT INTO entries (title, content, rating) VALUES('insert_title', 'some content', 1)")
|
193
|
+
assert !value.nil?
|
194
|
+
entry = Entry.find_by_title('insert_title')
|
195
|
+
assert_equal entry.id, value
|
196
|
+
|
197
|
+
# Ensure we get the id even if the PK column is not named 'id'
|
198
|
+
1.upto(4) do |i|
|
199
|
+
cpn_name = "return id test#{i}"
|
200
|
+
cpn = CustomPkName.new
|
201
|
+
cpn.name = cpn_name
|
202
|
+
cpn.save
|
203
|
+
value = cpn.custom_id
|
173
204
|
assert !value.nil?
|
174
|
-
|
175
|
-
assert_equal
|
176
|
-
|
177
|
-
# Ensure we get the id even if the PK column is not named 'id'
|
178
|
-
1.upto(4) do |i|
|
179
|
-
cpn_name = "return id test#{i}"
|
180
|
-
cpn = CustomPkName.new
|
181
|
-
cpn.name = cpn_name
|
182
|
-
cpn.save
|
183
|
-
value = cpn.custom_id
|
184
|
-
assert !value.nil?
|
185
|
-
cpn = CustomPkName.find_by_name(cpn_name)
|
186
|
-
assert_equal cpn.custom_id, value
|
187
|
-
end
|
205
|
+
cpn = CustomPkName.find_by_name(cpn_name)
|
206
|
+
assert_equal cpn.custom_id, value
|
188
207
|
end
|
189
208
|
end
|
190
209
|
|
191
210
|
def test_create_new_entry
|
192
211
|
Entry.delete_all
|
193
212
|
|
213
|
+
title = "First post!"
|
214
|
+
content = "Hello from JRuby on Rails!"
|
215
|
+
rating = 205.76
|
216
|
+
|
194
217
|
post = Entry.new
|
195
|
-
post.title =
|
196
|
-
post.content =
|
197
|
-
post.rating =
|
218
|
+
post.title = title
|
219
|
+
post.content = content
|
220
|
+
post.rating = rating
|
198
221
|
post.save
|
199
222
|
|
200
223
|
assert_equal 1, Entry.count
|
@@ -206,22 +229,33 @@ module SimpleTestMethods
|
|
206
229
|
end
|
207
230
|
|
208
231
|
def test_find_and_update_entry
|
232
|
+
title = "First post!"
|
233
|
+
content = "Hello from JRuby on Rails!"
|
234
|
+
new_title = "First post updated title"
|
235
|
+
rating = 205.76
|
236
|
+
user = User.create! :login => "something"
|
237
|
+
Entry.create! :title => title, :content => content, :rating => rating, :user => user
|
238
|
+
|
209
239
|
post = Entry.first
|
210
|
-
assert_equal
|
211
|
-
assert_equal
|
212
|
-
assert_equal
|
240
|
+
assert_equal title, post.title
|
241
|
+
assert_equal content, post.content
|
242
|
+
assert_equal rating, post.rating
|
213
243
|
|
214
|
-
post.title =
|
244
|
+
post.title = new_title
|
215
245
|
post.save
|
216
246
|
|
217
247
|
post = Entry.first
|
218
|
-
assert_equal
|
248
|
+
assert_equal new_title, post.title
|
219
249
|
end
|
220
250
|
|
221
251
|
def test_destroy_entry
|
252
|
+
user = User.create! :login => "something"
|
253
|
+
Entry.create! :title => '1', :content => '', :rating => 1.0, :user => user
|
254
|
+
Entry.create! :title => '2', :content => '', :rating => 2.0, :user => user
|
255
|
+
|
222
256
|
prev_count = Entry.count
|
223
|
-
|
224
|
-
|
257
|
+
entry = Entry.first
|
258
|
+
entry.destroy
|
225
259
|
|
226
260
|
assert_equal prev_count - 1, Entry.count
|
227
261
|
end
|
@@ -255,7 +289,7 @@ module SimpleTestMethods
|
|
255
289
|
|
256
290
|
def test_save_time_with_zone
|
257
291
|
t = Time.now
|
258
|
-
#precision will only be expected to the second
|
292
|
+
# precision will only be expected to the second :
|
259
293
|
original_time = Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec)
|
260
294
|
time = original_time.in_time_zone
|
261
295
|
e = DbType.first
|
@@ -268,7 +302,7 @@ module SimpleTestMethods
|
|
268
302
|
|
269
303
|
def test_save_date_time
|
270
304
|
t = Time.now
|
271
|
-
#precision will only be expected to the second
|
305
|
+
# precision will only be expected to the second :
|
272
306
|
time = Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec)
|
273
307
|
datetime = time.to_datetime
|
274
308
|
e = DbType.first
|
@@ -326,64 +360,65 @@ module SimpleTestMethods
|
|
326
360
|
e.save!
|
327
361
|
|
328
362
|
e = DbType.first
|
329
|
-
assert_equal
|
363
|
+
assert_equal 12.0, e.sample_float
|
330
364
|
end
|
331
|
-
|
365
|
+
|
332
366
|
def test_boolean
|
333
|
-
# An unset boolean should default to nil
|
334
367
|
e = DbType.first
|
335
|
-
|
368
|
+
assert_nil e.sample_boolean # unset boolean should default to nil
|
336
369
|
|
370
|
+
e.update_attributes :sample_boolean => false
|
371
|
+
|
372
|
+
e = DbType.first
|
373
|
+
assert_equal false, e.sample_boolean
|
374
|
+
|
337
375
|
e.sample_boolean = true
|
338
376
|
e.save!
|
339
377
|
|
340
378
|
e = DbType.first
|
341
|
-
assert_equal
|
379
|
+
assert_equal true, e.sample_boolean
|
342
380
|
end
|
343
381
|
|
344
382
|
def test_integer
|
345
|
-
# An unset boolean should default to nil
|
346
383
|
e = DbType.first
|
347
|
-
|
384
|
+
assert_nil e.sample_integer
|
348
385
|
|
349
386
|
e.sample_integer = 10
|
350
387
|
e.save!
|
351
388
|
|
352
389
|
e = DbType.first
|
353
|
-
assert_equal
|
390
|
+
assert_equal 10, e.sample_integer
|
354
391
|
end
|
355
392
|
|
356
393
|
def test_text
|
357
|
-
# An unset boolean should default to nil
|
358
394
|
e = DbType.first
|
359
|
-
|
360
395
|
assert_null_text e.sample_text
|
361
396
|
|
362
397
|
e.sample_text = "ooop?"
|
363
398
|
e.save!
|
364
399
|
|
365
400
|
e = DbType.first
|
366
|
-
assert_equal
|
401
|
+
assert_equal "ooop?", e.sample_text
|
367
402
|
end
|
368
403
|
|
369
404
|
def test_string
|
370
405
|
e = DbType.first
|
371
|
-
|
372
406
|
assert_empty_string e.sample_string
|
373
407
|
|
374
408
|
e.sample_string = "ooop?"
|
375
409
|
e.save!
|
376
410
|
|
377
411
|
e = DbType.first
|
378
|
-
assert_equal
|
412
|
+
assert_equal "ooop?", e.sample_string
|
379
413
|
end
|
380
414
|
|
381
415
|
def test_save_binary
|
382
|
-
#string is 60_000 bytes
|
416
|
+
# string is 60_000 bytes
|
383
417
|
binary_string = "\000ABCDEFGHIJKLMNOPQRSTUVWXYZ'\001\003" * 1 # 2_000
|
384
418
|
e = DbType.first
|
385
419
|
e.sample_binary = binary_string
|
386
420
|
e.save!
|
421
|
+
|
387
422
|
e = DbType.first
|
388
423
|
assert_equal binary_string, e.sample_binary
|
389
424
|
end
|
@@ -419,23 +454,32 @@ module SimpleTestMethods
|
|
419
454
|
end
|
420
455
|
|
421
456
|
def test_indexes
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
457
|
+
indexes = connection.indexes(:entries)
|
458
|
+
assert_equal 0, indexes.size
|
459
|
+
|
460
|
+
connection.add_index :entries, :updated_on
|
461
|
+
connection.add_index :entries, [ :title, :user_id ], :unique => true,
|
462
|
+
:name => 'x_entries_on_title_and_user_id' # <= 30 chars
|
463
|
+
|
464
|
+
indexes = connection.indexes(:entries)
|
465
|
+
assert_equal 2, indexes.size
|
466
|
+
|
467
|
+
assert_not_nil title_index = indexes.find { |index| index.unique }
|
468
|
+
|
469
|
+
assert_equal "entries", title_index.table.to_s
|
470
|
+
assert_true title_index.unique
|
471
|
+
assert_equal [ 'title', 'user_id' ], title_index.columns
|
472
|
+
|
473
|
+
updated_index = (indexes - [ title_index ]).first
|
474
|
+
|
475
|
+
assert_equal "entries", updated_index.table.to_s
|
476
|
+
assert_equal "index_entries_on_updated_on", updated_index.name
|
477
|
+
assert ! updated_index.unique
|
478
|
+
assert_equal [ 'updated_on' ], updated_index.columns
|
479
|
+
|
480
|
+
connection.remove_index :entries, :updated_on
|
481
|
+
indexes = connection.indexes(:entries)
|
482
|
+
assert_equal 1, indexes.size
|
439
483
|
end
|
440
484
|
|
441
485
|
def test_nil_values
|
@@ -453,14 +497,20 @@ module SimpleTestMethods
|
|
453
497
|
end
|
454
498
|
|
455
499
|
def test_invalid
|
456
|
-
|
500
|
+
title = "First post!"
|
501
|
+
content = "Hello from JRuby on Rails!"
|
502
|
+
rating = 205.76
|
503
|
+
user = User.create! :login => "something"
|
504
|
+
Entry.create! :title => title, :content => content, :rating => rating, :user => user
|
505
|
+
|
506
|
+
e = Entry.new(:title => title, :content => content, :rating => ' ')
|
457
507
|
assert e.valid?
|
458
508
|
end
|
459
509
|
|
460
510
|
def test_reconnect
|
461
|
-
assert_equal 1,
|
511
|
+
assert_equal 1, DbType.count
|
462
512
|
ActiveRecord::Base.connection.reconnect!
|
463
|
-
assert_equal 1,
|
513
|
+
assert_equal 1, DbType.count
|
464
514
|
end
|
465
515
|
|
466
516
|
if defined?(JRUBY_VERSION)
|
@@ -480,20 +530,19 @@ module SimpleTestMethods
|
|
480
530
|
|
481
531
|
class Animal < ActiveRecord::Base; end
|
482
532
|
|
483
|
-
def
|
484
|
-
assert_raise(ActiveRecord::ActiveRecordError,
|
485
|
-
ActiveRecord::StatementInvalid, ActiveRecord::JDBCError) do
|
533
|
+
def test_fetching_columns_for_nonexistent_table
|
534
|
+
assert_raise(ActiveRecord::ActiveRecordError, ActiveRecord::StatementInvalid, ActiveRecord::JDBCError) do
|
486
535
|
Animal.columns
|
487
536
|
end
|
488
537
|
end
|
489
538
|
end
|
490
539
|
|
491
540
|
def test_disconnect
|
492
|
-
assert_equal 1,
|
541
|
+
assert_equal 1, DbType.count
|
493
542
|
ActiveRecord::Base.clear_active_connections!
|
494
543
|
ActiveRecord::Base.connection_pool.disconnect! if ActiveRecord::Base.respond_to?(:connection_pool)
|
495
544
|
assert !ActiveRecord::Base.connected?
|
496
|
-
assert_equal 1,
|
545
|
+
assert_equal 1, DbType.count
|
497
546
|
assert ActiveRecord::Base.connected?
|
498
547
|
end
|
499
548
|
|
@@ -731,7 +780,150 @@ module SimpleTestMethods
|
|
731
780
|
|
732
781
|
assert_equal content_json, post.reload.content
|
733
782
|
end
|
783
|
+
|
784
|
+
def test_exec_insert
|
785
|
+
name_column = Thing.columns.detect { |column| column.name.to_s == 'name' }
|
786
|
+
created_column = Thing.columns.detect { |column| column.name.to_s == 'created_at' }
|
787
|
+
updated_column = Thing.columns.detect { |column| column.name.to_s == 'updated_at' }
|
788
|
+
now = Time.zone.now
|
789
|
+
|
790
|
+
binds = [ [ name_column, 'ferko' ], [ created_column, now ], [ updated_column, now ] ]
|
791
|
+
connection.exec_insert "INSERT INTO things VALUES (?,?,?)", 'INSERT_1', binds
|
792
|
+
assert Thing.find_by_name 'ferko'
|
793
|
+
# NOTE: #exec_insert accepts 5 arguments on AR-4.0 :
|
794
|
+
binds = [ [ name_column, 'jozko' ], [ created_column, now ], [ updated_column, now ] ]
|
795
|
+
connection.exec_insert "INSERT INTO things VALUES (?,?,?)", 'INSERT_2', binds, nil, nil
|
796
|
+
assert Thing.find_by_name 'jozko'
|
797
|
+
end
|
798
|
+
|
799
|
+
def test_exec_query_result
|
800
|
+
Entry.delete_all
|
801
|
+
user1 = User.create! :login => 'user1'
|
802
|
+
user2 = User.create! :login => 'user2'
|
803
|
+
Entry.create! :title => 'user11', :user_id => user1.id
|
804
|
+
Entry.create! :title => 'user12', :user_id => user1.id
|
805
|
+
Entry.create! :title => 'user21', :user_id => user2.id
|
806
|
+
|
807
|
+
result = Entry.connection.exec_query 'SELECT * FROM entries'
|
808
|
+
|
809
|
+
if ar_version('3.1')
|
810
|
+
assert_instance_of ActiveRecord::Result, result
|
811
|
+
assert_not_empty result.columns
|
812
|
+
columns = Entry.columns.map { |column| column.name.to_s }
|
813
|
+
assert_equal Set.new(columns), Set.new(result.columns)
|
814
|
+
|
815
|
+
assert_equal 3, result.rows.size
|
816
|
+
assert_instance_of Array, result.rows[0]
|
817
|
+
assert_equal 'user11', result.rows[0][1]
|
818
|
+
assert_equal 'user12', result.rows[1][1]
|
819
|
+
else
|
820
|
+
assert_instance_of Array, result
|
821
|
+
assert_equal 3, result.size
|
822
|
+
assert_instance_of Hash, result[0]
|
823
|
+
assert_equal 'user11', result[0]['title']
|
824
|
+
assert_equal user1.id, result[0]['user_id']
|
825
|
+
end
|
826
|
+
end
|
827
|
+
|
828
|
+
def test_exec_query_empty_result
|
829
|
+
Entry.delete_all; User.delete_all
|
830
|
+
|
831
|
+
result = User.connection.exec_query 'SELECT * FROM users'
|
832
|
+
|
833
|
+
if ar_version('3.1')
|
834
|
+
assert_instance_of ActiveRecord::Result, result
|
835
|
+
assert_not_empty result.columns
|
836
|
+
columns = User.columns.map { |column| column.name.to_s }
|
837
|
+
assert_equal Set.new(columns), Set.new(result.columns)
|
838
|
+
|
839
|
+
assert_equal 0, result.rows.size
|
840
|
+
else
|
841
|
+
assert_instance_of Array, result
|
842
|
+
assert_equal 0, result.size
|
843
|
+
end
|
844
|
+
end
|
845
|
+
|
846
|
+
def test_exec_query_raw
|
847
|
+
User.delete_all
|
848
|
+
User.create! :login => 'user1'
|
849
|
+
User.create! :login => 'user2'
|
850
|
+
|
851
|
+
result = User.connection.exec_query_raw 'SELECT * FROM users'
|
852
|
+
|
853
|
+
assert_instance_of Array, result
|
854
|
+
assert_equal 2, result.size
|
855
|
+
assert_instance_of Hash, result[0]
|
856
|
+
assert_equal 'user1', result[0]['login']
|
857
|
+
assert_equal 'user2', result[1]['login']
|
858
|
+
end
|
859
|
+
|
860
|
+
def test_select
|
861
|
+
Entry.delete_all
|
862
|
+
user = User.create! :login => 'select'
|
863
|
+
Entry.create! :title => 'title 1', :content => 'content 1', :user_id => user.id, :rating => 1.0
|
864
|
+
Entry.create! :title => 'title 2', :content => 'content 2', :user_id => user.id, :rating => 2.0
|
865
|
+
|
866
|
+
# rows = connection.execute 'SELECT * FROM entries'
|
867
|
+
# column_order = rows.first.keys
|
868
|
+
|
869
|
+
result = connection.select 'SELECT * FROM entries'
|
870
|
+
|
871
|
+
if ar_version('4.0')
|
872
|
+
assert_instance_of ActiveRecord::Result, result
|
873
|
+
assert_equal 2, result.rows.size
|
874
|
+
else
|
875
|
+
assert_instance_of Array, result
|
876
|
+
assert_equal 2, result.size
|
877
|
+
end
|
878
|
+
end
|
734
879
|
|
880
|
+
def test_select_rows
|
881
|
+
Entry.delete_all
|
882
|
+
user = User.create! :login => 'select_rows'
|
883
|
+
Entry.create! :title => 'title 1', :content => 'content 1', :user_id => user.id
|
884
|
+
Entry.create! :title => 'title 2', :content => 'content 2', :user_id => user.id, :rating => 1.0
|
885
|
+
|
886
|
+
rows = connection.execute 'SELECT * FROM entries'
|
887
|
+
column_order = rows.first.keys
|
888
|
+
|
889
|
+
rows = connection.select_rows 'SELECT * FROM entries'
|
890
|
+
assert_instance_of Array, rows
|
891
|
+
assert_equal 2, rows.size
|
892
|
+
|
893
|
+
row = rows[0]
|
894
|
+
column_order.each_with_index do |column, i|
|
895
|
+
case column.to_s
|
896
|
+
when 'id' then assert_not_nil row[i]
|
897
|
+
when 'title' then assert_equal 'title 1', row[i]
|
898
|
+
when 'content' then assert_equal 'content 1', row[i]
|
899
|
+
when 'user_id' then assert_equal user.id, row[i]
|
900
|
+
when 'rating' then assert_nil row[i]
|
901
|
+
when 'updated_on' then assert_not_nil row[i]
|
902
|
+
else raise "unexpected entries row: #{column.inspect}"
|
903
|
+
end
|
904
|
+
end
|
905
|
+
|
906
|
+
row = rows[1]
|
907
|
+
column_order.each_with_index do |column, i|
|
908
|
+
case column.to_s
|
909
|
+
when 'id' then assert_not_nil row[i]
|
910
|
+
when 'title' then assert_equal 'title 2', row[i]
|
911
|
+
when 'content' then assert_equal 'content 2', row[i]
|
912
|
+
when 'user_id' then assert_equal user.id, row[i]
|
913
|
+
when 'rating' then assert_not_nil row[i]
|
914
|
+
when 'updated_on' then assert_not_nil row[i]
|
915
|
+
else raise "unexpected entries row: #{column.inspect}"
|
916
|
+
end
|
917
|
+
end
|
918
|
+
end
|
919
|
+
|
920
|
+
def test_connection_alive_sql
|
921
|
+
connection = ActiveRecord::Base.connection
|
922
|
+
alive_sql = connection.config[:connection_alive_sql]
|
923
|
+
assert_not_nil alive_sql, "no :connection_alive_sql for #{connection}"
|
924
|
+
connection.execute alive_sql
|
925
|
+
end
|
926
|
+
|
735
927
|
protected
|
736
928
|
|
737
929
|
def assert_date_type(value)
|
@@ -822,32 +1014,65 @@ end
|
|
822
1014
|
module XmlColumnTests
|
823
1015
|
|
824
1016
|
def self.included(base)
|
825
|
-
base.send :include,
|
826
|
-
(ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR >= 1)
|
1017
|
+
base.send :include, TestMethods if base.ar_version('3.1')
|
827
1018
|
end
|
828
1019
|
|
829
|
-
|
1020
|
+
class XmlModel < ActiveRecord::Base; end
|
1021
|
+
|
1022
|
+
module TestMethods
|
830
1023
|
|
831
1024
|
def test_create_xml_column
|
832
|
-
|
833
|
-
t.xml :xml_test
|
834
|
-
end
|
1025
|
+
create_xml_models!
|
835
1026
|
|
836
|
-
xml_column = connection.columns(:
|
837
|
-
c.name == "
|
1027
|
+
xml_column = connection.columns(:xml_models).detect do |c|
|
1028
|
+
c.name == "xml_col"
|
838
1029
|
end
|
839
1030
|
|
840
|
-
|
1031
|
+
assert_xml_type xml_column.sql_type
|
1032
|
+
ensure
|
1033
|
+
drop_xml_models! rescue false
|
1034
|
+
end
|
1035
|
+
|
1036
|
+
def test_use_xml_column
|
1037
|
+
if created = ( ( create_xml_models! || true ) rescue nil )
|
1038
|
+
|
1039
|
+
XmlModel.create! :xml_col => "<xml><LoVE><![CDATA[Rubyist's <3 XML!]]></LoVE></xml>"
|
1040
|
+
|
1041
|
+
assert xml_model = XmlModel.first
|
1042
|
+
|
1043
|
+
unless xml_sql_type =~ /text/i
|
1044
|
+
require 'rexml/document'
|
1045
|
+
doc = REXML::Document.new xml_model.xml_col
|
1046
|
+
assert_equal "Rubyist's <3 XML!", doc.root.elements.first.text
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
else
|
1050
|
+
puts "test_use_xml_column skipped"
|
1051
|
+
end
|
841
1052
|
ensure
|
842
|
-
|
1053
|
+
drop_xml_models! if created
|
843
1054
|
end
|
844
1055
|
|
845
1056
|
protected
|
846
1057
|
|
1058
|
+
def assert_xml_type sql_type
|
1059
|
+
assert_equal xml_sql_type, sql_type
|
1060
|
+
end
|
1061
|
+
|
847
1062
|
def xml_sql_type
|
848
1063
|
'text'
|
849
1064
|
end
|
850
1065
|
|
1066
|
+
private
|
1067
|
+
|
1068
|
+
def create_xml_models!
|
1069
|
+
connection.create_table(:xml_models) { |t| t.xml :xml_col }
|
1070
|
+
end
|
1071
|
+
|
1072
|
+
def drop_xml_models!
|
1073
|
+
connection.drop_table(:xml_models)
|
1074
|
+
end
|
1075
|
+
|
851
1076
|
end
|
852
1077
|
|
853
1078
|
end
|
@@ -855,10 +1080,10 @@ end
|
|
855
1080
|
module ActiveRecord3TestMethods
|
856
1081
|
|
857
1082
|
def self.included(base)
|
858
|
-
base.send :include,
|
1083
|
+
base.send :include, TestMethods if base.ar_version('3.0')
|
859
1084
|
end
|
860
1085
|
|
861
|
-
module
|
1086
|
+
module TestMethods
|
862
1087
|
|
863
1088
|
def test_visitor_accessor
|
864
1089
|
adapter = Entry.connection
|
@@ -869,8 +1094,11 @@ module ActiveRecord3TestMethods
|
|
869
1094
|
end if Test::Unit::TestCase.ar_version('3.2') # >= 3.2
|
870
1095
|
|
871
1096
|
def test_where
|
872
|
-
|
873
|
-
|
1097
|
+
user = User.create! :login => "blogger"
|
1098
|
+
entry = Entry.create! :title => 'something', :content => 'JRuby on Rails !', :rating => 42.1, :user => user
|
1099
|
+
|
1100
|
+
entries = Entry.where(:title => entry.title)
|
1101
|
+
assert_equal entry, entries.first
|
874
1102
|
end
|
875
1103
|
|
876
1104
|
def test_remove_nonexistent_index
|
@@ -892,6 +1120,7 @@ module ActiveRecord3TestMethods
|
|
892
1120
|
end
|
893
1121
|
assert_equal 1, Thing.find(:all).size
|
894
1122
|
end
|
1123
|
+
|
895
1124
|
end
|
896
1125
|
|
897
1126
|
end
|
@@ -986,3 +1215,29 @@ module ExplainSupportTestMethods
|
|
986
1215
|
end
|
987
1216
|
|
988
1217
|
end
|
1218
|
+
|
1219
|
+
module CustomSelectTestMethods
|
1220
|
+
|
1221
|
+
def test_custom_select_float
|
1222
|
+
model = DbType.create! :sample_float => 1.42
|
1223
|
+
if ActiveRecord::VERSION::MAJOR >= 3
|
1224
|
+
model = DbType.where("id = #{model.id}").select('sample_float AS custom_sample_float').first
|
1225
|
+
else
|
1226
|
+
model = DbType.find(:first, :conditions => "id = #{model.id}", :select => 'sample_float AS custom_sample_float')
|
1227
|
+
end
|
1228
|
+
assert_equal 1.42, model.custom_sample_float
|
1229
|
+
assert_instance_of Float, model.custom_sample_float
|
1230
|
+
end
|
1231
|
+
|
1232
|
+
def test_custom_select_decimal
|
1233
|
+
model = DbType.create! :sample_small_decimal => ( decimal = BigDecimal.new('5.45') )
|
1234
|
+
if ActiveRecord::VERSION::MAJOR >= 3
|
1235
|
+
model = DbType.where("id = #{model.id}").select('sample_small_decimal AS custom_decimal').first
|
1236
|
+
else
|
1237
|
+
model = DbType.find(:first, :conditions => "id = #{model.id}", :select => 'sample_small_decimal AS custom_decimal')
|
1238
|
+
end
|
1239
|
+
assert_equal decimal, model.custom_decimal
|
1240
|
+
assert_instance_of BigDecimal, model.custom_decimal
|
1241
|
+
end
|
1242
|
+
|
1243
|
+
end
|