Permalink
Browse files

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
  • Loading branch information...
1 parent 044f960 commit c4782f7393029eeacc599a7921939744d1fe22cd @jeremy jeremy committed Jul 7, 2006
@@ -18,9 +18,9 @@ class Test::Unit::TestCase #:nodoc:
def create_fixtures(*table_names, &block)
Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", table_names, {}, &block)
end
-
+
def assert_date_from_db(expected, actual, message = nil)
- # SQL Server doesn't have a separate column type just for dates,
+ # SQL Server doesn't have a separate column type just for dates,
# so the time is in the string and incorrectly formatted
if current_adapter?(:SQLServerAdapter)
assert_equal expected.strftime("%Y/%m/%d 00:00:00"), actual.strftime("%Y/%m/%d 00:00:00")
@@ -49,17 +49,19 @@ def assert_no_queries(&block)
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
cattr_accessor :query_count
-
+
# Array of regexes of queries that are not counted against query_count
@@ignore_list = [/^SELECT currval/, /^SELECT CAST/]
-
+
alias_method :execute_without_query_counting, :execute
def execute_with_query_counting(sql, name = nil)
self.query_count += 1 unless @@ignore_list.any? { |r| sql =~ r }
@@ -557,7 +557,7 @@ def test_default_values
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 @@ def test_multiparameter_assignment_of_aggregation
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 @@ def test_to_xml
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
@@ -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) }
@@ -108,7 +108,7 @@ def test_sane_lock_method
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 @@ def test_second_lock_waits
end
protected
- def duel(zzz = 0.2)
+ def duel(zzz = 1.0)
t0, t1, t2, t3 = nil, nil, nil, nil
a = Thread.new do
Oops, something went wrong.

0 comments on commit c4782f7

Please sign in to comment.