Skip to content

Commit

Permalink
Updated unit test style
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1355 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed May 22, 2005
1 parent c41f0cc commit 79d9794
Showing 1 changed file with 43 additions and 48 deletions.
91 changes: 43 additions & 48 deletions actionpack/test/controller/new_render_test.rb
Expand Up @@ -116,127 +116,122 @@ def rescue_action(e)


class RenderTest < Test::Unit::TestCase class RenderTest < Test::Unit::TestCase
def setup def setup
@controller = TestController.new
@request = ActionController::TestRequest.new @request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new @response = ActionController::TestResponse.new


@request.host = "www.nextangle.com" @request.host = "www.nextangle.com"
end end


def test_simple_show def test_simple_show
@request.action = "hello_world" get :hello_world
response = process_request assert_response :success
assert_equal "200 OK", response.headers["Status"] assert_template "test/hello_world"
assert_equal "test/hello_world", response.template.first_render
end end


def test_do_with_render def test_do_with_render
@request.action = "render_hello_world" get :render_hello_world
assert_equal "test/hello_world", process_request.template.first_render assert_template "test/hello_world"
end end


def test_do_with_render_from_variable def test_do_with_render_from_variable
@request.action = "render_hello_world_from_variable" get :render_hello_world_from_variable
assert_equal "hello david", process_request.body assert_equal "hello david", @response.body
end end


def test_do_with_render_action def test_do_with_render_action
@request.action = "render_action_hello_world" get :render_action_hello_world
assert_equal "test/hello_world", process_request.template.first_render assert_template "test/hello_world"
end end


def test_do_with_render_text def test_do_with_render_text
@request.action = "render_text_hello_world" get :render_text_hello_world
assert_equal "hello world", process_request.body assert_equal "hello world", @response.body
end end


def test_do_with_render_custom_code def test_do_with_render_custom_code
@request.action = "render_custom_code" get :render_custom_code
assert_equal "404 Moved", process_request.headers["Status"] assert_response :missing
end end


def test_attempt_to_access_object_method def test_attempt_to_access_object_method
@request.action = "clone" assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { process_request }
end end


def test_private_methods def test_private_methods
@request.action = "determine_layout" assert_raises(ActionController::UnknownAction, "No action responded to [determine_layout]") { get :determine_layout }
assert_raises(ActionController::UnknownAction, "No action responded to [determine_layout]") { process_request }
end end


def test_access_to_request_in_view def test_access_to_request_in_view
ActionController::Base.view_controller_internals = false ActionController::Base.view_controller_internals = false


@request.action = "hello_world" get :hello_world
response = process_request assert_nil(assigns["request"])
assert_nil response.template.assigns["request"]


ActionController::Base.view_controller_internals = true ActionController::Base.view_controller_internals = true


@request.action = "hello_world" get :hello_world
response = process_request assert_kind_of ActionController::AbstractRequest, assigns["request"]
assert_kind_of ActionController::AbstractRequest, response.template.assigns["request"]
end end


def test_render_xml def test_render_xml
@request.action = "render_xml_hello" get :render_xml_hello
assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", process_request.body assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
end end


def test_render_xml_with_default def test_render_xml_with_default
@request.action = "greeting" get :greeting
assert_equal "<p>This is grand!</p>\n", process_request.body assert_equal "<p>This is grand!</p>\n", @response.body
end end


def test_layout_rendering def test_layout_rendering
@request.action = "layout_test" get :layout_test
assert_equal "<html>Hello world!</html>", process_request.body assert_equal "<html>Hello world!</html>", @response.body
end end


def test_layout_test_with_different_layout def test_layout_test_with_different_layout
@request.action = "layout_test_with_different_layout" get :layout_test_with_different_layout
assert_equal "<html>Hello world!</html>", process_request.body assert_equal "<html>Hello world!</html>", @response.body
end end


def test_rendering_without_layout def test_rendering_without_layout
@request.action = "rendering_without_layout" get :rendering_without_layout
assert_equal "Hello world!", process_request.body assert_equal "Hello world!", @response.body
end end


def test_rendering_nothing_on_layout def test_rendering_nothing_on_layout
@request.action = "rendering_nothing_on_layout" get :rendering_nothing_on_layout
assert_equal "", process_request.body assert_equal "", @response.body
end end


def test_render_xml_with_layouts def test_render_xml_with_layouts
@request.action = "builder_layout_test" get :builder_layout_test
assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", process_request.body assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
end end


def test_partials_list def test_partials_list
@request.action = "partials_list" get :partials_list
assert_equal "Hello: davidHello: mary", process_request.body assert_equal "Hello: davidHello: mary", @response.body
end end


def test_partial_only def test_partial_only
@request.action = "partial_only" get :partial_only
assert_equal "only partial", process_request.body assert_equal "only partial", @response.body
end end


def test_render_to_string def test_render_to_string
@request.action = "hello_in_a_string" get :hello_in_a_string
assert_equal "How's there? Hello: davidHello: mary", process_request.body assert_equal "How's there? Hello: davidHello: mary", @response.body
end end


def test_nested_rendering def test_nested_rendering
@request.action = "hello_world" get :hello_world
assert_equal "Living in a nested world", Fun::GamesController.process(@request, @response).body assert_equal "Living in a nested world", Fun::GamesController.process(@request, @response).body
end end


def test_accessing_params_in_template def test_accessing_params_in_template
@request.action = "accessing_params_in_template" get :accessing_params_in_template, :name => "David"
@request.query_parameters[:name] = "David" assert_equal "Hello: David", @response.body
assert_equal "Hello: David", process_request.body
end end


private private
Expand Down

0 comments on commit 79d9794

Please sign in to comment.