1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/helper.rb
Murray Steele 8a92cdc863 Add a repair_helper to repair changes to the validations inside validations_test.rb [#674 state:resolved]
Many of the tests in validations_test would add a new validation to
models.  However, only Topic was being reset with a fairly aggressive
clearing of all validations.  None of the other models being used however
were recieving the same treatment.  Now we use repair_validations(Topic)
for the whole test case because most test cases use Topic and then the
block form of repair_validations(<other_models>) inside any tests that use
other models.

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
2008-12-19 13:37:50 +00:00

74 lines
2.1 KiB
Ruby

$:.unshift(File.dirname(__FILE__) + '/../../lib')
$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib')
require 'config'
require 'test/unit'
require 'active_record'
require 'active_record/test_case'
require 'active_record/fixtures'
require 'connection'
require 'cases/repair_helper'
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
# Quote "type" if it's a reserved word for the current connection.
QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type')
def current_adapter?(*types)
types.any? do |type|
ActiveRecord::ConnectionAdapters.const_defined?(type) &&
ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters.const_get(type))
end
end
def uses_mocha(description)
require 'rubygems'
gem 'mocha', '>= 0.9.3'
require 'mocha'
yield
rescue LoadError
$stderr.puts "Skipping #{description} tests. `gem install mocha` and try again."
end
ActiveRecord::Base.connection.class.class_eval do
IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/]
def execute_with_query_record(sql, name = nil, &block)
$queries_executed ||= []
$queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
execute_without_query_record(sql, name, &block)
end
alias_method_chain :execute, :query_record
end
# Make with_scope public for tests
class << ActiveRecord::Base
public :with_scope, :with_exclusive_scope
end
unless ENV['FIXTURE_DEBUG']
module ActiveRecord::TestFixtures::ClassMethods
def try_to_load_dependency_with_silence(*args)
ActiveRecord::Base.logger.silence { try_to_load_dependency_without_silence(*args)}
end
alias_method_chain :try_to_load_dependency, :silence
end
end
class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
include ActiveRecord::Testing::RepairHelper
self.fixture_path = FIXTURES_ROOT
self.use_instantiated_fixtures = false
self.use_transactional_fixtures = true
def create_fixtures(*table_names, &block)
Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block)
end
end