1
0
Fork 0
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:
Jeremy Kemper 2006-07-07 10:48:43 +00:00
parent 044f960fd3
commit c4782f7393
5 changed files with 67 additions and 65 deletions

View file

@ -49,9 +49,11 @@ class Test::Unit::TestCase #:nodoc:
end
end
def current_adapter?(type)
ActiveRecord::ConnectionAdapters.const_defined?(type) &&
ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters.const_get(type))
def current_adapter?(*types)
types.any? do |type|
ActiveRecord::ConnectionAdapters.const_defined?(type) &&
ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters.const_get(type))
end
end
ActiveRecord::Base.connection.class.class_eval do

View file

@ -557,7 +557,7 @@ class BasicsTest < Test::Unit::TestCase
def test_utc_as_time_zone
# 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
attributes = { "bonus_time" => "5:42:00AM" }
@ -739,7 +739,7 @@ class BasicsTest < Test::Unit::TestCase
def test_attributes_on_dummy_time
# 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 = {
"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?(%(<author-email-address>david@loudthinking.com</author-email-address>))
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>))
else
assert xml.include?(%(<last-read type="date">2004-04-15</last-read>))
end
# 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?(%(<bonus-time type="datetime">#{bonus_time_in_current_timezone}</bonus-time>))
end

View file

@ -8,13 +8,13 @@ class InheritanceTest < Test::Unit::TestCase
def test_a_bad_type_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"
end
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.
if current_adapter?(:SQLServerAdapter) || current_adapter?(:SybaseAdapter)
if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
Company.connection.execute "SET IDENTITY_INSERT companies OFF"
end
assert_raises(ActiveRecord::SubclassNotFound) { Company.find(100) }

View file

@ -108,7 +108,7 @@ class PessimisticLockingTest < Test::Unit::TestCase
end
end
if current_adapter?(:PostgreSQLAdapter)
if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
def test_no_locks_no_wait
first, second = duel { Person.find 1 }
assert first.end > second.end
@ -120,7 +120,7 @@ class PessimisticLockingTest < Test::Unit::TestCase
end
protected
def duel(zzz = 0.2)
def duel(zzz = 1.0)
t0, t1, t2, t3 = nil, nil, nil, nil
a = Thread.new do

View file

@ -154,7 +154,7 @@ if ActiveRecord::Base.connection.supports_migrations?
# SQL Server and Sybase will not allow you to add a NOT NULL column
# to a table without specifying a default value, so the
# 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
Person.connection.create_table :testings do |t|
t.column :foo, :string
@ -207,7 +207,7 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_equal Fixnum, bob.age.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
assert_equal Time, bob.favorite_day.class
else