mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
More succinct current_adapter? Enable locking duel for Oracle.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4576 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
044f960fd3
commit
c4782f7393
5 changed files with 67 additions and 65 deletions
|
@ -49,9 +49,11 @@ class Test::Unit::TestCase #:nodoc:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_adapter?(type)
|
def current_adapter?(*types)
|
||||||
|
types.any? do |type|
|
||||||
ActiveRecord::ConnectionAdapters.const_defined?(type) &&
|
ActiveRecord::ConnectionAdapters.const_defined?(type) &&
|
||||||
ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters.const_get(type))
|
ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters.const_get(type))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ActiveRecord::Base.connection.class.class_eval do
|
ActiveRecord::Base.connection.class.class_eval do
|
||||||
|
|
|
@ -557,7 +557,7 @@ class BasicsTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_utc_as_time_zone
|
def test_utc_as_time_zone
|
||||||
# Oracle and SQLServer do not have a TIME datatype.
|
# Oracle and SQLServer do not have a TIME datatype.
|
||||||
return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OracleAdapter)
|
return true if current_adapter?(:SQLServerAdapter, :OracleAdapter)
|
||||||
|
|
||||||
Topic.default_timezone = :utc
|
Topic.default_timezone = :utc
|
||||||
attributes = { "bonus_time" => "5:42:00AM" }
|
attributes = { "bonus_time" => "5:42:00AM" }
|
||||||
|
@ -739,7 +739,7 @@ class BasicsTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_attributes_on_dummy_time
|
def test_attributes_on_dummy_time
|
||||||
# Oracle and SQL Server do not have a TIME datatype.
|
# Oracle and SQL Server do not have a TIME datatype.
|
||||||
return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OracleAdapter)
|
return true if current_adapter?(:SQLServerAdapter, :OracleAdapter)
|
||||||
|
|
||||||
attributes = {
|
attributes = {
|
||||||
"bonus_time" => "5:42:00AM"
|
"bonus_time" => "5:42:00AM"
|
||||||
|
@ -1239,13 +1239,13 @@ class BasicsTest < Test::Unit::TestCase
|
||||||
assert xml.include?(%(<content>Have a nice day</content>))
|
assert xml.include?(%(<content>Have a nice day</content>))
|
||||||
assert xml.include?(%(<author-email-address>david@loudthinking.com</author-email-address>))
|
assert xml.include?(%(<author-email-address>david@loudthinking.com</author-email-address>))
|
||||||
assert xml.match(%(<parent-id type="integer"></parent-id>))
|
assert xml.match(%(<parent-id type="integer"></parent-id>))
|
||||||
if current_adapter?(:SybaseAdapter) or current_adapter?(:SQLServerAdapter) or current_adapter?(:OracleAdapter)
|
if current_adapter?(:SybaseAdapter, :SQLServerAdapter, :OracleAdapter)
|
||||||
assert xml.include?(%(<last-read type="datetime">#{last_read_in_current_timezone}</last-read>))
|
assert xml.include?(%(<last-read type="datetime">#{last_read_in_current_timezone}</last-read>))
|
||||||
else
|
else
|
||||||
assert xml.include?(%(<last-read type="date">2004-04-15</last-read>))
|
assert xml.include?(%(<last-read type="date">2004-04-15</last-read>))
|
||||||
end
|
end
|
||||||
# Oracle and DB2 don't have true boolean or time-only fields
|
# Oracle and DB2 don't have true boolean or time-only fields
|
||||||
unless current_adapter?(:OracleAdapter) || current_adapter?(:DB2Adapter)
|
unless current_adapter?(:OracleAdapter, :DB2Adapter)
|
||||||
assert xml.include?(%(<approved type="boolean">false</approved>)), "Approved should be a boolean"
|
assert xml.include?(%(<approved type="boolean">false</approved>)), "Approved should be a boolean"
|
||||||
assert xml.include?(%(<bonus-time type="datetime">#{bonus_time_in_current_timezone}</bonus-time>))
|
assert xml.include?(%(<bonus-time type="datetime">#{bonus_time_in_current_timezone}</bonus-time>))
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,13 +8,13 @@ class InheritanceTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_a_bad_type_column
|
def test_a_bad_type_column
|
||||||
#SQLServer need to turn Identity Insert On before manually inserting into the Identity column
|
#SQLServer need to turn Identity Insert On before manually inserting into the Identity column
|
||||||
if current_adapter?(:SQLServerAdapter) || current_adapter?(:SybaseAdapter)
|
if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
|
||||||
Company.connection.execute "SET IDENTITY_INSERT companies ON"
|
Company.connection.execute "SET IDENTITY_INSERT companies ON"
|
||||||
end
|
end
|
||||||
Company.connection.insert "INSERT INTO companies (id, #{QUOTED_TYPE}, name) VALUES(100, 'bad_class!', 'Not happening')"
|
Company.connection.insert "INSERT INTO companies (id, #{QUOTED_TYPE}, name) VALUES(100, 'bad_class!', 'Not happening')"
|
||||||
|
|
||||||
#We then need to turn it back Off before continuing.
|
#We then need to turn it back Off before continuing.
|
||||||
if current_adapter?(:SQLServerAdapter) || current_adapter?(:SybaseAdapter)
|
if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
|
||||||
Company.connection.execute "SET IDENTITY_INSERT companies OFF"
|
Company.connection.execute "SET IDENTITY_INSERT companies OFF"
|
||||||
end
|
end
|
||||||
assert_raises(ActiveRecord::SubclassNotFound) { Company.find(100) }
|
assert_raises(ActiveRecord::SubclassNotFound) { Company.find(100) }
|
||||||
|
|
|
@ -108,7 +108,7 @@ class PessimisticLockingTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if current_adapter?(:PostgreSQLAdapter)
|
if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
|
||||||
def test_no_locks_no_wait
|
def test_no_locks_no_wait
|
||||||
first, second = duel { Person.find 1 }
|
first, second = duel { Person.find 1 }
|
||||||
assert first.end > second.end
|
assert first.end > second.end
|
||||||
|
@ -120,7 +120,7 @@ class PessimisticLockingTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def duel(zzz = 0.2)
|
def duel(zzz = 1.0)
|
||||||
t0, t1, t2, t3 = nil, nil, nil, nil
|
t0, t1, t2, t3 = nil, nil, nil, nil
|
||||||
|
|
||||||
a = Thread.new do
|
a = Thread.new do
|
||||||
|
|
|
@ -154,7 +154,7 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
# SQL Server and Sybase will not allow you to add a NOT NULL column
|
# SQL Server and Sybase will not allow you to add a NOT NULL column
|
||||||
# to a table without specifying a default value, so the
|
# to a table without specifying a default value, so the
|
||||||
# following test must be skipped
|
# following test must be skipped
|
||||||
unless current_adapter?(:SQLServerAdapter) || current_adapter?(:SybaseAdapter)
|
unless current_adapter?(:SQLServerAdapter, :SybaseAdapter)
|
||||||
def test_add_column_not_null_without_default
|
def test_add_column_not_null_without_default
|
||||||
Person.connection.create_table :testings do |t|
|
Person.connection.create_table :testings do |t|
|
||||||
t.column :foo, :string
|
t.column :foo, :string
|
||||||
|
@ -207,7 +207,7 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||||
assert_equal Fixnum, bob.age.class
|
assert_equal Fixnum, bob.age.class
|
||||||
assert_equal Time, bob.birthday.class
|
assert_equal Time, bob.birthday.class
|
||||||
|
|
||||||
if current_adapter?(:SQLServerAdapter) || current_adapter?(:OracleAdapter) || current_adapter?(:SybaseAdapter)
|
if current_adapter?(:SQLServerAdapter, :OracleAdapter, :SybaseAdapter)
|
||||||
# SQL Server, Sybase, and Oracle don't differentiate between date/time
|
# SQL Server, Sybase, and Oracle don't differentiate between date/time
|
||||||
assert_equal Time, bob.favorite_day.class
|
assert_equal Time, bob.favorite_day.class
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue