Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rails 2.3.1 compatibility

  • Loading branch information...
commit b4c289ac55daf98b4fb0ec06d09a75c6a26bc55a 1 parent 59b6451
@rsanheim rsanheim authored
View
2  .gitignore
@@ -1,4 +1,4 @@
doc
pkg
*.gem
-
+.treasure_map.rb
View
2  Rakefile
@@ -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
15 lib/unit_record.rb
@@ -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
View
2  lib/unit_record/disconnected_active_record.rb
@@ -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
4 test/sample_spec.rb
@@ -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
7 test/test_helper.rb
@@ -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?
View
6 test/unit_record/controller_test.rb
@@ -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
View
4 test/unit_record/disconnected_test_case_test.rb
@@ -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
View
14 test/unit_record/unit_record_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.