mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Oracle adapter gets Time or DateTime value already with timezone
This commit is contained in:
parent
ee654e54c4
commit
5d0dece6a6
1 changed files with 45 additions and 16 deletions
|
@ -446,18 +446,22 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
assert_equal Date, bob.favorite_day.class
|
assert_equal Date, bob.favorite_day.class
|
||||||
end
|
end
|
||||||
|
|
||||||
# Test DateTime column and defaults, including timezone.
|
# Oracle adapter stores Time or DateTime with timezone value already in _before_type_cast column
|
||||||
# FIXME: moment of truth may be Time on 64-bit platforms.
|
# therefore no timezone change is done afterwards when default timezone is changed
|
||||||
if bob.moment_of_truth.is_a?(DateTime)
|
unless current_adapter?(:OracleAdapter)
|
||||||
|
# Test DateTime column and defaults, including timezone.
|
||||||
|
# FIXME: moment of truth may be Time on 64-bit platforms.
|
||||||
|
if bob.moment_of_truth.is_a?(DateTime)
|
||||||
|
|
||||||
with_env_tz 'US/Eastern' do
|
with_env_tz 'US/Eastern' do
|
||||||
assert_equal DateTime.local_offset, bob.moment_of_truth.offset
|
assert_equal DateTime.local_offset, bob.moment_of_truth.offset
|
||||||
assert_not_equal 0, bob.moment_of_truth.offset
|
assert_not_equal 0, bob.moment_of_truth.offset
|
||||||
assert_not_equal "Z", bob.moment_of_truth.zone
|
assert_not_equal "Z", bob.moment_of_truth.zone
|
||||||
# US/Eastern is -5 hours from GMT
|
# US/Eastern is -5 hours from GMT
|
||||||
assert_equal Rational(-5, 24), bob.moment_of_truth.offset
|
assert_equal Rational(-5, 24), bob.moment_of_truth.offset
|
||||||
assert_match /\A-05:?00\Z/, bob.moment_of_truth.zone #ruby 1.8.6 uses HH:MM, prior versions use HHMM
|
assert_match /\A-05:?00\Z/, bob.moment_of_truth.zone #ruby 1.8.6 uses HH:MM, prior versions use HHMM
|
||||||
assert_equal DateTime::ITALY, bob.moment_of_truth.start
|
assert_equal DateTime::ITALY, bob.moment_of_truth.start
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -571,7 +575,7 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
ActiveRecord::Base.connection.create_table(:hats) do |table|
|
ActiveRecord::Base.connection.create_table(:hats) do |table|
|
||||||
table.column :hat_name, :string, :default => nil
|
table.column :hat_name, :string, :default => nil
|
||||||
end
|
end
|
||||||
exception = if current_adapter?(:PostgreSQLAdapter)
|
exception = if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
|
||||||
ActiveRecord::StatementInvalid
|
ActiveRecord::StatementInvalid
|
||||||
else
|
else
|
||||||
ActiveRecord::ActiveRecordError
|
ActiveRecord::ActiveRecordError
|
||||||
|
@ -625,7 +629,13 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
table.column :hat_size, :integer
|
table.column :hat_size, :integer
|
||||||
table.column :hat_style, :string, :limit => 100
|
table.column :hat_style, :string, :limit => 100
|
||||||
end
|
end
|
||||||
ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true
|
# Oracle index names should be 30 or less characters
|
||||||
|
if current_adapter?(:OracleAdapter)
|
||||||
|
ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true,
|
||||||
|
:name => 'index_hats_on_hat_style_size'
|
||||||
|
else
|
||||||
|
ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true
|
||||||
|
end
|
||||||
|
|
||||||
assert_nothing_raised { Person.connection.remove_column("hats", "hat_size") }
|
assert_nothing_raised { Person.connection.remove_column("hats", "hat_size") }
|
||||||
ensure
|
ensure
|
||||||
|
@ -783,7 +793,12 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
|
|
||||||
assert_nothing_raised { Person.connection.change_column :testings, :select, :string, :limit => 10 }
|
assert_nothing_raised { Person.connection.change_column :testings, :select, :string, :limit => 10 }
|
||||||
|
|
||||||
assert_nothing_raised { Person.connection.execute "insert into testings (#{Person.connection.quote_column_name('select')}) values ('7 chars')" }
|
# Oracle needs primary key value from sequence
|
||||||
|
if current_adapter?(:OracleAdapter)
|
||||||
|
assert_nothing_raised { Person.connection.execute "insert into testings (id, #{Person.connection.quote_column_name('select')}) values (testings_seq.nextval, '7 chars')" }
|
||||||
|
else
|
||||||
|
assert_nothing_raised { Person.connection.execute "insert into testings (#{Person.connection.quote_column_name('select')}) values ('7 chars')" }
|
||||||
|
end
|
||||||
ensure
|
ensure
|
||||||
Person.connection.drop_table :testings rescue nil
|
Person.connection.drop_table :testings rescue nil
|
||||||
end
|
end
|
||||||
|
@ -799,7 +814,12 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
person_klass.reset_column_information
|
person_klass.reset_column_information
|
||||||
assert_equal 99, person_klass.columns_hash["wealth"].default
|
assert_equal 99, person_klass.columns_hash["wealth"].default
|
||||||
assert_equal false, person_klass.columns_hash["wealth"].null
|
assert_equal false, person_klass.columns_hash["wealth"].null
|
||||||
assert_nothing_raised {person_klass.connection.execute("insert into testings (title) values ('tester')")}
|
# Oracle needs primary key value from sequence
|
||||||
|
if current_adapter?(:OracleAdapter)
|
||||||
|
assert_nothing_raised {person_klass.connection.execute("insert into testings (id, title) values (testings_seq.nextval, 'tester')")}
|
||||||
|
else
|
||||||
|
assert_nothing_raised {person_klass.connection.execute("insert into testings (title) values ('tester')")}
|
||||||
|
end
|
||||||
|
|
||||||
# change column default to see that column doesn't lose its not null definition
|
# change column default to see that column doesn't lose its not null definition
|
||||||
person_klass.connection.change_column_default "testings", "wealth", 100
|
person_klass.connection.change_column_default "testings", "wealth", 100
|
||||||
|
@ -1054,7 +1074,12 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_migrator_db_has_no_schema_migrations_table
|
def test_migrator_db_has_no_schema_migrations_table
|
||||||
ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations;")
|
# Oracle adapter raises error if semicolon is present as last character
|
||||||
|
if current_adapter?(:OracleAdapter)
|
||||||
|
ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations")
|
||||||
|
else
|
||||||
|
ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations;")
|
||||||
|
end
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 1)
|
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 1)
|
||||||
end
|
end
|
||||||
|
@ -1412,6 +1437,8 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
def string_column
|
def string_column
|
||||||
if current_adapter?(:PostgreSQLAdapter)
|
if current_adapter?(:PostgreSQLAdapter)
|
||||||
"character varying(255)"
|
"character varying(255)"
|
||||||
|
elsif current_adapter?(:OracleAdapter)
|
||||||
|
'VARCHAR2(255)'
|
||||||
else
|
else
|
||||||
'varchar(255)'
|
'varchar(255)'
|
||||||
end
|
end
|
||||||
|
@ -1420,6 +1447,8 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
def integer_column
|
def integer_column
|
||||||
if current_adapter?(:MysqlAdapter)
|
if current_adapter?(:MysqlAdapter)
|
||||||
'int(11)'
|
'int(11)'
|
||||||
|
elsif current_adapter?(:OracleAdapter)
|
||||||
|
'NUMBER(38)'
|
||||||
else
|
else
|
||||||
'integer'
|
'integer'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue