aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-07-07 10:48:43 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-07-07 10:48:43 +0000
commitc4782f7393029eeacc599a7921939744d1fe22cd (patch)
tree54218c45c6b055f2deafa6372fdc2fe87de5515a /activerecord
parent044f960fd35a93159d1e0278124109dd74107670 (diff)
downloadrails-c4782f7393029eeacc599a7921939744d1fe22cd.tar.gz
rails-c4782f7393029eeacc599a7921939744d1fe22cd.tar.bz2
rails-c4782f7393029eeacc599a7921939744d1fe22cd.zip
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
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/test/abstract_unit.rb16
-rwxr-xr-xactiverecord/test/base_test.rb8
-rwxr-xr-xactiverecord/test/inheritance_test.rb4
-rw-r--r--activerecord/test/locking_test.rb4
-rw-r--r--activerecord/test/migration_test.rb100
5 files changed, 67 insertions, 65 deletions
diff --git a/activerecord/test/abstract_unit.rb b/activerecord/test/abstract_unit.rb
index 761e29c741..4628293449 100755
--- a/activerecord/test/abstract_unit.rb
+++ b/activerecord/test/abstract_unit.rb
@@ -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 @@ 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
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 }
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 9299fd998a..9d010c813a 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -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
diff --git a/activerecord/test/inheritance_test.rb b/activerecord/test/inheritance_test.rb
index 211f739752..db10e1f048 100755
--- a/activerecord/test/inheritance_test.rb
+++ b/activerecord/test/inheritance_test.rb
@@ -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) }
diff --git a/activerecord/test/locking_test.rb b/activerecord/test/locking_test.rb
index 35c557e19d..8ddfb2289c 100644
--- a/activerecord/test/locking_test.rb
+++ b/activerecord/test/locking_test.rb
@@ -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
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index 2e6868b7e2..0429f10e5b 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -4,7 +4,7 @@ require 'fixtures/topic'
require File.dirname(__FILE__) + '/fixtures/migrations/1_people_have_last_names'
require File.dirname(__FILE__) + '/fixtures/migrations/2_we_need_reminders'
-if ActiveRecord::Base.connection.supports_migrations?
+if ActiveRecord::Base.connection.supports_migrations?
class Reminder < ActiveRecord::Base; end
class ActiveRecord::Migration
@@ -47,16 +47,16 @@ if ActiveRecord::Base.connection.supports_migrations?
end
def test_add_index
- Person.connection.add_column "people", "last_name", :string
+ Person.connection.add_column "people", "last_name", :string
Person.connection.add_column "people", "administrator", :boolean
Person.connection.add_column "people", "key", :string
-
+
assert_nothing_raised { Person.connection.add_index("people", "last_name") }
assert_nothing_raised { Person.connection.remove_index("people", "last_name") }
assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
assert_nothing_raised { Person.connection.remove_index("people", "last_name") }
-
+
# quoting
assert_nothing_raised { Person.connection.add_index("people", ["key"], :name => "key", :unique => true) }
assert_nothing_raised { Person.connection.remove_index("people", :name => "key", :unique => true) }
@@ -150,17 +150,17 @@ if ActiveRecord::Base.connection.supports_migrations?
ensure
Person.connection.drop_table :testings rescue nil
end
-
+
# 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)
+ # following test must be skipped
+ unless current_adapter?(:SQLServerAdapter, :SybaseAdapter)
def test_add_column_not_null_without_default
Person.connection.create_table :testings do |t|
t.column :foo, :string
end
Person.connection.add_column :testings, :bar, :string, :null => false
-
+
assert_raises(ActiveRecord::StatementInvalid) do
Person.connection.execute "insert into testings (foo, bar) values ('hello', NULL)"
end
@@ -168,7 +168,7 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.connection.drop_table :testings rescue nil
end
end
-
+
def test_add_column_not_null_with_default
Person.connection.create_table :testings, :id => false do |t|
t.column :foo, :string
@@ -182,7 +182,7 @@ if ActiveRecord::Base.connection.supports_migrations?
ensure
Person.connection.drop_table :testings rescue nil
end
-
+
def test_native_types
Person.delete_all
Person.connection.add_column "people", "last_name", :string
@@ -194,20 +194,20 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.connection.add_column "people", "male", :boolean
assert_nothing_raised { Person.create :first_name => 'bob', :last_name => 'bobsen', :bio => "I was born ....", :age => 18, :height => 1.78, :birthday => 18.years.ago, :favorite_day => 10.days.ago, :male => true }
bob = Person.find(:first)
-
+
assert_equal bob.first_name, 'bob'
assert_equal bob.last_name, 'bobsen'
assert_equal bob.bio, "I was born ...."
assert_equal bob.age, 18
assert_equal bob.male?, true
-
+
assert_equal String, bob.first_name.class
assert_equal String, bob.last_name.class
assert_equal String, bob.bio.class
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
@@ -224,7 +224,7 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.reset_column_information
assert Person.column_methods_hash.include?(:last_name)
-
+
ActiveRecord::Migration.remove_column 'people', 'last_name'
Person.reset_column_information
@@ -244,27 +244,27 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.reset_column_information
assert !Person.column_methods_hash.include?(:last_name)
end
-
+
def test_add_rename
Person.delete_all
-
+
begin
- Person.connection.add_column "people", "girlfriend", :string
- Person.create :girlfriend => 'bobette'
-
+ Person.connection.add_column "people", "girlfriend", :string
+ Person.create :girlfriend => 'bobette'
+
Person.connection.rename_column "people", "girlfriend", "exgirlfriend"
-
- Person.reset_column_information
+
+ Person.reset_column_information
bob = Person.find(:first)
-
+
assert_equal "bobette", bob.exgirlfriend
ensure
Person.connection.remove_column("people", "girlfriend") rescue nil
Person.connection.remove_column("people", "exgirlfriend") rescue nil
end
-
+
end
-
+
def test_rename_column_using_symbol_arguments
begin
Person.connection.rename_column :people, :first_name, :nick_name
@@ -275,7 +275,7 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.connection.add_column("people","first_name", :string)
end
end
-
+
def test_rename_column
begin
Person.connection.rename_column "people", "first_name", "nick_name"
@@ -286,7 +286,7 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.connection.add_column("people","first_name", :string)
end
end
-
+
def test_rename_table
begin
ActiveRecord::Base.connection.create_table :octopuses do |t|
@@ -317,7 +317,7 @@ if ActiveRecord::Base.connection.supports_migrations?
assert old_columns.find { |c| c.name == 'age' and c.type == :integer }
assert_nothing_raised { Person.connection.change_column "people", "age", :string }
-
+
new_columns = Person.connection.columns(Person.table_name, "#{name} Columns")
assert_nil new_columns.find { |c| c.name == 'age' and c.type == :integer }
assert new_columns.find { |c| c.name == 'age' and c.type == :string }
@@ -329,26 +329,26 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_nil new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true }
assert new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == false }
assert_nothing_raised { Topic.connection.change_column :topics, :approved, :boolean, :default => true }
- end
+ end
def test_change_column_with_new_default
Person.connection.add_column "people", "administrator", :boolean, :default => 1
- Person.reset_column_information
+ Person.reset_column_information
assert Person.new.administrator?
-
+
assert_nothing_raised { Person.connection.change_column "people", "administrator", :boolean, :default => 0 }
- Person.reset_column_information
+ Person.reset_column_information
assert !Person.new.administrator?
- end
+ end
def test_add_table
assert !Reminder.table_exists?
-
+
WeNeedReminders.up
-
+
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
assert_equal "hello world", Reminder.find(:first).content
-
+
WeNeedReminders.down
assert_raises(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
end
@@ -376,7 +376,7 @@ if ActiveRecord::Base.connection.supports_migrations?
def test_migrator_one_up
assert !Person.column_methods_hash.include?(:last_name)
assert !Reminder.table_exists?
-
+
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
Person.reset_column_information
@@ -388,17 +388,17 @@ if ActiveRecord::Base.connection.supports_migrations?
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
assert_equal "hello world", Reminder.find(:first).content
end
-
+
def test_migrator_one_down
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/')
-
+
ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
Person.reset_column_information
assert Person.column_methods_hash.include?(:last_name)
assert !Reminder.table_exists?
end
-
+
def test_migrator_one_up_one_down
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 0)
@@ -406,7 +406,7 @@ if ActiveRecord::Base.connection.supports_migrations?
assert !Person.column_methods_hash.include?(:last_name)
assert !Reminder.table_exists?
end
-
+
def test_migrator_verbosity
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
assert PeopleHaveLastNames.message_count > 0
@@ -416,7 +416,7 @@ if ActiveRecord::Base.connection.supports_migrations?
assert PeopleHaveLastNames.message_count > 0
PeopleHaveLastNames.message_count = 0
end
-
+
def test_migrator_verbosity_off
PeopleHaveLastNames.verbose = false
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
@@ -424,7 +424,7 @@ if ActiveRecord::Base.connection.supports_migrations?
ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 0)
assert PeopleHaveLastNames.message_count.zero?
end
-
+
def test_migrator_going_down_due_to_version_target
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/fixtures/migrations/', 0)
@@ -453,14 +453,14 @@ if ActiveRecord::Base.connection.supports_migrations?
ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""
end
-
+
def test_proper_table_name
assert_equal "table", ActiveRecord::Migrator.proper_table_name('table')
assert_equal "table", ActiveRecord::Migrator.proper_table_name(:table)
assert_equal "reminders", ActiveRecord::Migrator.proper_table_name(Reminder)
Reminder.reset_table_name
assert_equal Reminder.table_name, ActiveRecord::Migrator.proper_table_name(Reminder)
-
+
# Use the model's own prefix/suffix if a model is given
ActiveRecord::Base.table_name_prefix = "ARprefix_"
ActiveRecord::Base.table_name_suffix = "_ARsuffix"
@@ -471,8 +471,8 @@ if ActiveRecord::Base.connection.supports_migrations?
Reminder.table_name_prefix = ''
Reminder.table_name_suffix = ''
Reminder.reset_table_name
-
- # Use AR::Base's prefix/suffix if string or symbol is given
+
+ # Use AR::Base's prefix/suffix if string or symbol is given
ActiveRecord::Base.table_name_prefix = "prefix_"
ActiveRecord::Base.table_name_suffix = "_suffix"
Reminder.reset_table_name
@@ -481,7 +481,7 @@ if ActiveRecord::Base.connection.supports_migrations?
ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""
Reminder.reset_table_name
- end
+ end
def test_add_drop_table_with_prefix_and_suffix
assert !Reminder.table_exists?
@@ -502,17 +502,17 @@ if ActiveRecord::Base.connection.supports_migrations?
Reminder.reset_sequence_name
end
-# FrontBase does not support default values on BLOB/CLOB columns
+# FrontBase does not support default values on BLOB/CLOB columns
unless current_adapter?(:FrontBaseAdapter)
def test_create_table_with_binary_column
Person.connection.drop_table :binary_testings rescue nil
-
+
assert_nothing_raised {
Person.connection.create_table :binary_testings do |t|
t.column "data", :binary, :default => "", :null => false
end
}
-
+
columns = Person.connection.columns(:binary_testings)
data_column = columns.detect { |c| c.name == "data" }