activerecord-jdbc-adapter 0.9.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/History.txt +163 -0
  2. data/Manifest.txt +130 -65
  3. data/README.txt +64 -72
  4. data/lib/active_record/connection_adapters/derby_adapter.rb +1 -13
  5. data/lib/active_record/connection_adapters/h2_adapter.rb +1 -13
  6. data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -13
  7. data/lib/active_record/connection_adapters/informix_adapter.rb +1 -1
  8. data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -633
  9. data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -1
  10. data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
  11. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
  12. data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -13
  13. data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -1
  14. data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -13
  15. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -13
  16. data/lib/activerecord-jdbc-adapter.rb +6 -0
  17. data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
  18. data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
  19. data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
  20. data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
  21. data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
  22. data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
  23. data/lib/arel/visitors/db2.rb +15 -0
  24. data/lib/arel/visitors/derby.rb +19 -0
  25. data/lib/arel/visitors/hsqldb.rb +24 -0
  26. data/lib/arel/visitors/mssql.rb +44 -0
  27. data/lib/arjdbc.rb +29 -0
  28. data/lib/arjdbc/db2.rb +2 -0
  29. data/lib/arjdbc/db2/adapter.rb +413 -0
  30. data/lib/arjdbc/derby.rb +7 -0
  31. data/lib/{jdbc_adapter/jdbc_derby.rb → arjdbc/derby/adapter.rb} +58 -132
  32. data/lib/arjdbc/derby/connection_methods.rb +18 -0
  33. data/lib/arjdbc/discover.rb +92 -0
  34. data/lib/arjdbc/firebird.rb +2 -0
  35. data/lib/{jdbc_adapter/jdbc_firebird.rb → arjdbc/firebird/adapter.rb} +36 -14
  36. data/lib/arjdbc/h2.rb +4 -0
  37. data/lib/arjdbc/h2/adapter.rb +36 -0
  38. data/lib/arjdbc/h2/connection_methods.rb +12 -0
  39. data/lib/arjdbc/hsqldb.rb +4 -0
  40. data/lib/{jdbc_adapter/jdbc_hsqldb.rb → arjdbc/hsqldb/adapter.rb} +34 -62
  41. data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
  42. data/lib/arjdbc/informix.rb +3 -0
  43. data/lib/{jdbc_adapter/jdbc_informix.rb → arjdbc/informix/adapter.rb} +10 -19
  44. data/lib/arjdbc/informix/connection_methods.rb +10 -0
  45. data/lib/arjdbc/jdbc.rb +2 -0
  46. data/lib/arjdbc/jdbc/adapter.rb +285 -0
  47. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  48. data/lib/arjdbc/jdbc/callbacks.rb +44 -0
  49. data/lib/arjdbc/jdbc/column.rb +38 -0
  50. data/lib/arjdbc/jdbc/compatibility.rb +51 -0
  51. data/lib/arjdbc/jdbc/connection.rb +128 -0
  52. data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
  53. data/lib/arjdbc/jdbc/core_ext.rb +24 -0
  54. data/lib/arjdbc/jdbc/discover.rb +18 -0
  55. data/lib/arjdbc/jdbc/driver.rb +44 -0
  56. data/lib/arjdbc/jdbc/extension.rb +47 -0
  57. data/lib/arjdbc/jdbc/java.rb +14 -0
  58. data/lib/{jdbc_adapter → arjdbc/jdbc}/jdbc.rake +36 -26
  59. data/lib/{jdbc_adapter → arjdbc/jdbc}/missing_functionality_helper.rb +5 -5
  60. data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
  61. data/lib/arjdbc/jdbc/railtie.rb +9 -0
  62. data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
  63. data/lib/arjdbc/jdbc/require_driver.rb +16 -0
  64. data/lib/arjdbc/jdbc/type_converter.rb +126 -0
  65. data/lib/arjdbc/mimer.rb +2 -0
  66. data/lib/{jdbc_adapter/jdbc_mimer.rb → arjdbc/mimer/adapter.rb} +17 -16
  67. data/lib/arjdbc/mssql.rb +4 -0
  68. data/lib/arjdbc/mssql/adapter.rb +472 -0
  69. data/lib/arjdbc/mssql/connection_methods.rb +30 -0
  70. data/lib/arjdbc/mssql/limit_helpers.rb +92 -0
  71. data/lib/{jdbc_adapter → arjdbc/mssql}/tsql_helper.rb +2 -1
  72. data/lib/arjdbc/mysql.rb +4 -0
  73. data/lib/arjdbc/mysql/adapter.rb +416 -0
  74. data/lib/arjdbc/mysql/connection_methods.rb +27 -0
  75. data/lib/arjdbc/oracle.rb +3 -0
  76. data/lib/{jdbc_adapter/jdbc_oracle.rb → arjdbc/oracle/adapter.rb} +68 -33
  77. data/lib/arjdbc/oracle/connection_methods.rb +11 -0
  78. data/lib/arjdbc/postgresql.rb +4 -0
  79. data/lib/{jdbc_adapter/jdbc_postgre.rb → arjdbc/postgresql/adapter.rb} +147 -72
  80. data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
  81. data/lib/arjdbc/sqlite3.rb +4 -0
  82. data/lib/arjdbc/sqlite3/adapter.rb +381 -0
  83. data/lib/arjdbc/sqlite3/connection_methods.rb +34 -0
  84. data/lib/arjdbc/sybase.rb +2 -0
  85. data/lib/arjdbc/sybase/adapter.rb +46 -0
  86. data/lib/arjdbc/version.rb +8 -0
  87. data/lib/generators/jdbc/jdbc_generator.rb +9 -0
  88. data/lib/jdbc_adapter.rb +2 -27
  89. data/lib/jdbc_adapter/rake_tasks.rb +3 -10
  90. data/lib/jdbc_adapter/version.rb +3 -5
  91. data/lib/pg.rb +23 -1
  92. data/rails_generators/jdbc_generator.rb +2 -2
  93. data/rails_generators/templates/{jdbc.rb → config/initializers/jdbc.rb} +1 -1
  94. data/rails_generators/templates/{jdbc.rake → lib/tasks/jdbc.rake} +2 -2
  95. data/rakelib/compile.rake +5 -3
  96. data/rakelib/db.rake +19 -0
  97. data/rakelib/package.rake +12 -6
  98. data/rakelib/test.rake +24 -14
  99. data/src/java/{jdbc_adapter/JdbcDerbySpec.java → arjdbc/derby/DerbyModule.java} +63 -34
  100. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
  101. data/src/java/{jdbc_adapter/MssqlRubyJdbcConnection.java → arjdbc/informix/InformixRubyJdbcConnection.java} +15 -12
  102. data/src/java/{jdbc_adapter/JdbcAdapterInternalService.java → arjdbc/jdbc/AdapterJavaService.java} +21 -8
  103. data/src/java/{jdbc_adapter → arjdbc/jdbc}/JdbcConnectionFactory.java +6 -6
  104. data/src/java/{jdbc_adapter → arjdbc/jdbc}/RubyJdbcConnection.java +210 -67
  105. data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
  106. data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
  107. data/src/java/{jdbc_adapter/JdbcMySQLSpec.java → arjdbc/mysql/MySQLModule.java} +12 -12
  108. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +87 -0
  109. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
  110. data/src/java/{jdbc_adapter/PostgresRubyJdbcConnection.java → arjdbc/postgresql/PostgresqlRubyJdbcConnection.java} +11 -9
  111. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
  112. data/test/abstract_db_create.rb +98 -19
  113. data/test/activerecord/connection_adapters/type_conversion_test.rb +1 -1
  114. data/test/db/db2.rb +4 -2
  115. data/test/db/derby.rb +12 -14
  116. data/test/db/hsqldb.rb +3 -2
  117. data/test/db/jndi_config.rb +22 -12
  118. data/test/db/mssql.rb +5 -5
  119. data/test/db/sqlite3.rb +2 -6
  120. data/test/db2_simple_test.rb +56 -0
  121. data/test/derby_migration_test.rb +50 -3
  122. data/test/derby_simple_test.rb +87 -0
  123. data/test/generic_jdbc_connection_test.rb +21 -1
  124. data/test/h2_simple_test.rb +35 -0
  125. data/test/jdbc_common.rb +4 -5
  126. data/test/jndi_callbacks_test.rb +3 -1
  127. data/test/jndi_test.rb +1 -11
  128. data/test/models/entry.rb +20 -0
  129. data/test/models/mixed_case.rb +7 -2
  130. data/test/models/string_id.rb +18 -0
  131. data/test/mssql_db_create_test.rb +26 -0
  132. data/test/mssql_identity_insert_test.rb +19 -0
  133. data/test/mssql_legacy_types_test.rb +58 -0
  134. data/test/mssql_limit_offset_test.rb +136 -0
  135. data/test/mssql_multibyte_test.rb +18 -0
  136. data/test/mssql_simple_test.rb +49 -0
  137. data/test/mysql_db_create_test.rb +8 -6
  138. data/test/mysql_info_test.rb +123 -0
  139. data/test/mysql_simple_test.rb +19 -1
  140. data/test/oracle_simple_test.rb +9 -20
  141. data/test/oracle_specific_test.rb +83 -0
  142. data/test/pick_rails_version.rb +3 -0
  143. data/test/postgres_db_create_test.rb +11 -0
  144. data/test/postgres_drop_db_test.rb +16 -0
  145. data/test/postgres_mixed_case_test.rb +11 -1
  146. data/test/postgres_nonseq_pkey_test.rb +0 -2
  147. data/test/postgres_schema_search_path_test.rb +44 -0
  148. data/test/postgres_simple_test.rb +53 -0
  149. data/test/postgres_table_alias_length_test.rb +15 -0
  150. data/test/simple.rb +103 -9
  151. data/test/sqlite3_simple_test.rb +1 -0
  152. data/test/sybase_jtds_simple_test.rb +22 -0
  153. metadata +239 -137
  154. data/lib/active_record/connection_adapters/cachedb_adapter.rb +0 -1
  155. data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +0 -26
  156. data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
  157. data/lib/jdbc_adapter/jdbc_cachedb.rb +0 -33
  158. data/lib/jdbc_adapter/jdbc_db2.rb +0 -191
  159. data/lib/jdbc_adapter/jdbc_mssql.rb +0 -333
  160. data/lib/jdbc_adapter/jdbc_mysql.rb +0 -236
  161. data/lib/jdbc_adapter/jdbc_sqlite3.rb +0 -379
  162. data/lib/jdbc_adapter/jdbc_sybase.rb +0 -50
  163. data/src/java/jdbc_adapter/SQLBlock.java +0 -27
  164. data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +0 -41
  165. data/test/cachedb_simple_test.rb +0 -6
  166. data/test/db/cachedb.rb +0 -9
  167. data/test/jdbc_adapter/jdbc_db2_test.rb +0 -26
  168. data/test/jdbc_adapter/jdbc_sybase_test.rb +0 -33
  169. data/test/minirunit.rb +0 -109
  170. data/test/minirunit/testConnect.rb +0 -14
  171. data/test/minirunit/testH2.rb +0 -73
  172. data/test/minirunit/testHsqldb.rb +0 -73
  173. data/test/minirunit/testLoadActiveRecord.rb +0 -3
  174. data/test/minirunit/testMysql.rb +0 -83
  175. data/test/minirunit/testRawSelect.rb +0 -24
@@ -0,0 +1,18 @@
1
+ #! /usr/bin/env jruby
2
+
3
+ require 'jdbc_common'
4
+ require 'db/mssql'
5
+
6
+ class MsSQLMultibyteTest < Test::Unit::TestCase
7
+
8
+ include MultibyteTestMethods
9
+
10
+ def test_select_multibyte_string
11
+ Entry.create!(:title => 'テスト', :content => '本文')
12
+ entry = Entry.find(:last)
13
+ assert_equal "テスト", entry.title
14
+ assert_equal "本文", entry.content
15
+ assert_equal entry, Entry.find_by_title("テスト")
16
+ end
17
+
18
+ end
@@ -2,5 +2,54 @@ require 'jdbc_common'
2
2
  require 'db/mssql'
3
3
 
4
4
  class MsSQLSimpleTest < Test::Unit::TestCase
5
+
5
6
  include SimpleTestMethods
7
+
8
+ # MS SQL 2005 doesn't have a DATE class, only TIMESTAMP.
9
+ undef_method :test_save_date
10
+
11
+ # String comparisons are insensitive by default
12
+ undef_method :test_validates_uniqueness_of_strings_case_sensitive
13
+
14
+ def test_does_not_munge_quoted_strings
15
+ example_quoted_values = [%{'quoted'}, %{D\'oh!}]
16
+ example_quoted_values.each do |value|
17
+ entry = Entry.create!(:title => value)
18
+ entry.reload
19
+ assert_equal(value, entry.title)
20
+ end
21
+ end
22
+
23
+ def test_change_column_default
24
+
25
+ Entry.connection.change_column "entries", "title", :string, :default => "new default"
26
+ Entry.reset_column_information
27
+ assert_equal("new default", Entry.new.title)
28
+
29
+ Entry.connection.change_column "entries", "title", :string, :default => nil
30
+ Entry.reset_column_information
31
+ assert_equal(nil, Entry.new.title)
32
+
33
+ end
34
+
35
+ def test_change_column_nullability
36
+
37
+ Entry.connection.change_column "entries", "title", :string, :null => true
38
+ Entry.reset_column_information
39
+ title_column = Entry.columns.find { |c| c.name == "title" }
40
+ assert(title_column.null)
41
+
42
+ Entry.connection.change_column "entries", "title", :string, :null => false
43
+ Entry.reset_column_information
44
+ title_column = Entry.columns.find { |c| c.name == "title" }
45
+ assert(!title_column.null)
46
+
47
+ end
48
+
49
+ # ACTIVERECORD_JDBC-124
50
+ def test_model_does_not_have_row_num_column
51
+ entry = Entry.first
52
+ assert !entry.attributes.keys.include?("_row_num")
53
+ assert !entry.respond_to?(:_row_num)
54
+ end
6
55
  end
@@ -8,9 +8,9 @@ class MysqlDbCreateTest < Test::Unit::TestCase
8
8
  MYSQL_CONFIG
9
9
  end
10
10
 
11
- if find_executable?("mysql")
12
- def test_rake_db_create
13
- Rake::Task["db:create"].invoke
11
+ def test_rake_db_create
12
+ Rake::Task["db:create"].invoke
13
+ if find_executable?("mysql")
14
14
  output = nil
15
15
  IO.popen("mysql -u #{MYSQL_CONFIG[:username]} --password=#{MYSQL_CONFIG[:password]}", "r+") do |mysql|
16
16
  mysql << "show databases where `Database` = '#{@db_name}';"
@@ -18,8 +18,10 @@ class MysqlDbCreateTest < Test::Unit::TestCase
18
18
  assert mysql.read =~ /#{@db_name}/m
19
19
  end
20
20
  end
21
- else
22
- def test_skipped
23
- end
21
+ end
22
+
23
+ def test_rake_db_test_purge
24
+ Rake::Task["db:create"].invoke
25
+ Rake::Task["db:test:purge"].invoke
24
26
  end
25
27
  end
@@ -0,0 +1,123 @@
1
+ require 'jdbc_common'
2
+ require 'db/mysql'
3
+ begin; require 'active_support/core_ext/numeric/bytes'; rescue LoadError; end
4
+
5
+ class DBSetup < ActiveRecord::Migration
6
+
7
+ def self.up
8
+ create_table :books do |t|
9
+ t.string :title
10
+ t.timestamps
11
+ end
12
+
13
+ create_table :cars, :primary_key => 'legacy_id' do |t|
14
+ t.string :name
15
+ t.date :production_started_on
16
+ end
17
+
18
+ create_table :cats, :id => false do |t|
19
+ t.string :name
20
+ end
21
+
22
+ create_table :memos do |t|
23
+ t.text :text, :limit => 16.megabytes
24
+ end
25
+ end
26
+
27
+ def self.down
28
+ drop_table :books
29
+ drop_table :cars
30
+ drop_table :cats
31
+ drop_table :memos
32
+ end
33
+
34
+ end
35
+
36
+ class MysqlInfoTest < Test::Unit::TestCase
37
+
38
+ def setup
39
+ DBSetup.up
40
+ @connection = ActiveRecord::Base.connection
41
+ end
42
+
43
+ def teardown
44
+ DBSetup.down
45
+ end
46
+
47
+ ## primary_key
48
+ def test_should_return_the_primary_key_of_a_table
49
+ assert_equal 'id', @connection.primary_key('books')
50
+ end
51
+
52
+ def test_should_be_able_to_return_a_custom_primary_key
53
+ assert_equal 'legacy_id', @connection.primary_key('cars')
54
+ end
55
+
56
+ def test_should_return_nil_for_a_table_without_a_primary_key
57
+ assert_nil @connection.primary_key('cats')
58
+ end
59
+
60
+ ## structure_dump
61
+ def test_should_include_the_tables_in_a_structure_dump
62
+ # TODO: Improve these tests, I added this one because no other tests exists for this method.
63
+ dump = @connection.structure_dump
64
+ assert dump.include?('CREATE TABLE `books`')
65
+ assert dump.include?('CREATE TABLE `cars`')
66
+ assert dump.include?('CREATE TABLE `cats`')
67
+ assert dump.include?('CREATE TABLE `memos`')
68
+ end
69
+
70
+ def test_should_include_longtext_in_schema_dump
71
+ strio = StringIO.new
72
+ ActiveRecord::SchemaDumper::dump(@connection, strio)
73
+ dump = strio.string
74
+ assert_match %r{t.text\s+"text",\s+:limit => 2147483647$}, dump
75
+ end
76
+
77
+ # JRUBY-5040
78
+ def test_schema_dump_should_not_have_limits_on_datetime
79
+ strio = StringIO.new
80
+ ActiveRecord::SchemaDumper::dump(@connection, strio)
81
+ dump = strio.string
82
+ dump.grep(/datetime/).each {|line| assert line !~ /limit/ }
83
+ end
84
+
85
+ def test_schema_dump_should_not_have_limits_on_date
86
+ strio = StringIO.new
87
+ ActiveRecord::SchemaDumper::dump(@connection, strio)
88
+ dump = strio.string
89
+ dump.grep(/date/).each {|line| assert line !~ /limit/ }
90
+ end
91
+
92
+ def test_should_include_limit
93
+ text_column = @connection.columns('memos').find { |c| c.name == 'text' }
94
+ assert_equal 2147483647, text_column.limit
95
+ end
96
+
97
+ def test_should_set_sqltype_to_longtext
98
+ text_column = @connection.columns('memos').find { |c| c.name == 'text' }
99
+ assert text_column.sql_type =~ /^longtext/i
100
+ end
101
+
102
+ def test_should_set_type_to_text
103
+ text_column = @connection.columns('memos').find { |c| c.name == 'text' }
104
+ assert_equal :text, text_column.type
105
+ end
106
+
107
+ def test_verify_url_has_options
108
+ url = @connection.config[:url]
109
+ assert url =~ /characterEncoding=utf8/
110
+ assert url =~ /useUnicode=true/
111
+ assert url =~ /zeroDateTimeBehavior=convertToNull/
112
+ end
113
+
114
+ def test_no_limits_for_some_data_types
115
+ DbTypeMigration.up
116
+ strio = StringIO.new
117
+ ActiveRecord::SchemaDumper.dump(@connection, strio)
118
+ dump_lines = strio.string
119
+ assert_nil dump_lines.find {|l| l =~ /\.(float|date|datetime|integer|time|timestamp) .* :limit/ && l !~ /sample_integer/ }
120
+ ensure
121
+ DbTypeMigration.down
122
+ end
123
+ end
@@ -10,6 +10,7 @@ require 'db/mysql'
10
10
 
11
11
  class MysqlSimpleTest < Test::Unit::TestCase
12
12
  include SimpleTestMethods
13
+ include ActiveRecord3TestMethods
13
14
 
14
15
  def test_string_quoting_oddity
15
16
  s = "0123456789a'a"
@@ -24,8 +25,25 @@ class MysqlSimpleTest < Test::Unit::TestCase
24
25
  s = "weblog_development.posts"
25
26
  assert_equal "`weblog_development`.`posts`", ActiveRecord::Base.connection.quote_table_name(s)
26
27
  end
28
+
29
+ def test_update_all_with_limit
30
+ assert_nothing_raised { Entry.update_all({:title => "test"}, {}, {:limit => 1}) }
31
+ end
32
+
33
+ def test_find_in_other_schema_with_include
34
+ old_entries_table_name = Entry.table_name
35
+ old_users_table_name = User.table_name
36
+ begin
37
+ User.set_table_name 'weblog_development.users'
38
+ Entry.set_table_name 'weblog_development.entries'
39
+ assert !Entry.all(:include => :user).empty?
40
+ ensure
41
+ Entry.set_table_name old_entries_table_name
42
+ User.set_table_name old_users_table_name
43
+ end
44
+ end
27
45
  end
28
46
 
29
47
  class MysqlHasManyThroughTest < Test::Unit::TestCase
30
48
  include HasManyThroughMethods
31
- end
49
+ end
@@ -3,27 +3,16 @@ require 'db/oracle'
3
3
 
4
4
  class OracleSimpleTest < Test::Unit::TestCase
5
5
  include SimpleTestMethods
6
- end
7
-
8
- class OracleSpecificTest < Test::Unit::TestCase
9
- include MultibyteTestMethods
10
-
11
- def setup
12
- super
13
- @java_con.createStatement.execute "CREATE TABLE DEFAULT_NUMBER (VALUE NUMBER)"
14
- @java_con.createStatement.execute "INSERT INTO DEFAULT_NUMBER (VALUE) VALUES (0.076)"
15
- end
16
6
 
17
- def teardown
18
- @java_con.createStatement.execute "DROP TABLE DEFAULT_NUMBER"
19
- super
7
+ def test_default_id_type_is_integer
8
+ assert Integer === Entry.first.id
20
9
  end
21
10
 
22
-
23
- def test_default_number_precision
24
- klass = Class.new(ActiveRecord::Base)
25
- klass.set_table_name "DEFAULT_NUMBER"
26
- obj = klass.find(:first)
27
- assert_equal 0.076, obj.value
11
+ def test_sequences_are_not_cached
12
+ ActiveRecord::Base.transaction do
13
+ e1 = Entry.create :title => "hello1"
14
+ e2 = Entry.create :title => "hello2"
15
+ assert e1.id != e2.id
16
+ end
28
17
  end
29
- end if defined?(JRUBY_VERSION)
18
+ end
@@ -0,0 +1,83 @@
1
+ require 'jdbc_common'
2
+ require 'db/oracle'
3
+
4
+ class DefaultNumber < ActiveRecord::Base
5
+ end
6
+
7
+ class OracleSpecificTest < Test::Unit::TestCase
8
+ include MultibyteTestMethods # so we can get @java_con
9
+
10
+ def setup
11
+ super
12
+ @java_con.createStatement.execute "
13
+ CREATE TABLE DEFAULT_NUMBERS (
14
+ ID INTEGER NOT NULL PRIMARY KEY, VALUE NUMBER, DATUM DATE, FPOINT NUMBER(10,2), VALUE2 NUMBER(15)
15
+ )"
16
+ @java_con.createStatement.execute "
17
+ INSERT INTO DEFAULT_NUMBERS (ID, VALUE, DATUM, FPOINT, VALUE2)
18
+ VALUES (1, 0.076, TIMESTAMP'2009-11-05 00:00:00', 1000.01, 1234)"
19
+ @java_con.createStatement.execute "CREATE SYNONYM POSTS FOR ENTRIES"
20
+ end
21
+
22
+ def teardown
23
+ @java_con.createStatement.execute "DROP TABLE DEFAULT_NUMBERS"
24
+ @java_con.createStatement.execute "DROP SYNONYM POSTS"
25
+ super
26
+ end
27
+
28
+ def test_default_number_precision
29
+ assert_equal 0.076, DefaultNumber.find(:first).value
30
+ end
31
+
32
+ def test_number_with_precision_and_scale
33
+ assert_equal 1000.01, DefaultNumber.find(:first).fpoint
34
+ end
35
+
36
+ def test_number_with_precision
37
+ assert_equal 1234, DefaultNumber.find(:first).value2
38
+ end
39
+
40
+ def test_number_type_with_precision_and_scale_is_reported_correctly
41
+ assert_equal 'NUMBER', DefaultNumber.columns_hash['value'].sql_type
42
+ assert_equal 'NUMBER(10,2)', DefaultNumber.columns_hash['fpoint'].sql_type
43
+ assert_equal 'NUMBER(15)', DefaultNumber.columns_hash['value2'].sql_type
44
+ end
45
+
46
+ # JRUBY-3675, ACTIVERECORD_JDBC-22
47
+ def test_load_date
48
+ obj = DefaultNumber.find(:first)
49
+ assert_not_nil obj.datum, "no date"
50
+ end
51
+
52
+ # ACTIVERECORD_JDBC-127
53
+ def test_save_date
54
+ obj = DefaultNumber.find(:first)
55
+ obj.datum = '01Jan2010'
56
+ obj.save!
57
+ end
58
+
59
+ def test_save_timestamp
60
+ obj = DefaultNumber.find(:first)
61
+ obj.datum = Time.now
62
+ obj.save!
63
+ end
64
+
65
+ def test_load_null_date
66
+ @java_con.createStatement.execute "UPDATE DEFAULT_NUMBERS SET DATUM = NULL"
67
+ obj = DefaultNumber.find(:first)
68
+ assert obj.datum.nil?
69
+ end
70
+
71
+ def test_model_access_by_synonym
72
+ @klass = Class.new(ActiveRecord::Base)
73
+ @klass.set_table_name "POSTS"
74
+ entry_columns = Entry.columns_hash
75
+ @klass.columns.each do |c|
76
+ ec = entry_columns[c.name]
77
+ assert ec
78
+ assert_equal ec.sql_type, c.sql_type
79
+ assert_equal ec.type, c.type
80
+ end
81
+ end
82
+
83
+ end if defined?(JRUBY_VERSION)
@@ -0,0 +1,3 @@
1
+ # Specify version of activerecord with ENV['AR_VERSION'] if desired
2
+ gem 'rails', ENV['AR_VERSION'] if ENV['AR_VERSION']
3
+ require 'active_record/version'
@@ -14,8 +14,19 @@ class PostgresDbCreateTest < Test::Unit::TestCase
14
14
  output = `psql -c '\\l'`
15
15
  assert output =~ /#{@db_name}/m
16
16
  end
17
+
18
+ def test_rake_db_test_purge
19
+ Rake::Task["db:create"].invoke
20
+ Rake::Task["db:test:purge"].invoke
21
+ end
17
22
  else
18
23
  def test_skipped
19
24
  end
20
25
  end
26
+
27
+ def test_rake_db_create_does_not_load_full_environment
28
+ Rake::Task["db:create"].invoke
29
+ assert @rails_env_set
30
+ assert !@full_environment_loaded
31
+ end
21
32
  end
@@ -0,0 +1,16 @@
1
+ require 'abstract_db_create'
2
+ require 'db/postgres'
3
+
4
+ class PostgresDbDropTest < Test::Unit::TestCase
5
+ include AbstractDbCreate
6
+
7
+ def db_config
8
+ POSTGRES_CONFIG
9
+ end
10
+
11
+ def test_dropping_nonexistent_database_does_not_raise_exception
12
+ assert_nothing_raised do
13
+ Rake::Task["db:drop"].invoke
14
+ end
15
+ end
16
+ end
@@ -1,13 +1,18 @@
1
1
  require 'jdbc_common'
2
+ require 'models/entry'
2
3
  require 'models/mixed_case'
3
4
 
4
5
  class MixedCaseTest < Test::Unit::TestCase
5
-
6
6
  def setup
7
7
  Migration::MixedCase.up
8
+ @table_name = User.table_name
9
+ User.table_name = 'tblUsers'
10
+ User.reset_column_information
8
11
  end
9
12
 
10
13
  def teardown
14
+ User.table_name = @table_name
15
+ User.reset_column_information
11
16
  Migration::MixedCase.down
12
17
  end
13
18
 
@@ -16,4 +21,9 @@ class MixedCaseTest < Test::Unit::TestCase
16
21
  assert_equal 'some value', mixed_case.SOME_value
17
22
  end
18
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
19
29
  end