Permalink
Browse files

Rails 2.3.1 compatibility

  • Loading branch information...
1 parent 59b6451 commit b4c289ac55daf98b4fb0ec06d09a75c6a26bc55a @rsanheim rsanheim committed Mar 7, 2009
View
@@ -1,4 +1,4 @@
doc
pkg
*.gem
-
+.treasure_map.rb
View
@@ -59,7 +59,7 @@ task :readme do
sh "open #{file}"
end
-RAILS_VERSIONS = %w[1.2.6 2.0.2 2.1.0 2.1.1 2.2.2]
+RAILS_VERSIONS = %w[1.2.6 2.0.2 2.1.0 2.1.1 2.2.2 2.3.1]
namespace :test do
desc "test with multiple versions of rails"
View
@@ -1,3 +1,16 @@
+module UnitRecord
+ def self.rails_version
+ Rails::VERSION::STRING
+ end
+
+ def self.base_rails_test_class
+ if rails_version >= "2.3.1"
+ ActiveSupport::TestCase
+ else
+ Test::Unit::TestCase
+ end
+ end
+end
require "unit_record/association_stubbing"
require "unit_record/column_extension"
require "unit_record/disconnected_active_record"
@@ -9,7 +22,7 @@
ActiveRecord::ConnectionAdapters::Column.send :include, UnitRecord::ColumnExtension
ActiveRecord::Base.extend UnitRecord::DisconnectedActiveRecord
-Test::Unit::TestCase.extend UnitRecord::DisconnectedTestCase
+UnitRecord.base_rails_test_class.extend UnitRecord::DisconnectedTestCase
Fixtures.extend UnitRecord::DisconnectedFixtures
ActiveRecord::Base.class_eval do
@@ -11,7 +11,7 @@ def disconnect!(options = {})
ActiveRecord::Base.send :include, UnitRecord::AssociationStubbing
end
Fixtures.disconnect!
- Test::Unit::TestCase.disconnect!
+ UnitRecord.base_rails_test_class.disconnect!
ActiveRecord::Migration.verbose = false
ActiveRecord::Base.connection.change_strategy(:noop) do
load(RAILS_ROOT + "/db/schema.rb")
View
@@ -19,6 +19,10 @@
require "unit_record"
+if UnitRecord.rails_version >= "2.3"
+ ActiveSupport::TestCase.class_eval { include ActiveRecord::TestFixtures }
+end
+
# Needed because of this line in setup_with_fixtures and teardown_with_fixtures:
# return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank?
ActiveRecord::Base.configurations = {"irrelevant" => {:adapter => "stub"}}
View
@@ -32,7 +32,12 @@
$LOAD_PATH << File.dirname(__FILE__) + "/../lib"
require "unit_record"
-Test::Unit::TestCase.use_transactional_fixtures = true
+if UnitRecord.rails_version >= "2.3"
+ require "active_support/test_case"
+ ActiveSupport::TestCase.class_eval { include ActiveRecord::TestFixtures }
+end
+
+UnitRecord.base_rails_test_class.use_transactional_fixtures = true
# Needed because of this line in setup_with_fixtures and teardown_with_fixtures:
# return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank?
@@ -18,8 +18,10 @@ class ControllerTest < ActionController::TestCase
assert_equal "OK", @response.body
end
- test "sql caching is enabled" do
- assert_equal true, (SampleController < ActionController::Caching::SqlCache)
+ if defined?(ActionController::Caching::SqlCache) # SqlCache goes away in Rails 2.3.1
+ test "sql caching is enabled" do
+ assert_equal true, (SampleController < ActionController::Caching::SqlCache)
+ end
end
end
@@ -2,13 +2,13 @@
functional_tests do
test "use_transactional_fixtures is false" do
- assert_equal false, Test::Unit::TestCase.use_transactional_fixtures
+ assert_equal false, UnitRecord.base_rails_test_class.use_transactional_fixtures
end
test "trying to use fixtures gives useful message" do
exception = nil
begin
- Class.new(Test::Unit::TestCase) do
+ Class.new(UnitRecord.base_rails_test_class) do
fixtures :users
end
rescue => exception
@@ -0,0 +1,14 @@
+require File.dirname(__FILE__) + "/../test_helper"
+
+unit_tests do
+ if UnitRecord.rails_version > "2.3"
+ test "test case base class" do
+ assert_equal ActiveSupport::TestCase, UnitRecord.base_rails_test_class
+ end
+ else
+ test "test case base class" do
+ assert_equal Test::Unit::TestCase, UnitRecord.base_rails_test_class
+ end
+ end
+
+end

0 comments on commit b4c289a

Please sign in to comment.