aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/active_record_unit.rb6
-rw-r--r--actionpack/test/activerecord/render_partial_with_record_identification_test.rb22
-rw-r--r--actionpack/test/controller/action_pack_assertions_test.rb26
-rw-r--r--actionpack/test/controller/assert_select_test.rb131
-rw-r--r--actionpack/test/controller/base_test.rb2
-rw-r--r--actionpack/test/controller/caching_test.rb20
-rw-r--r--actionpack/test/controller/cgi_test.rb3
-rw-r--r--actionpack/test/controller/components_test.rb8
-rw-r--r--actionpack/test/controller/deprecation/deprecated_base_methods_test.rb20
-rw-r--r--actionpack/test/controller/html-scanner/sanitizer_test.rb2
-rw-r--r--actionpack/test/controller/layout_test.rb33
-rw-r--r--actionpack/test/controller/mime_responds_test.rb16
-rw-r--r--actionpack/test/controller/polymorphic_routes_test.rb3
-rw-r--r--actionpack/test/controller/redirect_test.rb16
-rw-r--r--actionpack/test/controller/render_test.rb32
-rw-r--r--actionpack/test/controller/request_forgery_protection_test.rb10
-rw-r--r--actionpack/test/controller/request_test.rb40
-rw-r--r--actionpack/test/controller/resources_test.rb2
-rw-r--r--actionpack/test/controller/test_test.rb26
-rw-r--r--actionpack/test/controller/url_rewriter_test.rb5
-rw-r--r--actionpack/test/controller/verification_test.rb2
-rw-r--r--actionpack/test/controller/view_paths_test.rb2
-rw-r--r--actionpack/test/template/atom_feed_helper_test.rb8
23 files changed, 177 insertions, 258 deletions
diff --git a/actionpack/test/active_record_unit.rb b/actionpack/test/active_record_unit.rb
index a377ccad24..d8d2e00dc2 100644
--- a/actionpack/test/active_record_unit.rb
+++ b/actionpack/test/active_record_unit.rb
@@ -82,7 +82,9 @@ class ActiveRecordTestConnector
end
end
-class ActiveRecordTestCase < ActiveSupport::TestCase
+class ActiveRecordTestCase < ActionController::TestCase
+ include ActiveRecord::TestFixtures
+
# Set our fixture path
if ActiveRecordTestConnector.able_to_connect
self.fixture_path = [FIXTURE_LOAD_PATH]
@@ -96,8 +98,6 @@ class ActiveRecordTestCase < ActiveSupport::TestCase
def run(*args)
super if ActiveRecordTestConnector.connected
end
-
- def default_test; end
end
ActiveRecordTestConnector.setup
diff --git a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
index d75cb2b53a..147b270808 100644
--- a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
+++ b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
@@ -47,15 +47,9 @@ class RenderPartialWithRecordIdentificationController < ActionController::Base
end
class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
+ tests RenderPartialWithRecordIdentificationController
fixtures :developers, :projects, :developers_projects, :topics, :replies, :companies, :mascots
- def setup
- @controller = RenderPartialWithRecordIdentificationController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- super
- end
-
def test_rendering_partial_with_has_many_and_belongs_to_association
get :render_with_has_many_and_belongs_to_association
assert_template 'projects/_project'
@@ -162,12 +156,7 @@ module Fun
end
class RenderPartialWithRecordIdentificationAndNestedControllersTest < ActiveRecordTestCase
- def setup
- @controller = Fun::NestedController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- super
- end
+ tests Fun::NestedController
def test_render_with_record_in_nested_controller
get :render_with_record_in_nested_controller
@@ -183,12 +172,7 @@ class RenderPartialWithRecordIdentificationAndNestedControllersTest < ActiveReco
end
class RenderPartialWithRecordIdentificationAndNestedDeeperControllersTest < ActiveRecordTestCase
- def setup
- @controller = Fun::Serious::NestedDeeperController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- super
- end
+ tests Fun::Serious::NestedDeeperController
def test_render_with_record_in_deeper_nested_controller
get :render_with_record_in_deeper_nested_controller
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index 56ba36cee5..7050000dd8 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -165,13 +165,11 @@ module Admin
end
# a test case to exercise the new capabilities TestRequest & TestResponse
-class ActionPackAssertionsControllerTest < Test::Unit::TestCase
+class ActionPackAssertionsControllerTest < ActionController::TestCase
# let's get this party started
def setup
ActionController::Routing::Routes.reload
ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module user content admin/user))
- @controller = ActionPackAssertionsController.new
- @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
end
def teardown
@@ -235,13 +233,13 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
map.connect ':controller/:action/:id'
end
process :redirect_to_named_route
- assert_raise(Test::Unit::AssertionFailedError) do
+ assert_raise(ActiveSupport::TestCase::Assertion) do
assert_redirected_to 'http://test.host/route_two'
end
- assert_raise(Test::Unit::AssertionFailedError) do
+ assert_raise(ActiveSupport::TestCase::Assertion) do
assert_redirected_to :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
end
- assert_raise(Test::Unit::AssertionFailedError) do
+ assert_raise(ActiveSupport::TestCase::Assertion) do
assert_redirected_to route_two_url
end
end
@@ -410,7 +408,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
def test_assert_redirection_fails_with_incorrect_controller
process :redirect_to_controller
- assert_raise(Test::Unit::AssertionFailedError) do
+ assert_raise(ActiveSupport::TestCase::Assertion) do
assert_redirected_to :controller => "action_pack_assertions", :action => "flash_me"
end
end
@@ -466,7 +464,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
begin
assert_valid assigns('record')
assert false
- rescue Test::Unit::AssertionFailedError => e
+ rescue ActiveSupport::TestCase::Assertion => e
end
end
@@ -475,7 +473,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
get :index
assert_response :success
flunk 'Expected non-success response'
- rescue Test::Unit::AssertionFailedError => e
+ rescue ActiveSupport::TestCase::Assertion => e
assert e.message.include?('FAIL')
end
@@ -484,17 +482,15 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
get :show
assert_response :success
flunk 'Expected non-success response'
- rescue Test::Unit::AssertionFailedError
+ rescue ActiveSupport::TestCase::Assertion
+ # success
rescue
flunk "assert_response failed to handle failure response with missing, but optional, exception."
end
end
-class ActionPackHeaderTest < Test::Unit::TestCase
- def setup
- @controller = ActionPackAssertionsController.new
- @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
- end
+class ActionPackHeaderTest < ActionController::TestCase
+ tests ActionPackAssertionsController
def test_rendering_xml_sets_content_type
process :hello_xml_world
diff --git a/actionpack/test/controller/assert_select_test.rb b/actionpack/test/controller/assert_select_test.rb
index 08cbcbf302..a79278159d 100644
--- a/actionpack/test/controller/assert_select_test.rb
+++ b/actionpack/test/controller/assert_select_test.rb
@@ -19,7 +19,18 @@ end
ActionMailer::Base.template_root = FIXTURE_LOAD_PATH
-class AssertSelectTest < Test::Unit::TestCase
+class AssertSelectTest < ActionController::TestCase
+ Assertion = ActiveSupport::TestCase::Assertion
+
+ class AssertSelectMailer < ActionMailer::Base
+ def test(html)
+ recipients "test <test@test.host>"
+ from "test@test.host"
+ subject "Test e-mail"
+ part :content_type=>"text/html", :body=>html
+ end
+ end
+
class AssertSelectController < ActionController::Base
def response_with=(content)
@content = content
@@ -51,21 +62,9 @@ class AssertSelectTest < Test::Unit::TestCase
end
end
- class AssertSelectMailer < ActionMailer::Base
- def test(html)
- recipients "test <test@test.host>"
- from "test@test.host"
- subject "Test e-mail"
- part :content_type=>"text/html", :body=>html
- end
- end
-
- AssertionFailedError = Test::Unit::AssertionFailedError
+ tests AssertSelectController
def setup
- @controller = AssertSelectController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
@@ -76,7 +75,7 @@ class AssertSelectTest < Test::Unit::TestCase
end
def assert_failure(message, &block)
- e = assert_raises(AssertionFailedError, &block)
+ e = assert_raises(Assertion, &block)
assert_match(message, e.message) if Regexp === message
assert_equal(message, e.message) if String === message
end
@@ -94,43 +93,43 @@ class AssertSelectTest < Test::Unit::TestCase
def test_equality_true_false
render_html %Q{<div id="1"></div><div id="2"></div>}
- assert_nothing_raised { assert_select "div" }
- assert_raises(AssertionFailedError) { assert_select "p" }
- assert_nothing_raised { assert_select "div", true }
- assert_raises(AssertionFailedError) { assert_select "p", true }
- assert_raises(AssertionFailedError) { assert_select "div", false }
- assert_nothing_raised { assert_select "p", false }
+ assert_nothing_raised { assert_select "div" }
+ assert_raises(Assertion) { assert_select "p" }
+ assert_nothing_raised { assert_select "div", true }
+ assert_raises(Assertion) { assert_select "p", true }
+ assert_raises(Assertion) { assert_select "div", false }
+ assert_nothing_raised { assert_select "p", false }
end
def test_equality_string_and_regexp
render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
- assert_nothing_raised { assert_select "div", "foo" }
- assert_raises(AssertionFailedError) { assert_select "div", "bar" }
- assert_nothing_raised { assert_select "div", :text=>"foo" }
- assert_raises(AssertionFailedError) { assert_select "div", :text=>"bar" }
- assert_nothing_raised { assert_select "div", /(foo|bar)/ }
- assert_raises(AssertionFailedError) { assert_select "div", /foobar/ }
- assert_nothing_raised { assert_select "div", :text=>/(foo|bar)/ }
- assert_raises(AssertionFailedError) { assert_select "div", :text=>/foobar/ }
- assert_raises(AssertionFailedError) { assert_select "p", :text=>/foobar/ }
+ assert_nothing_raised { assert_select "div", "foo" }
+ assert_raises(Assertion) { assert_select "div", "bar" }
+ assert_nothing_raised { assert_select "div", :text=>"foo" }
+ assert_raises(Assertion) { assert_select "div", :text=>"bar" }
+ assert_nothing_raised { assert_select "div", /(foo|bar)/ }
+ assert_raises(Assertion) { assert_select "div", /foobar/ }
+ assert_nothing_raised { assert_select "div", :text=>/(foo|bar)/ }
+ assert_raises(Assertion) { assert_select "div", :text=>/foobar/ }
+ assert_raises(Assertion) { assert_select "p", :text=>/foobar/ }
end
def test_equality_of_html
render_html %Q{<p>\n<em>"This is <strong>not</strong> a big problem,"</em> he said.\n</p>}
text = "\"This is not a big problem,\" he said."
html = "<em>\"This is <strong>not</strong> a big problem,\"</em> he said."
- assert_nothing_raised { assert_select "p", text }
- assert_raises(AssertionFailedError) { assert_select "p", html }
- assert_nothing_raised { assert_select "p", :html=>html }
- assert_raises(AssertionFailedError) { assert_select "p", :html=>text }
+ assert_nothing_raised { assert_select "p", text }
+ assert_raises(Assertion) { assert_select "p", html }
+ assert_nothing_raised { assert_select "p", :html=>html }
+ assert_raises(Assertion) { assert_select "p", :html=>text }
# No stripping for pre.
render_html %Q{<pre>\n<em>"This is <strong>not</strong> a big problem,"</em> he said.\n</pre>}
text = "\n\"This is not a big problem,\" he said.\n"
html = "\n<em>\"This is <strong>not</strong> a big problem,\"</em> he said.\n"
- assert_nothing_raised { assert_select "pre", text }
- assert_raises(AssertionFailedError) { assert_select "pre", html }
- assert_nothing_raised { assert_select "pre", :html=>html }
- assert_raises(AssertionFailedError) { assert_select "pre", :html=>text }
+ assert_nothing_raised { assert_select "pre", text }
+ assert_raises(Assertion) { assert_select "pre", html }
+ assert_nothing_raised { assert_select "pre", :html=>html }
+ assert_raises(Assertion) { assert_select "pre", :html=>text }
end
def test_counts
@@ -206,16 +205,16 @@ class AssertSelectTest < Test::Unit::TestCase
def test_assert_select_text_match
render_html %Q{<div id="1"><span>foo</span></div><div id="2"><span>bar</span></div>}
assert_select "div" do
- assert_nothing_raised { assert_select "div", "foo" }
- assert_nothing_raised { assert_select "div", "bar" }
- assert_nothing_raised { assert_select "div", /\w*/ }
- assert_nothing_raised { assert_select "div", /\w*/, :count=>2 }
- assert_raises(AssertionFailedError) { assert_select "div", :text=>"foo", :count=>2 }
- assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
- assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
- assert_nothing_raised { assert_select "div", :html=>/\w*/ }
- assert_nothing_raised { assert_select "div", :html=>/\w*/, :count=>2 }
- assert_raises(AssertionFailedError) { assert_select "div", :html=>"<span>foo</span>", :count=>2 }
+ assert_nothing_raised { assert_select "div", "foo" }
+ assert_nothing_raised { assert_select "div", "bar" }
+ assert_nothing_raised { assert_select "div", /\w*/ }
+ assert_nothing_raised { assert_select "div", /\w*/, :count=>2 }
+ assert_raises(Assertion) { assert_select "div", :text=>"foo", :count=>2 }
+ assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
+ assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
+ assert_nothing_raised { assert_select "div", :html=>/\w*/ }
+ assert_nothing_raised { assert_select "div", :html=>/\w*/, :count=>2 }
+ assert_raises(Assertion) { assert_select "div", :html=>"<span>foo</span>", :count=>2 }
end
end
@@ -323,7 +322,7 @@ class AssertSelectTest < Test::Unit::TestCase
# Test that we fail if there is nothing to pick.
def test_assert_select_rjs_fails_if_nothing_to_pick
render_rjs { }
- assert_raises(AssertionFailedError) { assert_select_rjs }
+ assert_raises(Assertion) { assert_select_rjs }
end
def test_assert_select_rjs_with_unicode
@@ -338,10 +337,10 @@ class AssertSelectTest < Test::Unit::TestCase
if str.respond_to?(:force_encoding)
str.force_encoding(Encoding::UTF_8)
assert_select str, /\343\203\201..\343\203\210/u
- assert_raises(AssertionFailedError) { assert_select str, /\343\203\201.\343\203\210/u }
+ assert_raises(Assertion) { assert_select str, /\343\203\201.\343\203\210/u }
else
assert_select str, Regexp.new("\343\203\201..\343\203\210",0,'U')
- assert_raises(AssertionFailedError) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
+ assert_raises(Assertion) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
end
end
end
@@ -365,7 +364,7 @@ class AssertSelectTest < Test::Unit::TestCase
assert_select "div", 1
assert_select "#3"
end
- assert_raises(AssertionFailedError) { assert_select_rjs "test4" }
+ assert_raises(Assertion) { assert_select_rjs "test4" }
end
def test_assert_select_rjs_for_replace
@@ -383,7 +382,7 @@ class AssertSelectTest < Test::Unit::TestCase
assert_select "div", 1
assert_select "#1"
end
- assert_raises(AssertionFailedError) { assert_select_rjs :replace, "test2" }
+ assert_raises(Assertion) { assert_select_rjs :replace, "test2" }
# Replace HTML.
assert_select_rjs :replace_html do
assert_select "div", 1
@@ -393,7 +392,7 @@ class AssertSelectTest < Test::Unit::TestCase
assert_select "div", 1
assert_select "#2"
end
- assert_raises(AssertionFailedError) { assert_select_rjs :replace_html, "test1" }
+ assert_raises(Assertion) { assert_select_rjs :replace_html, "test1" }
end
def test_assert_select_rjs_for_chained_replace
@@ -411,7 +410,7 @@ class AssertSelectTest < Test::Unit::TestCase
assert_select "div", 1
assert_select "#1"
end
- assert_raises(AssertionFailedError) { assert_select_rjs :chained_replace, "test2" }
+ assert_raises(Assertion) { assert_select_rjs :chained_replace, "test2" }
# Replace HTML.
assert_select_rjs :chained_replace_html do
assert_select "div", 1
@@ -421,7 +420,7 @@ class AssertSelectTest < Test::Unit::TestCase
assert_select "div", 1
assert_select "#2"
end
- assert_raises(AssertionFailedError) { assert_select_rjs :replace_html, "test1" }
+ assert_raises(Assertion) { assert_select_rjs :replace_html, "test1" }
end
# Simple remove
@@ -440,8 +439,8 @@ class AssertSelectTest < Test::Unit::TestCase
assert_select_rjs :remove, "test1"
- rescue Test::Unit::AssertionFailedError
- assert_equal "No RJS statement that removes 'test1' was rendered.", $!.message
+ rescue Assertion
+ assert_equal "No RJS statement that removes 'test1' was rendered.", $!.message
end
def test_assert_select_rjs_for_remove_ignores_block
@@ -472,8 +471,8 @@ class AssertSelectTest < Test::Unit::TestCase
assert_select_rjs :show, "test1"
- rescue Test::Unit::AssertionFailedError
- assert_equal "No RJS statement that shows 'test1' was rendered.", $!.message
+ rescue Assertion
+ assert_equal "No RJS statement that shows 'test1' was rendered.", $!.message
end
def test_assert_select_rjs_for_show_ignores_block
@@ -504,8 +503,8 @@ class AssertSelectTest < Test::Unit::TestCase
assert_select_rjs :hide, "test1"
- rescue Test::Unit::AssertionFailedError
- assert_equal "No RJS statement that hides 'test1' was rendered.", $!.message
+ rescue Assertion
+ assert_equal "No RJS statement that hides 'test1' was rendered.", $!.message
end
def test_assert_select_rjs_for_hide_ignores_block
@@ -536,8 +535,8 @@ class AssertSelectTest < Test::Unit::TestCase
assert_select_rjs :toggle, "test1"
- rescue Test::Unit::AssertionFailedError
- assert_equal "No RJS statement that toggles 'test1' was rendered.", $!.message
+ rescue Assertion
+ assert_equal "No RJS statement that toggles 'test1' was rendered.", $!.message
end
def test_assert_select_rjs_for_toggle_ignores_block
@@ -567,7 +566,7 @@ class AssertSelectTest < Test::Unit::TestCase
assert_select "div", 1
assert_select "#3"
end
- assert_raises(AssertionFailedError) { assert_select_rjs :insert_html, "test1" }
+ assert_raises(Assertion) { assert_select_rjs :insert_html, "test1" }
end
# Positioned insert.
@@ -693,7 +692,7 @@ EOF
#
def test_assert_select_email
- assert_raises(AssertionFailedError) { assert_select_email {} }
+ assert_raises(Assertion) { assert_select_email {} }
AssertSelectMailer.deliver_test "<div><p>foo</p><p>bar</p></div>"
assert_select_email do
assert_select "div:root" do
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb
index 738c016c6e..18d185b264 100644
--- a/actionpack/test/controller/base_test.rb
+++ b/actionpack/test/controller/base_test.rb
@@ -105,7 +105,7 @@ class ControllerInstanceTests < Test::Unit::TestCase
end
-class PerformActionTest < Test::Unit::TestCase
+class PerformActionTest < ActionController::TestCase
class MockLogger
attr_reader :logged
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index b6cdd116e5..eb106c1eb4 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -42,7 +42,7 @@ class PageCachingTestController < ActionController::Base
end
end
-class PageCachingTest < Test::Unit::TestCase
+class PageCachingTest < ActionController::TestCase
def setup
ActionController::Base.perform_caching = true
@@ -222,7 +222,7 @@ class ActionCachingMockController
end
end
-class ActionCacheTest < Test::Unit::TestCase
+class ActionCacheTest < ActionController::TestCase
def setup
reset!
FileUtils.mkdir_p(FILE_STORE_PATH)
@@ -291,11 +291,13 @@ class ActionCacheTest < Test::Unit::TestCase
ActionController::Base.use_accept_header = old_use_accept_header
end
- def test_action_cache_with_store_options
- MockTime.expects(:now).returns(12345).once
- @controller.expects(:read_fragment).with('hostname.com/action_caching_test', :expires_in => 1.hour).once
- @controller.expects(:write_fragment).with('hostname.com/action_caching_test', '12345.0', :expires_in => 1.hour).once
- get :index
+ uses_mocha 'test action cache' do
+ def test_action_cache_with_store_options
+ MockTime.expects(:now).returns(12345).once
+ @controller.expects(:read_fragment).with('hostname.com/action_caching_test', :expires_in => 1.hour).once
+ @controller.expects(:write_fragment).with('hostname.com/action_caching_test', '12345.0', :expires_in => 1.hour).once
+ get :index
+ end
end
def test_action_cache_with_custom_cache_path
@@ -469,7 +471,7 @@ class FragmentCachingTestController < ActionController::Base
def some_action; end;
end
-class FragmentCachingTest < Test::Unit::TestCase
+class FragmentCachingTest < ActionController::TestCase
def setup
ActionController::Base.perform_caching = true
@store = ActiveSupport::Cache::MemoryStore.new
@@ -601,7 +603,7 @@ class FunctionalCachingController < ActionController::Base
end
end
-class FunctionalFragmentCachingTest < Test::Unit::TestCase
+class FunctionalFragmentCachingTest < ActionController::TestCase
def setup
ActionController::Base.perform_caching = true
@store = ActiveSupport::Cache::MemoryStore.new
diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb
index 813171857a..87fbf1a4cd 100644
--- a/actionpack/test/controller/cgi_test.rb
+++ b/actionpack/test/controller/cgi_test.rb
@@ -48,7 +48,8 @@ class BaseCgiTest < Test::Unit::TestCase
# some developers have grown accustomed to using comma in cookie values.
@alt_cookie_fmt_request_hash = {"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"}
@cgi = CGI.new
- @cgi.stubs(:env_table).returns(@request_hash)
+ class << @cgi; attr_accessor :env_table end
+ @cgi.env_table = @request_hash
@request = ActionController::CgiRequest.new(@cgi)
end
diff --git a/actionpack/test/controller/components_test.rb b/actionpack/test/controller/components_test.rb
index 4d36fc411d..e7b17aa34e 100644
--- a/actionpack/test/controller/components_test.rb
+++ b/actionpack/test/controller/components_test.rb
@@ -69,12 +69,8 @@ class CalleeController < ActionController::Base
def rescue_action(e) raise end
end
-class ComponentsTest < Test::Unit::TestCase
- def setup
- @controller = CallerController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- end
+class ComponentsTest < ActionController::TestCase
+ tests CallerController
def test_calling_from_controller
assert_deprecated do
diff --git a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
index 86555a77df..dd69a63020 100644
--- a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
+++ b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class DeprecatedBaseMethodsTest < Test::Unit::TestCase
+class DeprecatedBaseMethodsTest < ActionController::TestCase
class Target < ActionController::Base
def home_url(greeting)
"http://example.com/#{greeting}"
@@ -13,11 +13,7 @@ class DeprecatedBaseMethodsTest < Test::Unit::TestCase
def rescue_action(e) raise e end
end
- def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- @controller = Target.new
- end
+ tests Target
def test_log_error_silences_deprecation_warnings
get :raises_name_error
@@ -25,10 +21,12 @@ class DeprecatedBaseMethodsTest < Test::Unit::TestCase
assert_not_deprecated { @controller.send :log_error, e }
end
- def test_assertion_failed_error_silences_deprecation_warnings
- get :raises_name_error
- rescue => e
- error = Test::Unit::Error.new('testing ur doodz', e)
- assert_not_deprecated { error.message }
+ if defined? Test::Unit::Error
+ def test_assertion_failed_error_silences_deprecation_warnings
+ get :raises_name_error
+ rescue => e
+ error = Test::Unit::Error.new('testing ur doodz', e)
+ assert_not_deprecated { error.message }
+ end
end
end
diff --git a/actionpack/test/controller/html-scanner/sanitizer_test.rb b/actionpack/test/controller/html-scanner/sanitizer_test.rb
index bae0f5c9fd..e85a5c7abf 100644
--- a/actionpack/test/controller/html-scanner/sanitizer_test.rb
+++ b/actionpack/test/controller/html-scanner/sanitizer_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class SanitizerTest < Test::Unit::TestCase
+class SanitizerTest < ActionController::TestCase
def setup
@sanitizer = nil # used by assert_sanitizer
end
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index 1120fdbff5..61c20f8299 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -34,11 +34,8 @@ end
ActionView::Template::register_template_handler :mab,
lambda { |template| template.source.inspect }
-class LayoutAutoDiscoveryTest < Test::Unit::TestCase
+class LayoutAutoDiscoveryTest < ActionController::TestCase
def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
@request.host = "www.nextangle.com"
end
@@ -98,12 +95,7 @@ class RendersNoLayoutController < LayoutTest
end
end
-class LayoutSetInResponseTest < Test::Unit::TestCase
- def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- end
-
+class LayoutSetInResponseTest < ActionController::TestCase
def test_layout_set_when_using_default_layout
@controller = DefaultLayoutController.new
get :hello
@@ -150,12 +142,7 @@ class SetsNonExistentLayoutFile < LayoutTest
layout "nofile.rhtml"
end
-class LayoutExceptionRaised < Test::Unit::TestCase
- def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- end
-
+class LayoutExceptionRaised < ActionController::TestCase
def test_exception_raised_when_layout_file_not_found
@controller = SetsNonExistentLayoutFile.new
get :hello
@@ -170,12 +157,7 @@ class LayoutStatusIsRendered < LayoutTest
end
end
-class LayoutStatusIsRenderedTest < Test::Unit::TestCase
- def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- end
-
+class LayoutStatusIsRenderedTest < ActionController::TestCase
def test_layout_status_is_rendered
@controller = LayoutStatusIsRendered.new
get :hello
@@ -187,12 +169,7 @@ class LayoutSymlinkedTest < LayoutTest
layout "symlinked/symlinked_layout"
end
-class LayoutSymlinkedIsRenderedTest < Test::Unit::TestCase
- def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- end
-
+class LayoutSymlinkedIsRenderedTest < ActionController::TestCase
def test_symlinked_layout_is_rendered
@controller = LayoutSymlinkedTest.new
get :hello
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 0d508eb8df..dc59180a68 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -162,13 +162,11 @@ class RespondToController < ActionController::Base
end
end
-class MimeControllerTest < Test::Unit::TestCase
+class MimeControllerTest < ActionController::TestCase
+ tests RespondToController
+
def setup
ActionController::Base.use_accept_header = true
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
- @controller = RespondToController.new
@request.host = "www.example.com"
end
@@ -509,12 +507,10 @@ class SuperPostController < PostController
end
end
-class MimeControllerLayoutsTest < Test::Unit::TestCase
- def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
+class MimeControllerLayoutsTest < ActionController::TestCase
+ tests PostController
- @controller = PostController.new
+ def setup
@request.host = "www.example.com"
end
diff --git a/actionpack/test/controller/polymorphic_routes_test.rb b/actionpack/test/controller/polymorphic_routes_test.rb
index 620f2b3ab5..efa3c44bc0 100644
--- a/actionpack/test/controller/polymorphic_routes_test.rb
+++ b/actionpack/test/controller/polymorphic_routes_test.rb
@@ -22,8 +22,7 @@ end
class Response::Nested < Response; end
uses_mocha 'polymorphic URL helpers' do
- class PolymorphicRoutesTest < Test::Unit::TestCase
-
+ class PolymorphicRoutesTest < ActiveSupport::TestCase
include ActionController::PolymorphicRoutes
def setup
diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb
index c55307d645..27cedc91d2 100644
--- a/actionpack/test/controller/redirect_test.rb
+++ b/actionpack/test/controller/redirect_test.rb
@@ -103,12 +103,8 @@ class RedirectController < ActionController::Base
end
end
-class RedirectTest < Test::Unit::TestCase
- def setup
- @controller = RedirectController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- end
+class RedirectTest < ActionController::TestCase
+ tests RedirectController
def test_simple_redirect
get :simple_redirect
@@ -256,12 +252,8 @@ module ModuleTest
end
end
- class ModuleRedirectTest < Test::Unit::TestCase
- def setup
- @controller = ModuleRedirectController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- end
+ class ModuleRedirectTest < ActionController::TestCase
+ tests ModuleRedirectController
def test_simple_redirect
get :simple_redirect
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index df9376727f..6a03466db1 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -641,12 +641,10 @@ class TestController < ActionController::Base
end
end
-class RenderTest < Test::Unit::TestCase
- def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- @controller = TestController.new
+class RenderTest < ActionController::TestCase
+ tests TestController
+ def setup
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
# a more accurate simulation of what happens in "real life".
@controller.logger = Logger.new(nil)
@@ -1333,12 +1331,10 @@ class RenderTest < Test::Unit::TestCase
end
end
-class EtagRenderTest < Test::Unit::TestCase
- def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- @controller = TestController.new
+class EtagRenderTest < ActionController::TestCase
+ tests TestController
+ def setup
@request.host = "www.nextangle.com"
@expected_bang_etag = etag_for(expand_key([:foo, 123]))
end
@@ -1430,12 +1426,10 @@ class EtagRenderTest < Test::Unit::TestCase
end
end
-class LastModifiedRenderTest < Test::Unit::TestCase
- def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- @controller = TestController.new
+class LastModifiedRenderTest < ActionController::TestCase
+ tests TestController
+ def setup
@request.host = "www.nextangle.com"
@last_modified = Time.now.utc.beginning_of_day.httpdate
end
@@ -1487,12 +1481,10 @@ class LastModifiedRenderTest < Test::Unit::TestCase
end
end
-class RenderingLoggingTest < Test::Unit::TestCase
- def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- @controller = TestController.new
+class RenderingLoggingTest < ActionController::TestCase
+ tests TestController
+ def setup
@request.host = "www.nextangle.com"
end
diff --git a/actionpack/test/controller/request_forgery_protection_test.rb b/actionpack/test/controller/request_forgery_protection_test.rb
index 5669b8f358..00c6bc0ab0 100644
--- a/actionpack/test/controller/request_forgery_protection_test.rb
+++ b/actionpack/test/controller/request_forgery_protection_test.rb
@@ -230,7 +230,7 @@ end
# OK let's get our test on
-class RequestForgeryProtectionControllerTest < Test::Unit::TestCase
+class RequestForgeryProtectionControllerTest < ActionController::TestCase
include RequestForgeryProtectionTests
def setup
@controller = RequestForgeryProtectionController.new
@@ -245,7 +245,7 @@ class RequestForgeryProtectionControllerTest < Test::Unit::TestCase
end
end
-class RequestForgeryProtectionWithoutSecretControllerTest < Test::Unit::TestCase
+class RequestForgeryProtectionWithoutSecretControllerTest < ActionController::TestCase
def setup
@controller = RequestForgeryProtectionWithoutSecretController.new
@request = ActionController::TestRequest.new
@@ -264,7 +264,7 @@ class RequestForgeryProtectionWithoutSecretControllerTest < Test::Unit::TestCase
# end
end
-class CsrfCookieMonsterControllerTest < Test::Unit::TestCase
+class CsrfCookieMonsterControllerTest < ActionController::TestCase
include RequestForgeryProtectionTests
def setup
@controller = CsrfCookieMonsterController.new
@@ -280,7 +280,7 @@ class CsrfCookieMonsterControllerTest < Test::Unit::TestCase
end
end
-class FreeCookieControllerTest < Test::Unit::TestCase
+class FreeCookieControllerTest < ActionController::TestCase
def setup
@controller = FreeCookieController.new
@request = ActionController::TestRequest.new
@@ -305,7 +305,7 @@ class FreeCookieControllerTest < Test::Unit::TestCase
end
end
-class SessionOffControllerTest < Test::Unit::TestCase
+class SessionOffControllerTest < ActionController::TestCase
def setup
@controller = SessionOffController.new
@request = ActionController::TestRequest.new
diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb
index e79a0ea76b..7e264289e6 100644
--- a/actionpack/test/controller/request_test.rb
+++ b/actionpack/test/controller/request_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'action_controller/integration'
-class RequestTest < Test::Unit::TestCase
+class RequestTest < ActiveSupport::TestCase
def setup
ActionController::Base.relative_url_root = nil
@request = ActionController::TestRequest.new
@@ -400,7 +400,7 @@ class RequestTest < Test::Unit::TestCase
end
end
-class UrlEncodedRequestParameterParsingTest < Test::Unit::TestCase
+class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase
def setup
@query_string = "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1"
@query_string_with_empty = "action=create_customer&full_name="
@@ -704,20 +704,20 @@ class UrlEncodedRequestParameterParsingTest < Test::Unit::TestCase
end
end
-class MultipartRequestParameterParsingTest < Test::Unit::TestCase
+class MultipartRequestParameterParsingTest < ActiveSupport::TestCase
FIXTURE_PATH = File.dirname(__FILE__) + '/../fixtures/multipart'
def test_single_parameter
- params = process('single_parameter')
+ params = parse_multipart('single_parameter')
assert_equal({ 'foo' => 'bar' }, params)
end
def test_bracketed_param
- assert_equal({ 'foo' => { 'baz' => 'bar'}}, process('bracketed_param'))
+ assert_equal({ 'foo' => { 'baz' => 'bar'}}, parse_multipart('bracketed_param'))
end
def test_text_file
- params = process('text_file')
+ params = parse_multipart('text_file')
assert_equal %w(file foo), params.keys.sort
assert_equal 'bar', params['foo']
@@ -729,17 +729,13 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase
end
def test_boundary_problem_file
- params = process('boundary_problem_file')
+ params = parse_multipart('boundary_problem_file')
assert_equal %w(file foo), params.keys.sort
file = params['file']
foo = params['foo']
- if RUBY_VERSION > '1.9'
- assert_kind_of File, file
- else
- assert_kind_of Tempfile, file
- end
+ assert_kind_of Tempfile, file
assert_equal 'file.txt', file.original_filename
assert_equal "text/plain", file.content_type
@@ -748,16 +744,14 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase
end
def test_large_text_file
- params = process('large_text_file')
+ params = parse_multipart('large_text_file')
assert_equal %w(file foo), params.keys.sort
assert_equal 'bar', params['foo']
file = params['file']
- if RUBY_VERSION > '1.9'
- assert_kind_of File, file
- else
- assert_kind_of Tempfile, file
- end
+
+ assert_kind_of Tempfile, file
+
assert_equal 'file.txt', file.original_filename
assert_equal "text/plain", file.content_type
assert ('a' * 20480) == file.read
@@ -774,7 +768,7 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase
end
def test_binary_file
- params = process('binary_file')
+ params = parse_multipart('binary_file')
assert_equal %w(file flowers foo), params.keys.sort
assert_equal 'bar', params['foo']
@@ -793,7 +787,7 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase
end
def test_mixed_files
- params = process('mixed_files')
+ params = parse_multipart('mixed_files')
assert_equal %w(files foo), params.keys.sort
assert_equal 'bar', params['foo']
@@ -805,7 +799,7 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase
end
private
- def process(name)
+ def parse_multipart(name)
File.open(File.join(FIXTURE_PATH, name), 'rb') do |file|
params = ActionController::AbstractRequest.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {})
assert_equal 0, file.pos # file was rewound after reading
@@ -814,7 +808,7 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase
end
end
-class XmlParamsParsingTest < Test::Unit::TestCase
+class XmlParamsParsingTest < ActiveSupport::TestCase
def test_hash_params
person = parse_body("<person><name>David</name></person>")[:person]
assert_kind_of Hash, person
@@ -868,7 +862,7 @@ class LegacyXmlParamsParsingTest < XmlParamsParsingTest
end
end
-class JsonParamsParsingTest < Test::Unit::TestCase
+class JsonParamsParsingTest < ActiveSupport::TestCase
def test_hash_params_for_application_json
person = parse_body({:person => {:name => "David"}}.to_json,'application/json')[:person]
assert_kind_of Hash, person
diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb
index 04f7a0a528..d5e8a3ae4a 100644
--- a/actionpack/test/controller/resources_test.rb
+++ b/actionpack/test/controller/resources_test.rb
@@ -29,7 +29,7 @@ module Backoffice
end
end
-class ResourcesTest < Test::Unit::TestCase
+class ResourcesTest < ActionController::TestCase
# The assertions in these tests are incompatible with the hash method
# optimisation. This could indicate user level problems
def setup
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index a23428804a..ee7b8ade8c 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'controller/fake_controllers'
-class TestTest < Test::Unit::TestCase
+class TestTest < ActionController::TestCase
class TestController < ActionController::Base
def no_op
render :text => 'dummy'
@@ -24,7 +24,7 @@ class TestTest < Test::Unit::TestCase
end
def render_raw_post
- raise Test::Unit::AssertionFailedError, "#raw_post is blank" if request.raw_post.blank?
+ raise ActiveSupport::TestCase::Assertion, "#raw_post is blank" if request.raw_post.blank?
render :text => request.raw_post
end
@@ -580,7 +580,7 @@ XML
assert_equal @response.redirect_url, redirect_to_url
# Must be a :redirect response.
- assert_raise(Test::Unit::AssertionFailedError) do
+ assert_raise(ActiveSupport::TestCase::Assertion) do
assert_redirected_to 'created resource'
end
end
@@ -602,21 +602,21 @@ XML
end
end
-class CleanBacktraceTest < Test::Unit::TestCase
+class CleanBacktraceTest < ActionController::TestCase
def test_should_reraise_the_same_object
- exception = Test::Unit::AssertionFailedError.new('message')
+ exception = ActiveSupport::TestCase::Assertion.new('message')
clean_backtrace { raise exception }
- rescue => caught
+ rescue Exception => caught
assert_equal exception.object_id, caught.object_id
assert_equal exception.message, caught.message
end
def test_should_clean_assertion_lines_from_backtrace
path = File.expand_path("#{File.dirname(__FILE__)}/../../lib/action_controller")
- exception = Test::Unit::AssertionFailedError.new('message')
+ exception = ActiveSupport::TestCase::Assertion.new('message')
exception.set_backtrace ["#{path}/abc", "#{path}/assertions/def"]
clean_backtrace { raise exception }
- rescue => caught
+ rescue Exception => caught
assert_equal ["#{path}/abc"], caught.backtrace
end
@@ -629,21 +629,17 @@ class CleanBacktraceTest < Test::Unit::TestCase
end
end
-class InferringClassNameTest < Test::Unit::TestCase
+class InferringClassNameTest < ActionController::TestCase
def test_determine_controller_class
assert_equal ContentController, determine_class("ContentControllerTest")
end
def test_determine_controller_class_with_nonsense_name
- assert_raises ActionController::NonInferrableControllerError do
- determine_class("HelloGoodBye")
- end
+ assert_nil determine_class("HelloGoodBye")
end
def test_determine_controller_class_with_sensible_name_where_no_controller_exists
- assert_raises ActionController::NonInferrableControllerError do
- determine_class("NoControllerWithThisNameTest")
- end
+ assert_nil determine_class("NoControllerWithThisNameTest")
end
private
diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb
index 64e9a085ca..8bc343e2ea 100644
--- a/actionpack/test/controller/url_rewriter_test.rb
+++ b/actionpack/test/controller/url_rewriter_test.rb
@@ -2,7 +2,7 @@ require 'abstract_unit'
ActionController::UrlRewriter
-class UrlRewriterTests < Test::Unit::TestCase
+class UrlRewriterTests < ActionController::TestCase
def setup
@request = ActionController::TestRequest.new
@params = {}
@@ -85,8 +85,7 @@ class UrlRewriterTests < Test::Unit::TestCase
end
end
-class UrlWriterTests < Test::Unit::TestCase
-
+class UrlWriterTests < ActionController::TestCase
class W
include ActionController::UrlWriter
end
diff --git a/actionpack/test/controller/verification_test.rb b/actionpack/test/controller/verification_test.rb
index b289443129..418a81baa8 100644
--- a/actionpack/test/controller/verification_test.rb
+++ b/actionpack/test/controller/verification_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class VerificationTest < Test::Unit::TestCase
+class VerificationTest < ActionController::TestCase
class TestController < ActionController::Base
verify :only => :guarded_one, :params => "one",
:add_flash => { :error => 'unguarded' },
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb
index b859a92cbd..04e14d8eac 100644
--- a/actionpack/test/controller/view_paths_test.rb
+++ b/actionpack/test/controller/view_paths_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class ViewLoadPathsTest < Test::Unit::TestCase
+class ViewLoadPathsTest < ActionController::TestCase
class TestController < ActionController::Base
def self.controller_path() "test" end
def rescue_action(e) raise end
diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb
index 06af8d1d6a..8a00a397ca 100644
--- a/actionpack/test/template/atom_feed_helper_test.rb
+++ b/actionpack/test/template/atom_feed_helper_test.rb
@@ -166,12 +166,10 @@ class ScrollsController < ActionController::Base
end
end
-class AtomFeedTest < Test::Unit::TestCase
- def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- @controller = ScrollsController.new
+class AtomFeedTest < ActionController::TestCase
+ tests ScrollsController
+ def setup
@request.host = "www.nextangle.com"
end