2004-12-13 18:47:27 -05:00
|
|
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2005-02-17 14:28:13 -05:00
|
|
|
$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
require 'active_record'
|
|
|
|
require 'active_record/fixtures'
|
2005-02-15 10:57:44 -05:00
|
|
|
require 'active_support/binding_of_caller'
|
|
|
|
require 'active_support/breakpoint'
|
2004-11-23 20:04:44 -05:00
|
|
|
require 'connection'
|
|
|
|
|
2005-11-16 03:16:54 -05:00
|
|
|
QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type') unless Object.const_defined?(:QUOTED_TYPE)
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Test::Unit::TestCase #:nodoc:
|
2005-09-29 21:00:04 -04:00
|
|
|
self.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
|
|
|
self.use_instantiated_fixtures = false
|
|
|
|
self.use_transactional_fixtures = (ENV['AR_NO_TX_FIXTURES'] != "yes")
|
|
|
|
|
|
|
|
def create_fixtures(*table_names, &block)
|
2006-02-27 15:29:28 -05:00
|
|
|
Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", table_names, {}, &block)
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-01-21 18:20:00 -05:00
|
|
|
|
|
|
|
def assert_date_from_db(expected, actual, message = nil)
|
|
|
|
# SQL Server doesn't have a separate column type just for dates,
|
|
|
|
# so the time is in the string and incorrectly formatted
|
2006-03-17 22:02:32 -05:00
|
|
|
if current_adapter?(:SQLServerAdapter)
|
2006-01-21 18:20:00 -05:00
|
|
|
assert_equal expected.strftime("%Y/%m/%d 00:00:00"), actual.strftime("%Y/%m/%d 00:00:00")
|
2006-03-17 22:02:32 -05:00
|
|
|
elsif current_adapter?(:SybaseAdapter)
|
|
|
|
assert_equal expected.to_s, actual.to_date.to_s, message
|
2006-01-21 18:20:00 -05:00
|
|
|
else
|
|
|
|
assert_equal expected.to_s, actual.to_s, message
|
|
|
|
end
|
|
|
|
end
|
2006-03-05 13:43:56 -05:00
|
|
|
|
2006-03-05 18:41:17 -05:00
|
|
|
def assert_queries(num = 1)
|
2006-03-05 13:43:56 -05:00
|
|
|
ActiveRecord::Base.connection.class.class_eval do
|
|
|
|
self.query_count = 0
|
|
|
|
alias_method :execute, :execute_with_query_counting
|
|
|
|
end
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
ActiveRecord::Base.connection.class.class_eval do
|
|
|
|
alias_method :execute, :execute_without_query_counting
|
|
|
|
end
|
2006-03-05 18:41:17 -05:00
|
|
|
assert_equal num, ActiveRecord::Base.connection.query_count, "#{ActiveRecord::Base.connection.query_count} instead of #{num} queries were executed."
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_no_queries(&block)
|
|
|
|
assert_queries(0, &block)
|
2006-03-05 13:43:56 -05:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2005-10-27 04:18:41 -04:00
|
|
|
|
|
|
|
def current_adapter?(type)
|
|
|
|
ActiveRecord::ConnectionAdapters.const_defined?(type) &&
|
|
|
|
ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters.const_get(type))
|
|
|
|
end
|
2005-11-19 04:53:36 -05:00
|
|
|
|
2006-03-05 13:43:56 -05:00
|
|
|
ActiveRecord::Base.connection.class.class_eval do
|
|
|
|
cattr_accessor :query_count
|
|
|
|
alias_method :execute_without_query_counting, :execute
|
|
|
|
def execute_with_query_counting(sql, name = nil)
|
|
|
|
self.query_count += 1
|
|
|
|
execute_without_query_counting(sql, name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-19 04:53:36 -05:00
|
|
|
#ActiveRecord::Base.logger = Logger.new(STDOUT)
|
|
|
|
#ActiveRecord::Base.colorize_logging = false
|