aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-08-22 04:38:03 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-08-22 04:38:03 +0000
commit070f3fdc8ce317772358185016f60480105963d6 (patch)
tree9a7b6075bd01b79404a3efc372cb9b0e8bfac45c
parentbb531a946d016ab0f41d91a4858a62156e65333e (diff)
downloadrails-070f3fdc8ce317772358185016f60480105963d6.tar.gz
rails-070f3fdc8ce317772358185016f60480105963d6.tar.bz2
rails-070f3fdc8ce317772358185016f60480105963d6.zip
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
-rw-r--r--actionpack/CHANGELOG2
-rwxr-xr-xactionpack/Rakefile4
-rw-r--r--actionpack/test/active_record_unit.rb68
-rw-r--r--actionpack/test/activerecord/active_record_assertions_test.rb10
-rw-r--r--actionpack/test/activerecord/active_record_store_test.rb1
-rw-r--r--actionpack/test/activerecord/pagination_test.rb14
6 files changed, 60 insertions, 39 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index f2f969a53f..644e2167e7 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -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]
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
index 0cdd8e1683..0a6e96926f 100755
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -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
diff --git a/actionpack/test/active_record_unit.rb b/actionpack/test/active_record_unit.rb
index 016f331d77..3ab9b6a50e 100644
--- a/actionpack/test/active_record_unit.rb
+++ b/actionpack/test/active_record_unit.rb
@@ -4,24 +4,35 @@ require File.dirname(__FILE__) + '/abstract_unit'
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 @@ class ActiveRecordTestConnector
#$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,13 +57,13 @@ class ActiveRecordTestConnector
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|
@@ -61,28 +71,30 @@ class ActiveRecordTestConnector
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 \ No newline at end of file
+ActiveRecordTestConnector.setup
diff --git a/actionpack/test/activerecord/active_record_assertions_test.rb b/actionpack/test/activerecord/active_record_assertions_test.rb
index f5661d19cc..ebb7774fc9 100644
--- a/actionpack/test/activerecord/active_record_assertions_test.rb
+++ b/actionpack/test/activerecord/active_record_assertions_test.rb
@@ -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 @@ class ActiveRecordAssertionsController < ActionController::Base
# 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 @@ class ActiveRecordAssertionsControllerTest < ActiveRecordTestCase
assert_success
assert_invalid_record 'company'
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb
index 96c147c7d0..f85bdeb466 100644
--- a/actionpack/test/activerecord/active_record_store_test.rb
+++ b/actionpack/test/activerecord/active_record_store_test.rb
@@ -70,6 +70,7 @@ class ActiveRecordStoreTest < Test::Unit::TestCase
session_class.create_table!
ENV['REQUEST_METHOD'] = 'GET'
+ ENV['REQUEST_URI'] = '/'
CGI::Session::ActiveRecordStore.session_class = session_class
@cgi = CGI.new
diff --git a/actionpack/test/activerecord/pagination_test.rb b/actionpack/test/activerecord/pagination_test.rb
index 386300c086..a32dd0369a 100644
--- a/actionpack/test/activerecord/pagination_test.rb
+++ b/actionpack/test/activerecord/pagination_test.rb
@@ -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/"