activerecord-jdbc-adapter 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,18 @@ require 'db/mysql'
11
11
  class MysqlSimpleTest < Test::Unit::TestCase
12
12
  include SimpleTestMethods
13
13
  include ActiveRecord3TestMethods
14
+ include ColumnNameQuotingTests
15
+
16
+ column_quote_char "`"
17
+
18
+ def test_column_class_instantiation
19
+ text_column = nil
20
+ assert_nothing_raised do
21
+ text_column = ActiveRecord::ConnectionAdapters::MysqlAdapter::Column.
22
+ new("title", nil, "text")
23
+ end
24
+ assert_not_nil text_column
25
+ end
14
26
 
15
27
  def test_string_quoting_oddity
16
28
  s = "0123456789a'a"
@@ -22,8 +34,8 @@ class MysqlSimpleTest < Test::Unit::TestCase
22
34
  end
23
35
 
24
36
  def test_table_name_quoting_with_dot
25
- s = "weblog_development.posts"
26
- assert_equal "`weblog_development`.`posts`", ActiveRecord::Base.connection.quote_table_name(s)
37
+ s = "#{MYSQL_CONFIG[:database]}.posts"
38
+ assert_equal "`#{MYSQL_CONFIG[:database]}`.`posts`", ActiveRecord::Base.connection.quote_table_name(s)
27
39
  end
28
40
 
29
41
  def test_update_all_with_limit
@@ -34,8 +46,8 @@ class MysqlSimpleTest < Test::Unit::TestCase
34
46
  old_entries_table_name = Entry.table_name
35
47
  old_users_table_name = User.table_name
36
48
  begin
37
- User.set_table_name 'weblog_development.users'
38
- Entry.set_table_name 'weblog_development.entries'
49
+ User.set_table_name "#{MYSQL_CONFIG[:database]}.users"
50
+ Entry.set_table_name "#{MYSQL_CONFIG[:database]}.entries"
39
51
  assert !Entry.all(:include => :user).empty?
40
52
  ensure
41
53
  Entry.set_table_name old_entries_table_name
@@ -16,7 +16,8 @@ class CreateNativeTypeMappingTestSchema < ActiveRecord::Migration
16
16
  real_should_be_float real,
17
17
  bool_should_be_boolean bool,
18
18
  interval_should_be_string interval,
19
- bigint_should_be_integer bigint
19
+ bigint_should_be_integer bigint,
20
+ uuid_should_be_string uuid
20
21
  )}
21
22
  end
22
23
 
@@ -42,6 +43,10 @@ class PostgresNativeTypeMappingTest < Test::Unit::TestCase
42
43
  Customer.columns.detect { |c| c.name == column_name }.type
43
44
  end
44
45
 
46
+ def test_uuid_column_should_map_to_string
47
+ assert_equal :string, column_type("uuid_should_be_string")
48
+ end
49
+
45
50
  def test_bigint_serial_should_be_mapped_to_integer
46
51
  assert_equal :integer, column_type("bigint_serial_should_be_integer")
47
52
  end
@@ -10,7 +10,13 @@ require 'db/postgres'
10
10
  class PostgresSimpleTest < Test::Unit::TestCase
11
11
  include SimpleTestMethods
12
12
  include ActiveRecord3TestMethods
13
+ include ColumnNameQuotingTests
13
14
 
15
+ def test_adapter_class_name_equals_native_adapter_class_name
16
+ classname = @connection.class.name[/[^:]*$/]
17
+ assert_equal 'PostgreSQLAdapter', classname
18
+ end
19
+
14
20
  def test_multi_statement_support
15
21
  results = @connection.execute "SELECT title from entries; SELECT login from users"
16
22
  assert_equal 2, results.length
@@ -51,39 +57,39 @@ class PostgresSchemaDumperTest < Test::Unit::TestCase
51
57
 
52
58
  # http://kenai.com/jira/browse/ACTIVERECORD_JDBC-135
53
59
  def test_schema_dump_should_not_have_limits_on_boolean
54
- lines = @dump.grep(/boolean/)
60
+ lines = @dump.lines.grep(/boolean/)
55
61
  assert !lines.empty?
56
62
  lines.each {|line| assert line !~ /limit/ }
57
63
  end
58
64
 
59
65
 
60
66
  def test_schema_dump_should_not_have_limits_on_binaries
61
- lines = @dump.grep(/binary/)
67
+ lines = @dump.lines.grep(/binary/)
62
68
  assert !lines.empty?, 'no binary type definitions found'
63
69
  lines.each {|line| assert line !~ /limit/, 'binary definition contains limit' }
64
70
  end
65
71
 
66
72
  # http://kenai.com/jira/browse/ACTIVERECORD_JDBC-139
67
73
  def test_schema_dump_should_not_have_limits_on_text_or_date
68
- lines = @dump.grep(/date|text/)
74
+ lines = @dump.lines.grep(/date|text/)
69
75
  assert !lines.empty?
70
76
  lines.each {|line| assert line !~ /limit/ }
71
77
  end
72
78
 
73
79
  def test_schema_dump_integer_with_no_limit_should_have_no_limit
74
- lines = @dump.grep(/sample_integer_no_limit/)
80
+ lines = @dump.lines.grep(/sample_integer_no_limit/)
75
81
  assert !lines.empty?
76
82
  lines.each {|line| assert line !~ /:limit/ }
77
83
  end
78
84
 
79
85
  def test_schema_dump_integer_with_limit_2_should_have_limit_2
80
- lines = @dump.grep(/sample_integer_with_limit_2/)
86
+ lines = @dump.lines.grep(/sample_integer_with_limit_2/)
81
87
  assert !lines.empty?
82
88
  lines.each {|line| assert line =~ /limit => 2/ }
83
89
  end
84
90
 
85
91
  def test_schema_dump_integer_with_limit_8_should_have_limit_8
86
- lines = @dump.grep(/sample_integer_with_limit_8/)
92
+ lines = @dump.lines.grep(/sample_integer_with_limit_8/)
87
93
  assert !lines.empty?
88
94
  lines.each {|line| assert line =~ /limit => 8/ }
89
95
  end
@@ -0,0 +1,34 @@
1
+ require 'jdbc_common'
2
+ require 'db/postgres'
3
+
4
+ class BooleanSchema < ActiveRecord::Migration
5
+ def self.up
6
+ create_table :booleans do |t|
7
+ t.boolean :value, :default => false, :null => false
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :booleans
13
+ end
14
+ end
15
+
16
+ class Boolean < ActiveRecord::Base
17
+ end
18
+
19
+ class PostgresTypeConversionTest < Test::Unit::TestCase
20
+ def setup
21
+ BooleanSchema.up
22
+ end
23
+
24
+ def teardown
25
+ BooleanSchema.down
26
+ end
27
+
28
+ def test_should_handle_bool_conversion_with_boolean_relation
29
+ assert_nothing_raised do
30
+ ActiveRecord::Base.connection.raw_connection.set_native_database_types
31
+ end
32
+ end
33
+ end
34
+
@@ -43,6 +43,58 @@ module FixtureSetup
43
43
  end
44
44
  end
45
45
 
46
+ module ColumnNameQuotingTests
47
+ def self.included(base)
48
+ base.class_eval do
49
+ @@column_quote_char = "\""
50
+
51
+ def self.column_quote_char(char)
52
+ @@column_quote_char = char
53
+ end
54
+ end
55
+ end
56
+
57
+ def test_column_names_are_escaped
58
+ conn = ActiveRecord::Base.connection
59
+ quoted = conn.quote_column_name "foo#{column_quote_char}bar"
60
+ assert_equal "#{column_quote_char}foo#{column_quote_char * 2}bar#{column_quote_char}", quoted
61
+ end
62
+
63
+ protected
64
+ def column_quote_char
65
+ @@column_quote_char || "\""
66
+ end
67
+ end
68
+
69
+ module DirtyAttributeTests
70
+ def test_partial_update
71
+ entry = Entry.new(:title => 'foo')
72
+ old_updated_on = 1.hour.ago.beginning_of_day
73
+
74
+ with_partial_updates Entry, false do
75
+ assert_queries(2) { 2.times { entry.save! } }
76
+ Entry.update_all({ :updated_on => old_updated_on }, :id => entry.id)
77
+ end
78
+
79
+ with_partial_updates Entry, true do
80
+ assert_queries(0) { 2.times { entry.save! } }
81
+ assert_equal old_updated_on, entry.reload.updated_on
82
+
83
+ assert_queries(1) { entry.title = 'bar'; entry.save! }
84
+ assert_not_equal old_updated_on, entry.reload.updated_on
85
+ end
86
+ end
87
+
88
+ private
89
+ def with_partial_updates(klass, on = true)
90
+ old = klass.partial_updates?
91
+ klass.partial_updates = on
92
+ yield
93
+ ensure
94
+ klass.partial_updates = old
95
+ end
96
+ end
97
+
46
98
  module SimpleTestMethods
47
99
  include FixtureSetup
48
100
 
@@ -228,11 +280,11 @@ module SimpleTestMethods
228
280
  # so they all have a initial value of an empty string ''
229
281
  assert_equal(nil, e.sample_text) unless ActiveRecord::Base.connection.adapter_name =~ /oracle/i
230
282
 
231
- e.sample_text = "ooop"
283
+ e.sample_text = "ooop?"
232
284
  e.save!
233
285
 
234
286
  e = DbType.find(:first)
235
- assert_equal("ooop", e.sample_text)
287
+ assert_equal("ooop?", e.sample_text)
236
288
  end
237
289
 
238
290
  def test_string
@@ -240,11 +292,11 @@ module SimpleTestMethods
240
292
 
241
293
  # An empty string is treated as a null value in Oracle: http://www.techonthenet.com/oracle/questions/empty_null.php
242
294
  assert_equal('', e.sample_string) unless ActiveRecord::Base.connection.adapter_name =~ /oracle/i
243
- e.sample_string = "ooop"
295
+ e.sample_string = "ooop?"
244
296
  e.save!
245
297
 
246
298
  e = DbType.find(:first)
247
- assert_equal("ooop", e.sample_string)
299
+ assert_equal("ooop?", e.sample_string)
248
300
  end
249
301
 
250
302
  def test_save_binary
@@ -259,8 +311,28 @@ module SimpleTestMethods
259
311
 
260
312
  def test_default_decimal_should_keep_fractional_part
261
313
  expected = 7.3
262
- actual = DbType.create(:sample_default_decimal => expected).sample_default_decimal
263
- assert_equal expected, actual
314
+ db_type = DbType.new(:sample_small_decimal => expected)
315
+ assert db_type.save
316
+ db_type = DbType.find(db_type.id)
317
+ assert_equal BigDecimal.new(expected.to_s), db_type.sample_small_decimal
318
+ end
319
+
320
+ def test_decimal_with_scale
321
+ test_value = 7.3
322
+ db_type = DbType.new(:sample_small_decimal => test_value)
323
+ assert db_type.save
324
+ db_type = DbType.find(db_type.id)
325
+ assert_kind_of BigDecimal, db_type.sample_small_decimal
326
+ assert_equal BigDecimal.new(test_value.to_s), db_type.sample_small_decimal
327
+ end
328
+
329
+ def test_decimal_with_zero_scale
330
+ test_value = 7000.0
331
+ db_type = DbType.new(:sample_decimal => test_value)
332
+ assert db_type.save
333
+ db_type = DbType.find(db_type.id)
334
+ assert_kind_of Integer, db_type.sample_decimal
335
+ assert_equal test_value.to_i, db_type.sample_decimal
264
336
  end
265
337
 
266
338
  def test_negative_default_value
@@ -6,6 +6,8 @@ require 'models/validates_uniqueness_of_string'
6
6
  class SQLite3SimpleTest < Test::Unit::TestCase
7
7
  include SimpleTestMethods
8
8
  include ActiveRecord3TestMethods
9
+ include ColumnNameQuotingTests
10
+ include DirtyAttributeTests
9
11
 
10
12
  def test_recreate_database
11
13
  assert @connection.tables.include?(Entry.table_name)
@@ -30,7 +32,7 @@ class SQLite3SimpleTest < Test::Unit::TestCase
30
32
 
31
33
  def test_columns
32
34
  cols = ActiveRecord::Base.connection.columns("entries")
33
- assert cols.find {|col| col.name == "title"}
35
+ assert cols.find {|col| col.name == "title"}
34
36
  end
35
37
 
36
38
  def test_remove_column
@@ -136,9 +138,9 @@ class SQLite3SimpleTest < Test::Unit::TestCase
136
138
  col = cols.find{|col| col.name == "test_column_default"}
137
139
  assert col
138
140
  assert_equal col.default, nil
139
-
141
+
140
142
  end
141
-
143
+
142
144
  def test_change_column_default
143
145
  assert_nothing_raised do
144
146
  ActiveRecord::Schema.define do
@@ -218,6 +220,14 @@ class SQLite3TypeConversionTest < Test::Unit::TestCase
218
220
  :sample_decimal => JInteger::MAX_VALUE + 1,
219
221
  :sample_small_decimal => 3.14,
220
222
  :sample_binary => TEST_BINARY)
223
+ DbType.create(
224
+ :sample_timestamp => TEST_TIME,
225
+ :sample_datetime => TEST_TIME,
226
+ :sample_time => TEST_TIME,
227
+ :sample_date => TEST_TIME,
228
+ :sample_decimal => JInteger::MAX_VALUE + 1,
229
+ :sample_small_decimal => 1.0,
230
+ :sample_binary => TEST_BINARY)
221
231
  end
222
232
 
223
233
  def teardown
@@ -244,4 +254,16 @@ class SQLite3TypeConversionTest < Test::Unit::TestCase
244
254
  assert_equal(TEST_BINARY, types.sample_binary)
245
255
  end
246
256
 
257
+ def test_small_decimal
258
+ types = DbType.find(:all, :order => ["sample_small_decimal desc"])
259
+ assert_equal(3.14, types[0].sample_small_decimal)
260
+ assert_equal(1.0, types[1].sample_small_decimal)
261
+ end
262
+
263
+ def test_small_decimal_with_ordering
264
+ types = DbType.find(:all, :order => ["sample_small_decimal asc"])
265
+ types[1].sample_small_decimal
266
+ assert_equal(1.0, types[0].sample_small_decimal)
267
+ assert_equal(3.14, types[1].sample_small_decimal)
268
+ end
247
269
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: activerecord-jdbc-adapter
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.0
5
+ version: 1.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nick Sieger, Ola Bini and JRuby contributors
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-13 00:00:00 Z
13
+ date: 2011-11-23 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: |-
@@ -26,6 +26,7 @@ extra_rdoc_files: []
26
26
 
27
27
  files:
28
28
  - .gitignore
29
+ - .travis.yml
29
30
  - Gemfile
30
31
  - Gemfile.lock
31
32
  - History.txt
@@ -137,6 +138,7 @@ files:
137
138
  - rails_generators/jdbc_generator.rb
138
139
  - rails_generators/templates/config/initializers/jdbc.rb
139
140
  - rails_generators/templates/lib/tasks/jdbc.rake
141
+ - rakelib/bundler_ext.rb
140
142
  - rakelib/compile.rake
141
143
  - rakelib/db.rake
142
144
  - rakelib/rails.rake
@@ -178,6 +180,7 @@ files:
178
180
  - test/derby_multibyte_test.rb
179
181
  - test/derby_simple_test.rb
180
182
  - test/generic_jdbc_connection_test.rb
183
+ - test/h2_change_column_test.rb
181
184
  - test/h2_simple_test.rb
182
185
  - test/has_many_through.rb
183
186
  - test/helper.rb
@@ -220,6 +223,7 @@ files:
220
223
  - test/postgres_schema_search_path_test.rb
221
224
  - test/postgres_simple_test.rb
222
225
  - test/postgres_table_alias_length_test.rb
226
+ - test/postgres_type_conversion_test.rb
223
227
  - test/simple.rb
224
228
  - test/sqlite3_simple_test.rb
225
229
  - test/sybase_jtds_simple_test.rb
@@ -281,6 +285,7 @@ test_files:
281
285
  - test/derby_multibyte_test.rb
282
286
  - test/derby_simple_test.rb
283
287
  - test/generic_jdbc_connection_test.rb
288
+ - test/h2_change_column_test.rb
284
289
  - test/h2_simple_test.rb
285
290
  - test/has_many_through.rb
286
291
  - test/helper.rb
@@ -323,6 +328,7 @@ test_files:
323
328
  - test/postgres_schema_search_path_test.rb
324
329
  - test/postgres_simple_test.rb
325
330
  - test/postgres_table_alias_length_test.rb
331
+ - test/postgres_type_conversion_test.rb
326
332
  - test/simple.rb
327
333
  - test/sqlite3_simple_test.rb
328
334
  - test/sybase_jtds_simple_test.rb