vendor/rails/actionpack/test/controller/test_test.rb in radiant-0.7.2 vs vendor/rails/actionpack/test/controller/test_test.rb in radiant-0.8.0
- old
+ new
@@ -1,9 +1,9 @@
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'
end
@@ -21,12 +21,17 @@
session['string'] = 'A wonder'
session[:symbol] = 'it works'
render :text => 'Success'
end
+ def reset_the_session
+ reset_session
+ render :text => 'ignore me'
+ 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
def render_body
render :text => request.body.read
@@ -62,11 +67,11 @@
</div>
</body>
</html>
HTML
end
-
+
def test_xml_output
response.content_type = "application/xml"
render :text => <<XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
@@ -115,12 +120,12 @@
def setup
@controller = TestController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
- ActionController::Routing::Routes.reload
ActionController::Routing.use_controllers! %w(content admin/user test_test/test)
+ ActionController::Routing::Routes.load_routes!
end
def teardown
ActionController::Routing::Routes.reload
end
@@ -169,10 +174,28 @@
assert_equal 'value1', session[:string]
assert_equal 'value2', session['symbol']
assert_equal 'value2', session[:symbol]
end
+ def test_session_is_cleared_from_controller_after_reset_session
+ process :set_session
+ process :reset_the_session
+ assert_equal Hash.new, @controller.session.to_hash
+ end
+
+ def test_session_is_cleared_from_response_after_reset_session
+ process :set_session
+ process :reset_the_session
+ assert_equal Hash.new, @response.session.to_hash
+ end
+
+ def test_session_is_cleared_from_request_after_reset_session
+ process :set_session
+ process :reset_the_session
+ assert_equal Hash.new, @request.session.to_hash
+ end
+
def test_process_with_request_uri_with_no_params
process :test_uri
assert_equal "/test_test/test/test_uri", @response.body
end
@@ -364,11 +387,11 @@
:children => { :count => 1,
:only => { :tag => "a",
:children => { :count => 1,
:only => { :tag => "img" } } } }
end
-
+
def test_should_not_impose_childless_html_tags_in_xml
process :test_xml_output
begin
$stderr = StringIO.new
@@ -410,11 +433,11 @@
assert_routing 'content', :controller => 'content', :action => 'index'
end
def test_assert_routing_with_method
with_routing do |set|
- set.draw { |map| map.resources(:content) }
+ set.draw { |map| map.resources(:content) }
assert_routing({ :method => 'post', :path => 'content' }, { :controller => 'content', :action => 'create' })
end
end
def test_assert_routing_in_module
@@ -484,11 +507,11 @@
def test_header_properly_reset_after_remote_http_request
xhr :get, :test_params
assert_nil @request.env['HTTP_X_REQUESTED_WITH']
end
- def test_header_properly_reset_after_get_request
+ def test_header_properly_reset_after_get_request
get :test_params
@request.recycle!
assert_nil @request.instance_variable_get("@request_method")
end
@@ -535,31 +558,31 @@
new_content_type = "new content_type"
file.content_type = new_content_type
assert_equal new_content_type, file.content_type
end
-
+
def test_test_uploaded_file_with_binary
filename = 'mona_lisa.jpg'
path = "#{FILES_DIR}/#{filename}"
content_type = 'image/png'
-
+
binary_uploaded_file = ActionController::TestUploadedFile.new(path, content_type, :binary)
assert_equal File.open(path, READ_BINARY).read, binary_uploaded_file.read
-
+
plain_uploaded_file = ActionController::TestUploadedFile.new(path, content_type)
assert_equal File.open(path, READ_PLAIN).read, plain_uploaded_file.read
end
def test_fixture_file_upload_with_binary
filename = 'mona_lisa.jpg'
path = "#{FILES_DIR}/#{filename}"
content_type = 'image/jpg'
-
+
binary_file_upload = fixture_file_upload(path, content_type, :binary)
assert_equal File.open(path, READ_BINARY).read, binary_file_upload.read
-
+
plain_file_upload = fixture_file_upload(path, content_type)
assert_equal File.open(path, READ_PLAIN).read, plain_file_upload.read
end
def test_fixture_file_upload
@@ -569,51 +592,29 @@
def test_test_uploaded_file_exception_when_file_doesnt_exist
assert_raise(RuntimeError) { ActionController::TestUploadedFile.new('non_existent_file') }
end
- def test_assert_follow_redirect_to_same_controller
- with_foo_routing do |set|
- get :redirect_to_same_controller
- assert_response :redirect
- assert_redirected_to :controller => 'test_test/test', :action => 'test_uri', :id => 5
- assert_deprecated 'follow_redirect' do
- assert_nothing_raised { follow_redirect }
- end
- end
- end
-
- def test_assert_follow_redirect_to_different_controller
- with_foo_routing do |set|
- get :redirect_to_different_controller
- assert_response :redirect
- assert_redirected_to :controller => 'fail', :id => 5
- assert_raise(RuntimeError) do
- assert_deprecated { follow_redirect }
- end
- end
- end
-
def test_redirect_url_only_cares_about_location_header
get :create
assert_response :created
# Redirect url doesn't care that it wasn't a :redirect response.
assert_equal 'created resource', @response.redirect_url
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
def test_binary_content_works_with_send_file
get :test_send_file
assert_nothing_raised(NoMethodError) { @response.binary_content }
end
-
+
protected
def with_foo_routing
with_routing do |set|
set.draw do |map|
map.generate_url 'foo', :controller => 'test'
@@ -622,26 +623,25 @@
yield set
end
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
def test_should_only_clean_assertion_failure_errors
clean_backtrace do
@@ -650,25 +650,21 @@
rescue => caught
assert !caught.backtrace.empty?
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
def determine_class(name)
ActionController::TestCase.determine_default_controller_class(name)
@@ -683,13 +679,14 @@
end
end
class NamedRoutesControllerTest < ActionController::TestCase
tests ContentController
-
+
def test_should_be_able_to_use_named_routes_before_a_request_is_done
with_routing do |set|
set.draw { |map| map.resources :contents }
assert_equal 'http://test.host/contents/new', new_content_url
+ assert_equal 'http://test.host/contents/1', content_url(:id => 1)
end
end
end