activerecord-jdbc-adapter 1.2.1 → 1.2.2

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.
Files changed (53) hide show
  1. data/.travis.yml +3 -0
  2. data/Gemfile.lock +13 -15
  3. data/History.txt +19 -0
  4. data/README.rdoc +2 -0
  5. data/Rakefile +2 -1
  6. data/lib/arel/visitors/derby.rb +9 -2
  7. data/lib/arel/visitors/sql_server.rb +2 -0
  8. data/lib/arjdbc/db2/adapter.rb +3 -1
  9. data/lib/arjdbc/derby/adapter.rb +10 -3
  10. data/lib/arjdbc/jdbc/adapter.rb +5 -2
  11. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  12. data/lib/arjdbc/jdbc/base_ext.rb +15 -0
  13. data/lib/arjdbc/jdbc/connection.rb +5 -1
  14. data/lib/arjdbc/jdbc/missing_functionality_helper.rb +1 -0
  15. data/lib/arjdbc/mssql/adapter.rb +31 -28
  16. data/lib/arjdbc/mssql/lock_helpers.rb +72 -0
  17. data/lib/arjdbc/mysql/adapter.rb +110 -45
  18. data/lib/arjdbc/oracle/adapter.rb +7 -0
  19. data/lib/arjdbc/postgresql/adapter.rb +327 -153
  20. data/lib/arjdbc/sqlite3/adapter.rb +9 -4
  21. data/lib/arjdbc/version.rb +1 -1
  22. data/rakelib/db.rake +17 -5
  23. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +14 -4
  24. data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +25 -0
  25. data/test/db/jdbc.rb +4 -3
  26. data/test/db2_reset_column_information_test.rb +8 -0
  27. data/test/derby_reset_column_information_test.rb +8 -0
  28. data/test/derby_row_locking_test.rb +9 -0
  29. data/test/derby_simple_test.rb +40 -0
  30. data/test/h2_simple_test.rb +2 -2
  31. data/test/helper.rb +15 -2
  32. data/test/jdbc_common.rb +1 -0
  33. data/test/jndi_callbacks_test.rb +5 -9
  34. data/test/manualTestDatabase.rb +31 -31
  35. data/test/models/validates_uniqueness_of_string.rb +1 -1
  36. data/test/mssql_ignore_system_views_test.rb +27 -0
  37. data/test/mssql_null_test.rb +14 -0
  38. data/test/mssql_reset_column_information_test.rb +8 -0
  39. data/test/mssql_row_locking_sql_test.rb +159 -0
  40. data/test/mssql_row_locking_test.rb +9 -0
  41. data/test/mysql_reset_column_information_test.rb +8 -0
  42. data/test/mysql_simple_test.rb +69 -5
  43. data/test/oracle_reset_column_information_test.rb +8 -0
  44. data/test/oracle_specific_test.rb +1 -1
  45. data/test/postgres_nonseq_pkey_test.rb +1 -1
  46. data/test/postgres_reset_column_information_test.rb +8 -0
  47. data/test/postgres_simple_test.rb +72 -1
  48. data/test/row_locking.rb +90 -0
  49. data/test/simple.rb +82 -2
  50. data/test/sqlite3_reset_column_information_test.rb +8 -0
  51. data/test/sqlite3_simple_test.rb +47 -0
  52. data/test/sybase_reset_column_information_test.rb +8 -0
  53. metadata +33 -3
@@ -13,7 +13,7 @@ class CreateValidatesUniquenessOf < ActiveRecord::Migration
13
13
  end
14
14
 
15
15
  class ValidatesUniquenessOfString < ActiveRecord::Base
16
- self.set_table_name "validates_uniqueness_of"
16
+ self.table_name = "validates_uniqueness_of"
17
17
  validates_uniqueness_of :cs_string, :case_sensitive => true
18
18
  validates_uniqueness_of :ci_string, :case_sensitive => false
19
19
  end
@@ -0,0 +1,27 @@
1
+ #! /usr/bin/env jruby
2
+
3
+ require 'jdbc_common'
4
+ require 'db/mssql'
5
+
6
+ class IgnoreSystemViewsTest < Test::Unit::TestCase
7
+
8
+ include MigrationSetup
9
+
10
+ def test_system_views_ignored
11
+ assert_equal true, table_exists?("sys.views"), %{table_exists?("sys.views")}
12
+ assert_equal true, table_exists?("information_schema.views"), %{table_exists?("information_schema.views")}
13
+ assert_equal false, table_exists?("dbo.views"), %{table_exists?("dbo.views")}
14
+ assert_equal false, table_exists?(:views), %{table_exists?(:views)}
15
+ ActiveRecord::Schema.define { suppress_messages { create_table :views } }
16
+ assert_equal true, table_exists?(:views), %{table_exists?(:views)}
17
+ ActiveRecord::Schema.define { suppress_messages { drop_table :views } }
18
+ assert_equal false, table_exists?(:views), %{table_exists?(:views)}
19
+ end
20
+
21
+ private
22
+
23
+ def table_exists?(*args)
24
+ !!ActiveRecord::Base.connection.table_exists?(*args)
25
+ end
26
+ end
27
+
@@ -0,0 +1,14 @@
1
+ require 'jdbc_common'
2
+ require 'db/mssql'
3
+
4
+ class MsSQLNullTest < Test::Unit::TestCase
5
+ include MigrationSetup
6
+
7
+ [nil, "NULL", "null", "(null)", "(NULL)"].each_with_index do |v, i|
8
+ define_method "test_null_#{i}" do
9
+ entry = Entry.create!(:title => v, :content => v)
10
+ entry = Entry.find(entry.id)
11
+ assert_equal [v, v], [entry.title, entry.content], "writing #{v.inspect} should read back as #{v.inspect} for both string and text columns"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ #! /usr/bin/env jruby
2
+
3
+ require 'jdbc_common'
4
+ require 'db/mssql'
5
+
6
+ class MsSQLResetColumnInformationTest < Test::Unit::TestCase
7
+ include ResetColumnInformationTestMethods
8
+ end
@@ -0,0 +1,159 @@
1
+ #! /usr/bin/env jruby
2
+
3
+ require 'arjdbc/mssql/adapter'
4
+ require 'test/unit'
5
+
6
+ # This tests ArJdbc::MsSQL#add_lock! without actually connecting to the database.
7
+ class MssqlRowLockingSqlTest < Test::Unit::TestCase
8
+
9
+ def test_find_all
10
+ add_lock_test "Appointment.find(:all)",
11
+ %q{SELECT * FROM appointments},
12
+ %q{SELECT * FROM appointments WITH(ROWLOCK,UPDLOCK)}
13
+ end
14
+
15
+ def test_find_first
16
+ add_lock_test "Appointment.find(:first)",
17
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments) AS t WHERE t._row_num BETWEEN 1 AND 1},
18
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments WITH(ROWLOCK,UPDLOCK) ) AS t WHERE t._row_num BETWEEN 1 AND 1}
19
+ end
20
+
21
+ def test_find_all_where
22
+ add_lock_test "AppointmentDetail.find(:all, :conditions => {:name => 'foo', :value => 'bar'})",
23
+ %q{SELECT * FROM appointment_details WHERE (appointment_details.[name] = N'foo' AND appointment_details.[value] = N'bar')},
24
+ %q{SELECT * FROM appointment_details WITH(ROWLOCK,UPDLOCK) WHERE (appointment_details.[name] = N'foo' AND appointment_details.[value] = N'bar')}
25
+ end
26
+
27
+ def test_find_first_where
28
+ add_lock_test "AppointmentDetail.find(:first, :conditions => {:name => 'foo', :value => 'bar'})",
29
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details WHERE (appointment_details.[name] = N'foo' AND appointment_details.[value] = N'bar')) AS t WHERE t._row_num BETWEEN 1 AND 1},
30
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details WITH(ROWLOCK,UPDLOCK) WHERE (appointment_details.[name] = N'foo' AND appointment_details.[value] = N'bar')) AS t WHERE t._row_num BETWEEN 1 AND 1}
31
+ end
32
+
33
+ def test_find_all_where_array
34
+ add_lock_test "AppointmentDetail.find(:all, :conditions => ['name = ?', 'foo'])",
35
+ %q{SELECT * FROM appointment_details WHERE (name = N'foo')},
36
+ %q{SELECT * FROM appointment_details WITH(ROWLOCK,UPDLOCK) WHERE (name = N'foo')}
37
+ end
38
+
39
+ def test_find_first_where_array
40
+ add_lock_test "AppointmentDetail.find(:first, :conditions => ['name = ?', 'foo'])",
41
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details WHERE (name = N'foo')) AS t WHERE t._row_num BETWEEN 1 AND 1},
42
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details WITH(ROWLOCK,UPDLOCK) WHERE (name = N'foo')) AS t WHERE t._row_num BETWEEN 1 AND 1}
43
+ end
44
+
45
+ def test_find_all_joins
46
+ add_lock_test "AppointmentDetail.find(:all, :joins => :appointment)",
47
+ %q{SELECT appointment_details.* FROM appointment_details INNER JOIN appointments ON appointments.id = appointment_details.appointment_id},
48
+ %q{SELECT appointment_details.* FROM appointment_details WITH(ROWLOCK,UPDLOCK) INNER JOIN appointments WITH(ROWLOCK,UPDLOCK) ON appointments.id = appointment_details.appointment_id}
49
+ end
50
+
51
+ def test_find_first_joins
52
+ add_lock_test "AppointmentDetail.find(:first, :joins => :appointment)",
53
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details INNER JOIN appointments ON appointments.id = appointment_details.appointment_id) AS t WHERE t._row_num BETWEEN 1 AND 1},
54
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details WITH(ROWLOCK,UPDLOCK) INNER JOIN appointments WITH(ROWLOCK,UPDLOCK) ON appointments.id = appointment_details.appointment_id) AS t WHERE t._row_num BETWEEN 1 AND 1}
55
+ end
56
+
57
+ def test_find_all_2joins
58
+ add_lock_test "Appointment.find(:all, :joins => [:appointment_details, :appointment_hl7s])",
59
+ %q{SELECT appointments.* FROM appointments INNER JOIN appointment_details ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s ON appointment_hl7s.appointment_id = appointments.id},
60
+ %q{SELECT appointments.* FROM appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN appointment_details WITH(ROWLOCK,UPDLOCK) ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s WITH(ROWLOCK,UPDLOCK) ON appointment_hl7s.appointment_id = appointments.id}
61
+ end
62
+
63
+ def test_find_first_2joins
64
+ add_lock_test "Appointment.find(:first, :joins => [:appointment_details, :appointment_hl7s])",
65
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments INNER JOIN appointment_details ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s ON appointment_hl7s.appointment_id = appointments.id) AS t WHERE t._row_num BETWEEN 1 AND 1},
66
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN appointment_details WITH(ROWLOCK,UPDLOCK) ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s WITH(ROWLOCK,UPDLOCK) ON appointment_hl7s.appointment_id = appointments.id) AS t WHERE t._row_num BETWEEN 1 AND 1}
67
+ end
68
+
69
+ def test_find_all_2joins_where
70
+ add_lock_test "Appointment.find(:all, :joins => [:appointment_details, :appointment_hl7s], :conditions => {'appointment_details.name' => 'foo'})",
71
+ %q{SELECT appointments.* FROM appointments INNER JOIN appointment_details ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s ON appointment_hl7s.appointment_id = appointments.id WHERE (appointment_details.[name] = N'foo')},
72
+ %q{SELECT appointments.* FROM appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN appointment_details WITH(ROWLOCK,UPDLOCK) ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s WITH(ROWLOCK,UPDLOCK) ON appointment_hl7s.appointment_id = appointments.id WHERE (appointment_details.[name] = N'foo')}
73
+ end
74
+
75
+ def test_find_first_2joins_where
76
+ add_lock_test "Appointment.find(:first, :joins => [:appointment_details, :appointment_hl7s], :conditions => {'appointment_details.name' => 'foo'})",
77
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments INNER JOIN appointment_details ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s ON appointment_hl7s.appointment_id = appointments.id WHERE (appointment_details.[name] = N'foo')) AS t WHERE t._row_num BETWEEN 1 AND 1},
78
+ %q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN appointment_details WITH(ROWLOCK,UPDLOCK) ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s WITH(ROWLOCK,UPDLOCK) ON appointment_hl7s.appointment_id = appointments.id WHERE (appointment_details.[name] = N'foo')) AS t WHERE t._row_num BETWEEN 1 AND 1}
79
+ end
80
+
81
+ def test_custom_join_ar097
82
+ add_lock_test "custom join (arjdbc 0.9.7)",
83
+ %q{
84
+ SELECT t.* FROM (
85
+ SELECT
86
+ ROW_NUMBER() OVER(ORDER BY appointments.id) AS row_num,
87
+ appointments.*
88
+ FROM
89
+ appointments INNER JOIN
90
+ appointment_details AS d1 ON appointments.[id] = d1.[appointment_id]
91
+ WHERE (d1.[name] = N'appointment_identifier' AND d1.[value] = N'279955^MQ')
92
+ ) AS t WHERE t.row_num BETWEEN 1 AND 1
93
+ }, %q{
94
+ SELECT t.* FROM (
95
+ SELECT
96
+ ROW_NUMBER() OVER(ORDER BY appointments.id) AS row_num,
97
+ appointments.*
98
+ FROM
99
+ appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN
100
+ appointment_details AS d1 WITH(ROWLOCK,UPDLOCK) ON appointments.[id] = d1.[appointment_id]
101
+ WHERE (d1.[name] = N'appointment_identifier' AND d1.[value] = N'279955^MQ')
102
+ ) AS t WHERE t.row_num BETWEEN 1 AND 1
103
+ }
104
+ end
105
+
106
+ def test_custom_join_ar111
107
+ add_lock_test "custom join (arjdbc 1.1.1)",
108
+ %q{
109
+ SELECT t.*
110
+ FROM
111
+ (
112
+ SELECT
113
+ ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num,
114
+ appointments.*
115
+ FROM
116
+ appointments INNER JOIN
117
+ appointment_details AS d1 ON appointments.[id] = d1.[appointment_id]
118
+ WHERE
119
+ (d1.[name] = N'appointment_identifier' AND d1.[value] = N'389727^MQ')
120
+ ) AS t
121
+ WHERE
122
+ t._row_num BETWEEN 1 AND 1
123
+ }, %q{
124
+ SELECT t.*
125
+ FROM
126
+ (
127
+ SELECT
128
+ ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num,
129
+ appointments.*
130
+ FROM
131
+ appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN
132
+ appointment_details AS d1 WITH(ROWLOCK,UPDLOCK) ON appointments.[id] = d1.[appointment_id]
133
+ WHERE
134
+ (d1.[name] = N'appointment_identifier' AND d1.[value] = N'389727^MQ')
135
+ ) AS t
136
+ WHERE
137
+ t._row_num BETWEEN 1 AND 1
138
+ }
139
+ end
140
+
141
+
142
+ private
143
+
144
+ class Dummy
145
+ include ::ArJdbc::MsSQL::LockHelpers::SqlServerAddLock
146
+ end
147
+
148
+ def add_lock!(sql, options={})
149
+ result = sql.dup
150
+ Dummy.new.add_lock!(result, {:lock=>true}.merge(options))
151
+ result
152
+ end
153
+
154
+ def add_lock_test(message, before, after, options={})
155
+ before = before.gsub(/\s*\n\s*/m, " ").strip
156
+ after = after.gsub(/\s*\n\s*/m, " ").strip
157
+ assert_equal after, add_lock!(before, options).strip, message
158
+ end
159
+ end
@@ -0,0 +1,9 @@
1
+ #! /usr/bin/env jruby
2
+
3
+ require 'jdbc_common'
4
+ require 'db/mssql'
5
+
6
+ class MssqlRowLockingTest < Test::Unit::TestCase
7
+ include MigrationSetup
8
+ include RowLockingTestMethods
9
+ end
@@ -0,0 +1,8 @@
1
+ #! /usr/bin/env jruby
2
+
3
+ require 'jdbc_common'
4
+ require 'db/mysql'
5
+
6
+ class MySQLResetColumnInformationTest < Test::Unit::TestCase
7
+ include ResetColumnInformationTestMethods
8
+ end
@@ -18,7 +18,7 @@ class MysqlSimpleTest < Test::Unit::TestCase
18
18
  def test_column_class_instantiation
19
19
  text_column = nil
20
20
  assert_nothing_raised do
21
- text_column = ActiveRecord::ConnectionAdapters::MysqlAdapter::Column.
21
+ text_column = ActiveRecord::ConnectionAdapters::MysqlColumn.
22
22
  new("title", nil, "text")
23
23
  end
24
24
  assert_not_nil text_column
@@ -42,17 +42,81 @@ class MysqlSimpleTest < Test::Unit::TestCase
42
42
  assert_nothing_raised { Entry.update_all({:title => "test"}, {}, {:limit => 1}) }
43
43
  end
44
44
 
45
+ # from rails active record tests
46
+ def test_update_all_with_joins_and_offset_and_order
47
+ user_1 = User.create :login => 'user_1'
48
+ user_2 = User.create :login => 'user_2'
49
+
50
+ entry_1 = Entry.create :title => 'title_1', :content => 'content_1', :rating => 0,
51
+ :user_id => user_1.id
52
+ entry_2 = Entry.create :title => 'title_2', :content => 'content_2', :rating => 1,
53
+ :user_id => user_2.id
54
+
55
+ all_entries = Entry.joins(:user).where('users.id' => user_1.id).
56
+ order('users.id', 'entries.id')
57
+ count = all_entries.count
58
+ entries = all_entries.offset(1)
59
+
60
+ assert_equal count - 1, entries.update_all(:user_id => user_2.id)
61
+ assert_equal user_2, Entry.find_by_title('title_2').user
62
+ end
63
+
64
+ # from rails active record tests
65
+ def test_caching_of_columns
66
+ user = User.create :login => 'test'
67
+
68
+ # clear cache possibly created by other tests
69
+ user.entries.reset_column_information
70
+
71
+ assert_queries(1, /SHOW FIELDS/) { user.entries.columns; user.entries.columns }
72
+
73
+ ## and again to verify that reset_column_information clears the cache correctly
74
+ user.entries.reset_column_information
75
+ assert_queries(1, /SHOW FIELDS/) { user.entries.columns; user.entries.columns }
76
+ end
77
+
78
+ # from rails active record tests
79
+ def test_drop_index_from_table_named_values
80
+ connection = Entry.connection
81
+ connection.create_table :values, :force => true do |t|
82
+ t.integer :value
83
+ end
84
+
85
+ assert_nothing_raised do
86
+ connection.add_index :values, :value
87
+ connection.remove_index :values, :column => :value
88
+ end
89
+
90
+ connection.drop_table :values rescue nil
91
+ end
92
+
45
93
  def test_find_in_other_schema_with_include
46
94
  old_entries_table_name = Entry.table_name
47
95
  old_users_table_name = User.table_name
48
96
  begin
49
- User.set_table_name "#{MYSQL_CONFIG[:database]}.users"
50
- Entry.set_table_name "#{MYSQL_CONFIG[:database]}.entries"
97
+ User.table_name = "#{MYSQL_CONFIG[:database]}.users"
98
+ Entry.table_name = "#{MYSQL_CONFIG[:database]}.entries"
51
99
  assert !Entry.all(:include => :user).empty?
52
100
  ensure
53
- Entry.set_table_name old_entries_table_name
54
- User.set_table_name old_users_table_name
101
+ Entry.table_name = old_entries_table_name
102
+ User.table_name = old_users_table_name
103
+ end
104
+ end
105
+
106
+ def test_create_xml_column
107
+ assert_nothing_raised do
108
+ @connection.create_table :xml_testings do |t|
109
+ t.xml :xml_test
110
+ end
55
111
  end
112
+
113
+ xml_test = @connection.columns(:xml_testings).detect do |c|
114
+ c.name == "xml_test"
115
+ end
116
+
117
+ assert_equal "text", xml_test.sql_type
118
+ ensure
119
+ @connection.drop_table :xml_testings rescue nil
56
120
  end
57
121
  end
58
122
 
@@ -0,0 +1,8 @@
1
+ #! /usr/bin/env jruby
2
+
3
+ require 'jdbc_common'
4
+ require 'db/oracle'
5
+
6
+ class OracleResetColumnInformationTest < Test::Unit::TestCase
7
+ include ResetColumnInformationTestMethods
8
+ end
@@ -70,7 +70,7 @@ class OracleSpecificTest < Test::Unit::TestCase
70
70
 
71
71
  def test_model_access_by_synonym
72
72
  @klass = Class.new(ActiveRecord::Base)
73
- @klass.set_table_name "POSTS"
73
+ @klass.table_name = "POSTS"
74
74
  entry_columns = Entry.columns_hash
75
75
  @klass.columns.each do |c|
76
76
  ec = entry_columns[c.name]
@@ -15,7 +15,7 @@ class CreateUrls < ActiveRecord::Migration
15
15
  end
16
16
 
17
17
  class Url < ActiveRecord::Base
18
- set_primary_key :uhash
18
+ self.primary_key = :uhash
19
19
  #Shouldn't be needed: set_sequence_name nil
20
20
  end
21
21
 
@@ -0,0 +1,8 @@
1
+ #! /usr/bin/env jruby
2
+
3
+ require 'jdbc_common'
4
+ require 'db/postgres'
5
+
6
+ class PostgresResetColumnInformationTest < Test::Unit::TestCase
7
+ include ResetColumnInformationTestMethods
8
+ end
@@ -16,13 +16,84 @@ class PostgresSimpleTest < Test::Unit::TestCase
16
16
  classname = @connection.class.name[/[^:]*$/]
17
17
  assert_equal 'PostgreSQLAdapter', classname
18
18
  end
19
-
19
+
20
+ def test_encoding
21
+ assert_not_nil @connection.encoding
22
+ end
23
+
20
24
  def test_multi_statement_support
21
25
  results = @connection.execute "SELECT title from entries; SELECT login from users"
22
26
  assert_equal 2, results.length
23
27
  assert_equal ["title"], results[0].first.keys
24
28
  assert_equal ["login"], results[1].first.keys
25
29
  end
30
+
31
+ def test_create_xml_column
32
+ assert_nothing_raised do
33
+ @connection.create_table :xml_testings do |t|
34
+ t.column :xml_test, :xml
35
+ end
36
+ end
37
+
38
+ xml_test = @connection.columns(:xml_testings).detect do
39
+ |c| c.name == "xml_test"
40
+ end
41
+
42
+ assert_equal "xml", xml_test.sql_type
43
+ ensure
44
+ @connection.drop_table :xml_testings rescue nil
45
+ end
46
+
47
+ def test_create_table_with_limits
48
+ assert_nothing_raised do
49
+ @connection.create_table :testings do |t|
50
+ t.column :eleven_int, :integer, :limit => 11
51
+ end
52
+ end
53
+
54
+ columns = @connection.columns(:testings)
55
+ eleven = columns.detect { |c| c.name == "eleven_int" }
56
+ assert_equal "integer", eleven.sql_type
57
+ ensure
58
+ @connection.drop_table :testings rescue nil
59
+ end
60
+ end
61
+
62
+ class PostgresTimestampTest < Test::Unit::TestCase
63
+ def setup
64
+ DbTypeMigration.up
65
+ end
66
+
67
+ def teardown
68
+ DbTypeMigration.down
69
+ end
70
+
71
+ def test_string_is_character_varying
72
+ sample_string = DbType.connection.columns(:db_types).detect do |c|
73
+ c.name == "sample_string"
74
+ end
75
+
76
+ assert_match(/^character varying/, sample_string.sql_type)
77
+ end
78
+
79
+ # infinite timestamp tests based on rails tests for postgresql_adapter.rb
80
+ def test_load_infinity_and_beyond
81
+ d = DbType.find_by_sql("select 'infinity'::timestamp as sample_timestamp")
82
+ assert d.first.sample_timestamp.infinite?, 'timestamp should be infinite'
83
+
84
+ d = DbType.find_by_sql "select '-infinity'::timestamp as sample_timestamp"
85
+ time = d.first.sample_timestamp
86
+ assert time.infinite?, "timestamp should be infinte"
87
+ assert_operator time, :<, 0
88
+ end
89
+
90
+ def test_save_infinity_and_beyond
91
+ d = DbType.create!(:sample_timestamp => 1.0 / 0.0)
92
+ assert_equal(1.0 / 0.0, d.sample_timestamp)
93
+
94
+ e = DbType.create!(:sample_timestamp => -1.0 / 0.0)
95
+ assert_equal(-1.0 / 0.0, e.sample_timestamp)
96
+ end
26
97
  end
27
98
 
28
99
  class PostgresDeserializationTest < Test::Unit::TestCase