Permalink
Browse files

Clean up and run the Active Record integration tests by default.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4804 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent bb531a9 commit 070f3fdc8ce317772358185016f60480105963d6 @jeremy jeremy committed Aug 22, 2006
@@ -1,5 +1,7 @@
*SVN*
+* Clean up and run the Active Record integration tests by default. [Jeremy Kemper]
+
* Correct example in cookies docs. #5832 [jessemerriman@warpmail.net]
* Updated to script.aculo.us 1.6.2 [Thomas Fuchs]
View
@@ -22,7 +22,9 @@ task :default => [ :test ]
# Run the unit tests
-Rake::TestTask.new { |t|
+task :test => [:test_action_pack, :test_active_record_integration]
+
+Rake::TestTask.new(:test_action_pack) { |t|
t.libs << "test"
# make sure we include the controller tests (c*) first as on some systems
# this will not happen automatically and the tests (as a whole) will error
@@ -4,24 +4,35 @@
class ActiveRecordTestConnector
cattr_accessor :able_to_connect
cattr_accessor :connected
-
+
# Set our defaults
self.connected = false
self.able_to_connect = true
end
# Try to grab AR
-begin
- PATH_TO_AR = File.dirname(__FILE__) + '/../../activerecord'
- require "#{PATH_TO_AR}/lib/active_record" unless Object.const_defined?(:ActiveRecord)
- require "#{PATH_TO_AR}/lib/active_record/fixtures" unless Object.const_defined?(:Fixtures)
-rescue Object => e
- $stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}"
- ActiveRecordTestConnector.able_to_connect = false
+if defined?(ActiveRecord) && defined?(Fixtures)
+ $stderr.puts 'Active Record is already loaded, running tests'
+else
+ $stderr.print 'Attempting to load Active Record... '
+ begin
+ PATH_TO_AR = "#{File.dirname(__FILE__)}/../../activerecord/lib"
+ raise "#{PATH_TO_AR} doesn't exist" unless File.directory?(PATH_TO_AR)
+ $LOAD_PATH.unshift PATH_TO_AR
+ require 'active_record'
+ require 'active_record/fixtures'
+ $stderr.puts 'success'
+ rescue Object => e
+ $stderr.print "failed. Skipping Active Record assertion tests: #{e}"
+ ActiveRecordTestConnector.able_to_connect = false
+ end
end
+$stderr.flush
+
+
# Define the rest of the connector
-class ActiveRecordTestConnector
+class ActiveRecordTestConnector
def self.setup
unless self.connected || !self.able_to_connect
setup_connection
@@ -33,12 +44,11 @@ def self.setup
#$stderr.puts " #{e.backtrace.join("\n ")}\n"
self.able_to_connect = false
end
-
+
private
-
+
def self.setup_connection
if Object.const_defined?(:ActiveRecord)
-
begin
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :dbfile => ':memory:')
ActiveRecord::Base.connection
@@ -47,42 +57,44 @@ def self.setup_connection
ActiveRecord::Base.establish_connection(:adapter => 'sqlite', :dbfile => ':memory:')
ActiveRecord::Base.connection
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."
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?
end
end
end
-
-# Test case for inheiritance
+
+# Test case for inheiritance
class ActiveRecordTestCase < Test::Unit::TestCase
# Set our fixture path
- self.fixture_path = "#{File.dirname(__FILE__)}/fixtures/"
-
+ if ActiveRecordTestConnector.able_to_connect
+ self.fixture_path = "#{File.dirname(__FILE__)}/fixtures/"
+ self.use_transactional_fixtures = false
+ end
+
def setup
- abort_tests unless ActiveRecordTestConnector.connected = true
+ abort_tests unless ActiveRecordTestConnector.connected
end
-
+
# Default so Test::Unit::TestCase doesn't complain
def test_truth
end
-
+
private
-
- # If things go wrong, we don't want to run our test cases. We'll just define them to test nothing.
- def abort_tests
- self.class.public_instance_methods.grep(/^test./).each do |method|
- self.class.class_eval { define_method(method.to_sym){} }
+ # If things go wrong, we don't want to run our test cases. We'll just define them to test nothing.
+ def abort_tests
+ self.class.public_instance_methods.grep(/^test./).each do |method|
+ self.class.class_eval { define_method(method.to_sym){} }
+ end
end
- end
end
-ActiveRecordTestConnector.setup
+ActiveRecordTestConnector.setup
@@ -1,5 +1,5 @@
require "#{File.dirname(__FILE__)}/../active_record_unit"
-require 'fixtures/company'
+require 'fixtures/company' if ActiveRecordTestConnector.able_to_connect
class ActiveRecordAssertionsController < ActionController::Base
self.template_root = "#{File.dirname(__FILE__)}/../fixtures/"
@@ -37,10 +37,10 @@ def bad_company
# the safety dance......
def rescue_action(e) raise; end
end
-
+
class ActiveRecordAssertionsControllerTest < ActiveRecordTestCase
- fixtures :companies
-
+ fixtures :companies if ActiveRecordTestConnector.able_to_connect
+
def setup
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@@ -81,4 +81,4 @@ def test_invalid_record
assert_success
assert_invalid_record 'company'
end
-end
+end
@@ -70,6 +70,7 @@ def setup
session_class.create_table!
ENV['REQUEST_METHOD'] = 'GET'
+ ENV['REQUEST_URI'] = '/'
CGI::Session::ActiveRecordStore.session_class = session_class
@cgi = CGI.new
@@ -1,12 +1,16 @@
require File.dirname(__FILE__) + '/../active_record_unit'
-require 'fixtures/topic'
-require 'fixtures/reply'
-require 'fixtures/developer'
-require 'fixtures/project'
+if ActiveRecordTestConnector.able_to_connect
+ require 'fixtures/topic'
+ require 'fixtures/reply'
+ require 'fixtures/developer'
+ require 'fixtures/project'
+end
class PaginationTest < ActiveRecordTestCase
- fixtures :topics, :replies, :developers, :projects, :developers_projects
+ if ActiveRecordTestConnector.able_to_connect
+ fixtures :topics, :replies, :developers, :projects, :developers_projects
+ end
class PaginationController < ActionController::Base
self.template_root = "#{File.dirname(__FILE__)}/../fixtures/"

0 comments on commit 070f3fd

Please sign in to comment.