From 767eaa9df13549037f053c89a0a0d334b3086873 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 22 Aug 2006 09:19:55 +0000 Subject: Clean up and run the Active Record integration tests by default. Closes #5854. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4807 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/abstract_unit.rb | 1 - actionpack/test/active_record_unit.rb | 71 +++++++++++++--------- .../activerecord/active_record_assertions_test.rb | 3 +- .../test/activerecord/active_record_store_test.rb | 35 +---------- actionpack/test/activerecord/pagination_test.rb | 13 +--- 5 files changed, 47 insertions(+), 76 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 94fcae4caf..4d858dfa0c 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -6,7 +6,6 @@ require 'yaml' require 'test/unit' require 'action_controller' require 'breakpoint' - require 'action_controller/test_process' ActionController::Base.logger = nil diff --git a/actionpack/test/active_record_unit.rb b/actionpack/test/active_record_unit.rb index 3ab9b6a50e..1a17977ff5 100644 --- a/actionpack/test/active_record_unit.rb +++ b/actionpack/test/active_record_unit.rb @@ -33,41 +33,52 @@ $stderr.flush # Define the rest of the connector class ActiveRecordTestConnector - def self.setup - unless self.connected || !self.able_to_connect - setup_connection - load_schema - self.connected = true + class << self + def setup + unless self.connected || !self.able_to_connect + setup_connection + load_schema + require_fixture_models + self.connected = true + end + rescue Object => e + $stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}" + #$stderr.puts " #{e.backtrace.join("\n ")}\n" + self.able_to_connect = false end - rescue Object => e - $stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}" - #$stderr.puts " #{e.backtrace.join("\n ")}\n" - self.able_to_connect = false - end - private + private + + def setup_connection + if Object.const_defined?(:ActiveRecord) + begin + connection_options = {:adapter => 'sqlite3', :dbfile => ':memory:'} + ActiveRecord::Base.establish_connection(connection_options) + ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => connection_options } + ActiveRecord::Base.connection + rescue Object + $stderr.puts 'SQLite 3 unavailable; falling to SQLite 2.' + connection_options = {:adapter => 'sqlite', :dbfile => ':memory:'} + ActiveRecord::Base.establish_connection(connection_options) + ActiveRecord::Base.configurations = { 'sqlite2_ar_integration' => connection_options } + ActiveRecord::Base.connection + end - def self.setup_connection - if Object.const_defined?(:ActiveRecord) - begin - ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :dbfile => ':memory:') - ActiveRecord::Base.connection - rescue Object - $stderr.puts 'SQLite 3 unavailable; falling to SQLite 2.' - ActiveRecord::Base.establish_connection(:adapter => 'sqlite', :dbfile => ':memory:') - ActiveRecord::Base.connection + Object.send(:const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')) unless Object.const_defined?(:QUOTED_TYPE) + else + raise "Couldn't locate ActiveRecord." end + end - Object.send(:const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')) unless Object.const_defined?(:QUOTED_TYPE) - else - raise "Couldn't locate ActiveRecord." + # Load actionpack sqlite tables + def load_schema + File.read(File.dirname(__FILE__) + "/fixtures/db_definitions/sqlite.sql").split(';').each do |sql| + ActiveRecord::Base.connection.execute(sql) unless sql.blank? + end end - end - # Load actionpack sqlite tables - def self.load_schema - File.read(File.dirname(__FILE__) + "/fixtures/db_definitions/sqlite.sql").split(';').each do |sql| - ActiveRecord::Base.connection.execute(sql) unless sql.blank? + def require_fixture_models + Dir.glob(File.dirname(__FILE__) + "/fixtures/*.rb").each {|f| require f} end end end @@ -80,6 +91,10 @@ class ActiveRecordTestCase < Test::Unit::TestCase self.use_transactional_fixtures = false end + def self.fixtures(*args) + super if ActiveRecordTestConnector.connected + end + def setup abort_tests unless ActiveRecordTestConnector.connected end diff --git a/actionpack/test/activerecord/active_record_assertions_test.rb b/actionpack/test/activerecord/active_record_assertions_test.rb index ebb7774fc9..6662d3d10c 100644 --- a/actionpack/test/activerecord/active_record_assertions_test.rb +++ b/actionpack/test/activerecord/active_record_assertions_test.rb @@ -1,5 +1,4 @@ require "#{File.dirname(__FILE__)}/../active_record_unit" -require 'fixtures/company' if ActiveRecordTestConnector.able_to_connect class ActiveRecordAssertionsController < ActionController::Base self.template_root = "#{File.dirname(__FILE__)}/../fixtures/" @@ -39,7 +38,7 @@ class ActiveRecordAssertionsController < ActionController::Base end class ActiveRecordAssertionsControllerTest < ActiveRecordTestCase - fixtures :companies if ActiveRecordTestConnector.able_to_connect + fixtures :companies def setup @request = ActionController::TestRequest.new diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb index f85bdeb466..3bb37a2274 100644 --- a/actionpack/test/activerecord/active_record_store_test.rb +++ b/actionpack/test/activerecord/active_record_store_test.rb @@ -1,33 +1,8 @@ -# Unfurl the safety net. -path_to_ar = File.dirname(__FILE__) + '/../../../activerecord' -if Object.const_defined?(:ActiveRecord) or File.exist?(path_to_ar) - begin - # These tests exercise CGI::Session::ActiveRecordStore, so you're going to # need AR in a sibling directory to AP and have SQLite installed. - -unless Object.const_defined?(:ActiveRecord) - require File.join(path_to_ar, 'lib', 'active_record') -end - -require File.dirname(__FILE__) + '/../abstract_unit' +require File.dirname(__FILE__) + '/../active_record_unit' require 'action_controller/session/active_record_store' -#ActiveRecord::Base.logger = Logger.new($stdout) -begin - CGI::Session::ActiveRecordStore::Session.establish_connection(:adapter => 'sqlite3', :database => ':memory:') - CGI::Session::ActiveRecordStore::Session.connection -rescue Object - $stderr.puts 'SQLite 3 unavailable; falling back to SQLite 2.' - begin - CGI::Session::ActiveRecordStore::Session.establish_connection(:adapter => 'sqlite', :database => ':memory:') - CGI::Session::ActiveRecordStore::Session.connection - rescue Object - $stderr.puts 'SQLite 2 unavailable; skipping ActiveRecordStore test suite.' - raise SystemExit - end -end - module CommonActiveRecordStoreTests def test_basics @@ -165,11 +140,3 @@ class SqlBypassActiveRecordStoreTest < ActiveRecordStoreTest assert_equal({ 'foo' => 'bar' }, @new_session.model.data) end end - - -# End of safety net. - rescue Object => e - $stderr.puts "Skipping CGI::Session::ActiveRecordStore tests: #{e}" - #$stderr.puts " #{e.backtrace.join("\n ")}" - end -end diff --git a/actionpack/test/activerecord/pagination_test.rb b/actionpack/test/activerecord/pagination_test.rb index a32dd0369a..ddd2cec8b3 100644 --- a/actionpack/test/activerecord/pagination_test.rb +++ b/actionpack/test/activerecord/pagination_test.rb @@ -1,17 +1,8 @@ require File.dirname(__FILE__) + '/../active_record_unit' -if ActiveRecordTestConnector.able_to_connect - require 'fixtures/topic' - require 'fixtures/reply' - require 'fixtures/developer' - require 'fixtures/project' -end - class PaginationTest < ActiveRecordTestCase - if ActiveRecordTestConnector.able_to_connect - fixtures :topics, :replies, :developers, :projects, :developers_projects - end - + fixtures :topics, :replies, :developers, :projects, :developers_projects + class PaginationController < ActionController::Base self.template_root = "#{File.dirname(__FILE__)}/../fixtures/" -- cgit v1.2.3