diff options
Diffstat (limited to 'actionpack/test')
26 files changed, 371 insertions, 428 deletions
diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb index f1dcb39ef1..331797afcf 100644 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ b/actionpack/test/abstract_controller/abstract_controller_test.rb @@ -139,7 +139,7 @@ module AbstractController private def self.layout(formats) begin - view_paths.find_by_parts(name.underscore, {:formats => formats}t, "layouts") + view_paths.find_by_parts(name.underscore, {:formats => formats}, "layouts") rescue ActionView::MissingTemplate begin view_paths.find_by_parts("application", {:formats => formats}, "layouts") diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb index 34f18806a2..663cd259c8 100644 --- a/actionpack/test/activerecord/active_record_store_test.rb +++ b/actionpack/test/activerecord/active_record_store_test.rb @@ -13,6 +13,7 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest end def set_session_value + raise "missing session!" unless session session[:foo] = params[:foo] || "bar" head :ok end diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 96f7a42c9b..dd59999a0c 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -292,14 +292,14 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase # make sure that the template objects exist def test_template_objects_alive process :assign_this - assert !@response.has_template_object?('hi') - assert @response.has_template_object?('howdy') + assert !@controller.template.assigns['hi'] + assert @controller.template.assigns['howdy'] end # make sure we don't have template objects when we shouldn't def test_template_object_missing process :nothing - assert_nil @response.template_objects['howdy'] + assert_nil @controller.template.assigns['howdy'] end # check the empty flashing @@ -328,11 +328,11 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase # check if we were rendered by a file-based template? def test_rendered_action process :nothing - assert_nil @response.rendered[:template] + assert_nil @controller.template.rendered[:template] process :hello_world - assert @response.rendered[:template] - assert 'hello_world', @response.rendered[:template].to_s + assert @controller.template.rendered[:template] + assert 'hello_world', @controller.template.rendered[:template].to_s end # check the redirection location @@ -378,10 +378,12 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase def test_redirect_url_match process :redirect_external assert @response.redirect? - assert @response.redirect_url_match?("rubyonrails") - assert @response.redirect_url_match?(/rubyonrails/) - assert !@response.redirect_url_match?("phpoffrails") - assert !@response.redirect_url_match?(/perloffrails/) + assert_deprecated do + assert @response.redirect_url_match?("rubyonrails") + assert @response.redirect_url_match?(/rubyonrails/) + assert !@response.redirect_url_match?("phpoffrails") + assert !@response.redirect_url_match?(/perloffrails/) + end end # check for a redirection diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 569d698a03..c3bd113b86 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -53,7 +53,7 @@ class DispatcherTest < Test::Unit::TestCase assert_equal [ 500, {"Content-Type" => "text/html"}, - "<html><body><h1>500 Internal Server Error</h1></body></html>" + ["<html><body><h1>500 Internal Server Error</h1></body></html>"] ], dispatch end end diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index e83fde2349..aca7a821c8 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -165,11 +165,11 @@ class FilterTest < Test::Unit::TestCase def index render :text => 'ok' end - + def public end end - + class SkippingAndReorderingController < TestController skip_before_filter :ensure_login before_filter :find_record @@ -450,7 +450,8 @@ class FilterTest < Test::Unit::TestCase def test_empty_filter_chain assert_equal 0, EmptyFilterChainController.filter_chain.size - assert test_process(EmptyFilterChainController).template.assigns['action_executed'] + test_process(EmptyFilterChainController) + assert @controller.template.assigns['action_executed'] end def test_added_filter_to_inheritance_graph @@ -466,88 +467,109 @@ class FilterTest < Test::Unit::TestCase end def test_running_filters - assert_equal %w( wonderful_life ensure_login ), test_process(PrependingController).template.assigns["ran_filter"] + test_process(PrependingController) + assert_equal %w( wonderful_life ensure_login ), @controller.template.assigns["ran_filter"] end def test_running_filters_with_proc - assert test_process(ProcController).template.assigns["ran_proc_filter"] + test_process(ProcController) + assert @controller.template.assigns["ran_proc_filter"] end def test_running_filters_with_implicit_proc - assert test_process(ImplicitProcController).template.assigns["ran_proc_filter"] + test_process(ImplicitProcController) + assert @controller.template.assigns["ran_proc_filter"] end def test_running_filters_with_class - assert test_process(AuditController).template.assigns["was_audited"] + test_process(AuditController) + assert @controller.template.assigns["was_audited"] end def test_running_anomolous_yet_valid_condition_filters - response = test_process(AnomolousYetValidConditionController) - assert_equal %w( ensure_login ), response.template.assigns["ran_filter"] - assert response.template.assigns["ran_class_filter"] - assert response.template.assigns["ran_proc_filter1"] - assert response.template.assigns["ran_proc_filter2"] + test_process(AnomolousYetValidConditionController) + assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"] + assert @controller.template.assigns["ran_class_filter"] + assert @controller.template.assigns["ran_proc_filter1"] + assert @controller.template.assigns["ran_proc_filter2"] - response = test_process(AnomolousYetValidConditionController, "show_without_filter") - assert_equal nil, response.template.assigns["ran_filter"] - assert !response.template.assigns["ran_class_filter"] - assert !response.template.assigns["ran_proc_filter1"] - assert !response.template.assigns["ran_proc_filter2"] + test_process(AnomolousYetValidConditionController, "show_without_filter") + assert_equal nil, @controller.template.assigns["ran_filter"] + assert !@controller.template.assigns["ran_class_filter"] + assert !@controller.template.assigns["ran_proc_filter1"] + assert !@controller.template.assigns["ran_proc_filter2"] end def test_running_conditional_options - response = test_process(ConditionalOptionsFilter) - assert_equal %w( ensure_login ), response.template.assigns["ran_filter"] + test_process(ConditionalOptionsFilter) + assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"] end def test_running_collection_condition_filters - assert_equal %w( ensure_login ), test_process(ConditionalCollectionFilterController).template.assigns["ran_filter"] - assert_equal nil, test_process(ConditionalCollectionFilterController, "show_without_filter").template.assigns["ran_filter"] - assert_equal nil, test_process(ConditionalCollectionFilterController, "another_action").template.assigns["ran_filter"] + test_process(ConditionalCollectionFilterController) + assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"] + test_process(ConditionalCollectionFilterController, "show_without_filter") + assert_equal nil, @controller.template.assigns["ran_filter"] + test_process(ConditionalCollectionFilterController, "another_action") + assert_equal nil, @controller.template.assigns["ran_filter"] end def test_running_only_condition_filters - assert_equal %w( ensure_login ), test_process(OnlyConditionSymController).template.assigns["ran_filter"] - assert_equal nil, test_process(OnlyConditionSymController, "show_without_filter").template.assigns["ran_filter"] + test_process(OnlyConditionSymController) + assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"] + test_process(OnlyConditionSymController, "show_without_filter") + assert_equal nil, @controller.template.assigns["ran_filter"] - assert test_process(OnlyConditionProcController).template.assigns["ran_proc_filter"] - assert !test_process(OnlyConditionProcController, "show_without_filter").template.assigns["ran_proc_filter"] + test_process(OnlyConditionProcController) + assert @controller.template.assigns["ran_proc_filter"] + test_process(OnlyConditionProcController, "show_without_filter") + assert !@controller.template.assigns["ran_proc_filter"] - assert test_process(OnlyConditionClassController).template.assigns["ran_class_filter"] - assert !test_process(OnlyConditionClassController, "show_without_filter").template.assigns["ran_class_filter"] + test_process(OnlyConditionClassController) + assert @controller.template.assigns["ran_class_filter"] + test_process(OnlyConditionClassController, "show_without_filter") + assert !@controller.template.assigns["ran_class_filter"] end def test_running_except_condition_filters - assert_equal %w( ensure_login ), test_process(ExceptConditionSymController).template.assigns["ran_filter"] - assert_equal nil, test_process(ExceptConditionSymController, "show_without_filter").template.assigns["ran_filter"] + test_process(ExceptConditionSymController) + assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"] + test_process(ExceptConditionSymController, "show_without_filter") + assert_equal nil, @controller.template.assigns["ran_filter"] - assert test_process(ExceptConditionProcController).template.assigns["ran_proc_filter"] - assert !test_process(ExceptConditionProcController, "show_without_filter").template.assigns["ran_proc_filter"] + test_process(ExceptConditionProcController) + assert @controller.template.assigns["ran_proc_filter"] + test_process(ExceptConditionProcController, "show_without_filter") + assert !@controller.template.assigns["ran_proc_filter"] - assert test_process(ExceptConditionClassController).template.assigns["ran_class_filter"] - assert !test_process(ExceptConditionClassController, "show_without_filter").template.assigns["ran_class_filter"] + test_process(ExceptConditionClassController) + assert @controller.template.assigns["ran_class_filter"] + test_process(ExceptConditionClassController, "show_without_filter") + assert !@controller.template.assigns["ran_class_filter"] end def test_running_before_and_after_condition_filters - assert_equal %w( ensure_login clean_up_tmp), test_process(BeforeAndAfterConditionController).template.assigns["ran_filter"] - assert_equal nil, test_process(BeforeAndAfterConditionController, "show_without_filter").template.assigns["ran_filter"] + test_process(BeforeAndAfterConditionController) + assert_equal %w( ensure_login clean_up_tmp), @controller.template.assigns["ran_filter"] + test_process(BeforeAndAfterConditionController, "show_without_filter") + assert_equal nil, @controller.template.assigns["ran_filter"] end def test_around_filter - controller = test_process(AroundFilterController) - assert controller.template.assigns["before_ran"] - assert controller.template.assigns["after_ran"] + test_process(AroundFilterController) + assert @controller.template.assigns["before_ran"] + assert @controller.template.assigns["after_ran"] end def test_before_after_class_filter - controller = test_process(BeforeAfterClassFilterController) - assert controller.template.assigns["before_ran"] - assert controller.template.assigns["after_ran"] + test_process(BeforeAfterClassFilterController) + assert @controller.template.assigns["before_ran"] + assert @controller.template.assigns["after_ran"] end def test_having_properties_in_around_filter - controller = test_process(AroundFilterController) - assert_equal "before and after", controller.template.assigns["execution_log"] + test_process(AroundFilterController) + assert_equal "before and after", @controller.template.assigns["execution_log"] end def test_prepending_and_appending_around_filter @@ -560,7 +582,7 @@ class FilterTest < Test::Unit::TestCase def test_rendering_breaks_filtering_chain response = test_process(RenderingController) assert_equal "something else", response.body - assert !response.template.assigns["ran_action"] + assert !@controller.template.assigns["ran_action"] end def test_filters_with_mixed_specialization_run_in_order @@ -586,40 +608,53 @@ class FilterTest < Test::Unit::TestCase def test_running_prepended_before_and_after_filter assert_equal 3, PrependingBeforeAndAfterController.filter_chain.length - response = test_process(PrependingBeforeAndAfterController) - assert_equal %w( before_all between_before_all_and_after_all after_all ), response.template.assigns["ran_filter"] + test_process(PrependingBeforeAndAfterController) + assert_equal %w( before_all between_before_all_and_after_all after_all ), @controller.template.assigns["ran_filter"] end - + def test_skipping_and_limiting_controller - assert_equal %w( ensure_login ), test_process(SkippingAndLimitedController, "index").template.assigns["ran_filter"] - assert_nil test_process(SkippingAndLimitedController, "public").template.assigns["ran_filter"] + test_process(SkippingAndLimitedController, "index") + assert_equal %w( ensure_login ), @controller.template.assigns["ran_filter"] + test_process(SkippingAndLimitedController, "public") + assert_nil @controller.template.assigns["ran_filter"] end def test_skipping_and_reordering_controller - assert_equal %w( find_record ensure_login ), test_process(SkippingAndReorderingController, "index").template.assigns["ran_filter"] + test_process(SkippingAndReorderingController, "index") + assert_equal %w( find_record ensure_login ), @controller.template.assigns["ran_filter"] end def test_conditional_skipping_of_filters - assert_nil test_process(ConditionalSkippingController, "login").template.assigns["ran_filter"] - assert_equal %w( ensure_login find_user ), test_process(ConditionalSkippingController, "change_password").template.assigns["ran_filter"] + test_process(ConditionalSkippingController, "login") + assert_nil @controller.template.assigns["ran_filter"] + test_process(ConditionalSkippingController, "change_password") + assert_equal %w( ensure_login find_user ), @controller.template.assigns["ran_filter"] - assert_nil test_process(ConditionalSkippingController, "login").template.controller.instance_variable_get("@ran_after_filter") - assert_equal %w( clean_up ), test_process(ConditionalSkippingController, "change_password").template.controller.instance_variable_get("@ran_after_filter") + test_process(ConditionalSkippingController, "login") + assert_nil @controller.template.controller.instance_variable_get("@ran_after_filter") + test_process(ConditionalSkippingController, "change_password") + assert_equal %w( clean_up ), @controller.template.controller.instance_variable_get("@ran_after_filter") end def test_conditional_skipping_of_filters_when_parent_filter_is_also_conditional - assert_equal %w( conditional_in_parent conditional_in_parent ), test_process(ChildOfConditionalParentController).template.assigns['ran_filter'] - assert_nil test_process(ChildOfConditionalParentController, 'another_action').template.assigns['ran_filter'] + test_process(ChildOfConditionalParentController) + assert_equal %w( conditional_in_parent conditional_in_parent ), @controller.template.assigns['ran_filter'] + test_process(ChildOfConditionalParentController, 'another_action') + assert_nil @controller.template.assigns['ran_filter'] end def test_condition_skipping_of_filters_when_siblings_also_have_conditions - assert_equal %w( conditional_in_parent conditional_in_parent ), test_process(ChildOfConditionalParentController).template.assigns['ran_filter'], "1" - assert_equal nil, test_process(AnotherChildOfConditionalParentController).template.assigns['ran_filter'] - assert_equal %w( conditional_in_parent conditional_in_parent ), test_process(ChildOfConditionalParentController).template.assigns['ran_filter'] + test_process(ChildOfConditionalParentController) + assert_equal %w( conditional_in_parent conditional_in_parent ), @controller.template.assigns['ran_filter'], "1" + test_process(AnotherChildOfConditionalParentController) + assert_equal nil, @controller.template.assigns['ran_filter'] + test_process(ChildOfConditionalParentController) + assert_equal %w( conditional_in_parent conditional_in_parent ), @controller.template.assigns['ran_filter'] end def test_changing_the_requirements - assert_equal nil, test_process(ChangingTheRequirementsController, "go_wild").template.assigns['ran_filter'] + test_process(ChangingTheRequirementsController, "go_wild") + assert_equal nil, @controller.template.assigns['ran_filter'] end def test_a_rescuing_around_filter @@ -638,7 +673,8 @@ class FilterTest < Test::Unit::TestCase request = ActionController::TestRequest.new request.action = action controller = controller.new if controller.is_a?(Class) - controller.process_with_test(request, ActionController::TestResponse.new) + @controller = controller + @controller.process_with_test(request, ActionController::TestResponse.new) end end @@ -819,9 +855,9 @@ class YieldingAroundFiltersTest < Test::Unit::TestCase end def test_with_proc - controller = test_process(ControllerWithProcFilter,'no_raise') - assert controller.template.assigns['before'] - assert controller.template.assigns['after'] + test_process(ControllerWithProcFilter,'no_raise') + assert @controller.template.assigns['before'] + assert @controller.template.assigns['after'] end def test_nested_filters @@ -841,13 +877,13 @@ class YieldingAroundFiltersTest < Test::Unit::TestCase end def test_filter_order_with_all_filter_types - controller = test_process(ControllerWithAllTypesOfFilters,'no_raise') - assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) around (after yield) after',controller.template.assigns['ran_filter'].join(' ') + test_process(ControllerWithAllTypesOfFilters,'no_raise') + assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) around (after yield) after', @controller.template.assigns['ran_filter'].join(' ') end def test_filter_order_with_skip_filter_method - controller = test_process(ControllerWithTwoLessFilters,'no_raise') - assert_equal 'before around (before yield) around (after yield)',controller.template.assigns['ran_filter'].join(' ') + test_process(ControllerWithTwoLessFilters,'no_raise') + assert_equal 'before around (before yield) around (after yield)', @controller.template.assigns['ran_filter'].join(' ') end def test_first_filter_in_multiple_before_filter_chain_halts @@ -880,6 +916,7 @@ class YieldingAroundFiltersTest < Test::Unit::TestCase request = ActionController::TestRequest.new request.action = action controller = controller.new if controller.is_a?(Class) - controller.process_with_test(request, ActionController::TestResponse.new) + @controller = controller + @controller.process_with_test(request, ActionController::TestResponse.new) end end diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index d8a892811e..ef60cae0ff 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -79,64 +79,64 @@ class FlashTest < ActionController::TestCase get :set_flash get :use_flash - assert_equal "hello", @response.template.assigns["flash_copy"]["that"] - assert_equal "hello", @response.template.assigns["flashy"] + assert_equal "hello", @controller.template.assigns["flash_copy"]["that"] + assert_equal "hello", @controller.template.assigns["flashy"] get :use_flash - assert_nil @response.template.assigns["flash_copy"]["that"], "On second flash" + assert_nil @controller.template.assigns["flash_copy"]["that"], "On second flash" end def test_keep_flash get :set_flash get :use_flash_and_keep_it - assert_equal "hello", @response.template.assigns["flash_copy"]["that"] - assert_equal "hello", @response.template.assigns["flashy"] + assert_equal "hello", @controller.template.assigns["flash_copy"]["that"] + assert_equal "hello", @controller.template.assigns["flashy"] get :use_flash - assert_equal "hello", @response.template.assigns["flash_copy"]["that"], "On second flash" + assert_equal "hello", @controller.template.assigns["flash_copy"]["that"], "On second flash" get :use_flash - assert_nil @response.template.assigns["flash_copy"]["that"], "On third flash" + assert_nil @controller.template.assigns["flash_copy"]["that"], "On third flash" end def test_flash_now get :set_flash_now - assert_equal "hello", @response.template.assigns["flash_copy"]["that"] - assert_equal "bar" , @response.template.assigns["flash_copy"]["foo"] - assert_equal "hello", @response.template.assigns["flashy"] + assert_equal "hello", @controller.template.assigns["flash_copy"]["that"] + assert_equal "bar" , @controller.template.assigns["flash_copy"]["foo"] + assert_equal "hello", @controller.template.assigns["flashy"] get :attempt_to_use_flash_now - assert_nil @response.template.assigns["flash_copy"]["that"] - assert_nil @response.template.assigns["flash_copy"]["foo"] - assert_nil @response.template.assigns["flashy"] + assert_nil @controller.template.assigns["flash_copy"]["that"] + assert_nil @controller.template.assigns["flash_copy"]["foo"] + assert_nil @controller.template.assigns["flashy"] end def test_update_flash get :set_flash get :use_flash_and_update_it - assert_equal "hello", @response.template.assigns["flash_copy"]["that"] - assert_equal "hello again", @response.template.assigns["flash_copy"]["this"] + assert_equal "hello", @controller.template.assigns["flash_copy"]["that"] + assert_equal "hello again", @controller.template.assigns["flash_copy"]["this"] get :use_flash - assert_nil @response.template.assigns["flash_copy"]["that"], "On second flash" - assert_equal "hello again", @response.template.assigns["flash_copy"]["this"], "On second flash" + assert_nil @controller.template.assigns["flash_copy"]["that"], "On second flash" + assert_equal "hello again", @controller.template.assigns["flash_copy"]["this"], "On second flash" end def test_flash_after_reset_session get :use_flash_after_reset_session - assert_equal "hello", @response.template.assigns["flashy_that"] - assert_equal "good-bye", @response.template.assigns["flashy_this"] - assert_nil @response.template.assigns["flashy_that_reset"] + assert_equal "hello", @controller.template.assigns["flashy_that"] + assert_equal "good-bye", @controller.template.assigns["flashy_this"] + assert_nil @controller.template.assigns["flashy_that_reset"] end def test_sweep_after_halted_filter_chain get :std_action - assert_nil @response.template.assigns["flash_copy"]["foo"] + assert_nil @controller.template.assigns["flash_copy"]["foo"] get :filter_halting_action - assert_equal "bar", @response.template.assigns["flash_copy"]["foo"] + assert_equal "bar", @controller.template.assigns["flash_copy"]["foo"] get :std_action # follow redirection - assert_equal "bar", @response.template.assigns["flash_copy"]["foo"] + assert_equal "bar", @controller.template.assigns["flash_copy"]["foo"] get :std_action - assert_nil @response.template.assigns["flash_copy"]["foo"] + assert_nil @controller.template.assigns["flash_copy"]["foo"] end end diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index 5f36461b89..58addc123d 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -211,7 +211,7 @@ class IsolatedHelpersTest < Test::Unit::TestCase end def test_helper_in_a - assert_raise(NameError) { A.process(@request, @response) } + assert_raise(ActionView::TemplateError) { A.process(@request, @response) } end def test_helper_in_b diff --git a/actionpack/test/controller/http_digest_authentication_test.rb b/actionpack/test/controller/http_digest_authentication_test.rb index 00789eea38..7bebc8cd2a 100644 --- a/actionpack/test/controller/http_digest_authentication_test.rb +++ b/actionpack/test/controller/http_digest_authentication_test.rb @@ -111,8 +111,6 @@ class HttpDigestAuthenticationTest < ActionController::TestCase test "authentication request with valid credential and nil session" do @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please') - # session_id = "" in functional test, but is +nil+ in real life - @request.session.session_id = nil get :display assert_response :success diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index e39a934c24..70fa41aded 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -297,7 +297,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest assert_response 410 assert_response :gone assert_equal "cookie_1=; path=/\ncookie_3=chocolate; path=/", headers["Set-Cookie"] - assert_equal({"cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies) + assert_equal({"cookie_1"=>nil, "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies) assert_equal "Gone", response.body end end @@ -337,7 +337,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest get '/get_with_params?foo=bar' assert_equal '/get_with_params?foo=bar', request.env["REQUEST_URI"] assert_equal '/get_with_params?foo=bar', request.request_uri - assert_equal "", request.env["QUERY_STRING"] + assert_equal "foo=bar", request.env["QUERY_STRING"] assert_equal 'foo=bar', request.query_string assert_equal 'bar', request.parameters['foo'] diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index f2721e274d..da3f7b0cb8 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -56,8 +56,8 @@ class LayoutAutoDiscoveryTest < ActionController::TestCase def test_third_party_template_library_auto_discovers_layout @controller = ThirdPartyTemplateLibraryController.new get :hello - assert_equal 'layouts/third_party_template_library.mab', @controller.active_layout(true).to_s - assert_equal 'layouts/third_party_template_library', @response.layout + assert @controller.active_layout(true).identifier.include?('layouts/third_party_template_library.mab') + assert @controller.template.layout.include?('layouts/third_party_template_library') assert_response :success assert_equal 'Mab', @response.body end @@ -72,7 +72,7 @@ class LayoutAutoDiscoveryTest < ActionController::TestCase def test_namespaced_controllers_auto_detect_layouts @controller = MultipleExtensions.new get :hello - assert_equal 'layouts/multiple_extensions.html.erb', @controller.active_layout(true).to_s + assert @controller.active_layout(true).identifier.include?('layouts/multiple_extensions.html.erb') assert_equal 'multiple_extensions.html.erb hello.rhtml', @response.body.strip end end @@ -116,70 +116,72 @@ class RendersNoLayoutController < LayoutTest end class LayoutSetInResponseTest < ActionController::TestCase + include ActionView::TemplateHandlers + def test_layout_set_when_using_default_layout @controller = DefaultLayoutController.new get :hello - assert_equal 'layouts/layout_test', @response.layout + assert @controller.template.layout.include?('layouts/layout_test') end def test_layout_set_when_set_in_controller @controller = HasOwnLayoutController.new get :hello - assert_equal 'layouts/item', @response.layout + assert @controller.template.layout.include?('layouts/item') end def test_layout_only_exception_when_included @controller = OnlyLayoutController.new get :hello - assert_equal 'layouts/item', @response.layout + assert @controller.template.layout.include?('layouts/item') end def test_layout_only_exception_when_excepted @controller = OnlyLayoutController.new get :goodbye - assert_equal nil, @response.layout + assert_equal nil, @controller.template.layout end def test_layout_except_exception_when_included @controller = ExceptLayoutController.new get :hello - assert_equal 'layouts/item', @response.layout + assert @controller.template.layout.include?('layouts/item') end def test_layout_except_exception_when_excepted @controller = ExceptLayoutController.new get :goodbye - assert_equal nil, @response.layout + assert_equal nil, @controller.template.layout end def test_layout_set_when_using_render @controller = SetsLayoutInRenderController.new get :hello - assert_equal 'layouts/third_party_template_library', @response.layout + assert @controller.template.layout.include?('layouts/third_party_template_library') end def test_layout_is_not_set_when_none_rendered @controller = RendersNoLayoutController.new get :hello - assert_nil @response.layout + assert_nil @controller.template.layout end def test_exempt_from_layout_honored_by_render_template - ActionController::Base.exempt_from_layout :rhtml + ActionController::Base.exempt_from_layout :erb @controller = RenderWithTemplateOptionController.new get :hello assert_equal "alt/hello.rhtml", @response.body.strip ensure - ActionController::Base.exempt_from_layout.delete(/\.rhtml$/) + ActionController::Base.exempt_from_layout.delete(ERB) end def test_layout_is_picked_from_the_controller_instances_view_path pending do @controller = PrependsViewPathController.new get :hello - assert_equal 'layouts/alt', @response.layout + assert_equal 'layouts/alt', @controller.template.layout end end @@ -204,7 +206,7 @@ class LayoutExceptionRaised < ActionController::TestCase def test_exception_raised_when_layout_file_not_found @controller = SetsNonExistentLayoutFile.new get :hello - assert_kind_of ActionView::MissingTemplate, @response.template.instance_eval { @exception } + assert_kind_of ActionView::MissingTemplate, @controller.template.instance_eval { @exception } end end @@ -232,7 +234,7 @@ unless RUBY_PLATFORM =~ /(:?mswin|mingw|bccwin)/ @controller = LayoutSymlinkedTest.new get :hello assert_response 200 - assert_equal "layouts/symlinked/symlinked_layout", @response.layout + assert @controller.template.layout.include?("layouts/symlinked/symlinked_layout") end end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index bf72730bea..da063710a9 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'controller/fake_models' +require 'pathname' module Fun class GamesController < ActionController::Base @@ -772,7 +773,7 @@ class RenderTest < ActionController::TestCase begin get :render_line_offset flunk "the action should have raised an exception" - rescue RuntimeError => exc + rescue StandardError => exc line = exc.backtrace.first assert(line =~ %r{:(\d+):}) assert_equal "1", $1, @@ -1735,7 +1736,7 @@ class RenderingLoggingTest < ActionController::TestCase @controller.logger = MockLogger.new get :layout_test logged = @controller.logger.logged.find_all {|l| l =~ /render/i } - assert_equal "Rendering test/hello_world", logged[0] - assert_equal "Rendering template within layouts/standard", logged[1] + assert logged[0] =~ %r{Rendering.*test/hello_world} + assert logged[1] =~ %r{Rendering template within.*layouts/standard} end end diff --git a/actionpack/test/controller/request/test_request_test.rb b/actionpack/test/controller/request/test_request_test.rb index 81551b4ba7..0a39feb7fe 100644 --- a/actionpack/test/controller/request/test_request_test.rb +++ b/actionpack/test/controller/request/test_request_test.rb @@ -10,26 +10,27 @@ class ActionController::TestRequestTest < ActiveSupport::TestCase def test_test_request_has_session_options_initialized assert @request.session_options end - - Rack::Session::Abstract::ID::DEFAULT_OPTIONS.each_key do |option| - test "test_rack_default_session_options_#{option}_exists_in_session_options_and_is_default" do - assert_equal(Rack::Session::Abstract::ID::DEFAULT_OPTIONS[option], - @request.session_options[option], + + ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS.each_key do |option| + test "rack default session options #{option} exists in session options and is default" do + assert_equal(ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS[option], + @request.session_options[option], "Missing rack session default option #{option} in request.session_options") end - test "test_rack_default_session_options_#{option}_exists_in_session_options" do - assert(@request.session_options.has_key?(option), + + test "rack default session options #{option} exists in session options" do + assert(@request.session_options.has_key?(option), "Missing rack session option #{option} in request.session_options") end end - + def test_session_id_exists_by_default assert_not_nil(@request.session_options[:id]) end - + def test_session_id_different_on_each_call - prev_id = + prev_id = assert_not_equal(@request.session_options[:id], ActionController::TestRequest.new.session_options[:id]) end - + end
\ No newline at end of file diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index 124e259ef6..f68ffc7a2a 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -184,12 +184,6 @@ XML 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 diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb index 1539f8f506..0ac10634b2 100644 --- a/actionpack/test/controller/view_paths_test.rb +++ b/actionpack/test/controller/view_paths_test.rb @@ -20,7 +20,7 @@ class ViewLoadPathsTest < ActionController::TestCase layout 'test/sub' def hello_world; render(:template => 'test/hello_world'); end end - + def setup TestController.view_paths = nil @@ -42,30 +42,39 @@ class ViewLoadPathsTest < ActionController::TestCase ActiveSupport::Deprecation.behavior = @old_behavior end + def expand(array) + array.map {|x| File.expand_path(x)} + end + + def assert_paths(*paths) + controller = paths.first.is_a?(Class) ? paths.shift : @controller + assert_equal expand(paths), controller.view_paths.map(&:to_s) + end + def test_template_load_path_was_set_correctly - assert_equal [FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s) + assert_paths FIXTURE_LOAD_PATH end def test_controller_appends_view_path_correctly @controller.append_view_path 'foo' - assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths.map(&:to_s) + assert_paths(FIXTURE_LOAD_PATH, "foo") @controller.append_view_path(%w(bar baz)) - assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s) - + assert_paths(FIXTURE_LOAD_PATH, "foo", "bar", "baz") + @controller.append_view_path(FIXTURE_LOAD_PATH) - assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s) + assert_paths(FIXTURE_LOAD_PATH, "foo", "bar", "baz", FIXTURE_LOAD_PATH) end def test_controller_prepends_view_path_correctly @controller.prepend_view_path 'baz' - assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s) + assert_paths("baz", FIXTURE_LOAD_PATH) @controller.prepend_view_path(%w(foo bar)) - assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s) + assert_paths "foo", "bar", "baz", FIXTURE_LOAD_PATH @controller.prepend_view_path(FIXTURE_LOAD_PATH) - assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s) + assert_paths FIXTURE_LOAD_PATH, "foo", "bar", "baz", FIXTURE_LOAD_PATH end def test_template_appends_view_path_correctly @@ -73,11 +82,11 @@ class ViewLoadPathsTest < ActionController::TestCase class_view_paths = TestController.view_paths @controller.append_view_path 'foo' - assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths.map(&:to_s) + assert_paths FIXTURE_LOAD_PATH, "foo" @controller.append_view_path(%w(bar baz)) - assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s) - assert_equal class_view_paths, TestController.view_paths + assert_paths FIXTURE_LOAD_PATH, "foo", "bar", "baz" + assert_paths TestController, *class_view_paths end def test_template_prepends_view_path_correctly @@ -85,11 +94,11 @@ class ViewLoadPathsTest < ActionController::TestCase class_view_paths = TestController.view_paths @controller.prepend_view_path 'baz' - assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s) + assert_paths "baz", FIXTURE_LOAD_PATH @controller.prepend_view_path(%w(foo bar)) - assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s) - assert_equal class_view_paths, TestController.view_paths + assert_paths "foo", "bar", "baz", FIXTURE_LOAD_PATH + assert_paths TestController, *class_view_paths end def test_view_paths @@ -130,12 +139,12 @@ class ViewLoadPathsTest < ActionController::TestCase A.view_paths = ['a/path'] - assert_equal ['a/path'], A.view_paths.map(&:to_s) - assert_equal A.view_paths, B.view_paths - assert_equal original_load_paths, C.view_paths - + assert_paths A, "a/path" + assert_paths A, *B.view_paths + assert_paths C, *original_load_paths + C.view_paths = [] assert_nothing_raised { C.view_paths << 'c/path' } - assert_equal ['c/path'], C.view_paths.map(&:to_s) + assert_paths C, "c/path" end end diff --git a/actionpack/test/dispatch/rack_test.rb b/actionpack/test/dispatch/rack_test.rb index 9fad4b22ee..94eba2a24f 100644 --- a/actionpack/test/dispatch/rack_test.rb +++ b/actionpack/test/dispatch/rack_test.rb @@ -201,93 +201,3 @@ class RackRequestNeedsRewoundTest < BaseRackTest assert_equal 0, request.body.pos end end - -class RackResponseTest < BaseRackTest - def setup - super - @response = ActionDispatch::Response.new - end - - test "simple output" do - @response.body = "Hello, World!" - @response.prepare! - - status, headers, body = @response.to_a - assert_equal 200, status - assert_equal({ - "Content-Type" => "text/html; charset=utf-8", - "Cache-Control" => "private, max-age=0, must-revalidate", - "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"', - "Set-Cookie" => "", - "Content-Length" => "13" - }, headers) - - parts = [] - body.each { |part| parts << part } - assert_equal ["Hello, World!"], parts - end - - def test_utf8_output - @response.body = [1090, 1077, 1089, 1090].pack("U*") - @response.prepare! - - status, headers, body = @response.to_a - assert_equal 200, status - assert_equal({ - "Content-Type" => "text/html; charset=utf-8", - "Cache-Control" => "private, max-age=0, must-revalidate", - "ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"', - "Set-Cookie" => "", - "Content-Length" => "8" - }, headers) - end - - def test_streaming_block - @response.body = Proc.new do |response, output| - 5.times { |n| output.write(n) } - end - @response.prepare! - - status, headers, body = @response.to_a - assert_equal 200, status - assert_equal({ - "Content-Type" => "text/html; charset=utf-8", - "Cache-Control" => "no-cache", - "Set-Cookie" => "" - }, headers) - - parts = [] - body.each { |part| parts << part.to_s } - assert_equal ["0", "1", "2", "3", "4"], parts - end -end - -class RackResponseHeadersTest < BaseRackTest - def setup - super - @response = ActionDispatch::Response.new - @response.status = "200 OK" - end - - test "content type" do - [204, 304].each do |c| - @response.status = c.to_s - assert !response_headers.has_key?("Content-Type"), "#{c} should not have Content-Type header" - end - - [200, 302, 404, 500].each do |c| - @response.status = c.to_s - assert response_headers.has_key?("Content-Type"), "#{c} did not have Content-Type header" - end - end - - test "status" do - assert !response_headers.has_key?('Status') - end - - private - def response_headers - @response.prepare! - @response.to_a[1] - end -end diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index 88b81dc493..9e008a9ae8 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -94,9 +94,8 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest assert_equal %w(files foo), params.keys.sort assert_equal 'bar', params['foo'] - # Ruby CGI doesn't handle multipart/mixed for us. + # Rack doesn't handle multipart/mixed for us. files = params['files'] - assert_kind_of String, files files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding) assert_equal 19756, files.size end @@ -133,46 +132,6 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest end end - # The lint wrapper is used in integration tests - # instead of a normal StringIO class - InputWrapper = Rack::Lint::InputWrapper - - test "parses unwindable stream" do - InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE) - params = parse_multipart('large_text_file') - assert_equal %w(file foo), params.keys.sort - assert_equal 'bar', params['foo'] - end - - test "uploads and reads file with unwindable input" do - InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE) - - with_test_routing do - post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain") - assert_equal "File: Hello", response.body - end - end - - test "passes through rack middleware and uploads file" do - with_muck_middleware do - with_test_routing do - post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain") - assert_equal "File: Hello", response.body - end - end - end - - test "passes through rack middleware and uploads file with unwindable input" do - InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE) - - with_muck_middleware do - with_test_routing do - post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain") - assert_equal "File: Hello", response.body - end - end - end - private def fixture(name) File.open(File.join(FIXTURE_PATH, name), 'rb') do |file| @@ -199,25 +158,4 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest yield end end - - class MuckMiddleware - def initialize(app) - @app = app - end - - def call(env) - env['rack.input'].read - env['rack.input'].rewind - @app.call(env) - end - end - - def with_muck_middleware - original_middleware = ActionController::Dispatcher.middleware - middleware = original_middleware.dup - middleware.insert_after ActionDispatch::RewindableInput, MuckMiddleware - ActionController::Dispatcher.middleware = middleware - yield - ActionController::Dispatcher.middleware = original_middleware - end end diff --git a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb index 8de4a83d76..7167cdafac 100644 --- a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb @@ -126,45 +126,7 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest assert_parses expected, query end - test "passes through rack middleware and parses params" do - with_muck_middleware do - assert_parses({ "a" => { "b" => "c" } }, "a[b]=c") - end - end - - # The lint wrapper is used in integration tests - # instead of a normal StringIO class - InputWrapper = Rack::Lint::InputWrapper - - test "passes through rack middleware and parses params with unwindable input" do - InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE) - with_muck_middleware do - assert_parses({ "a" => { "b" => "c" } }, "a[b]=c") - end - end - private - class MuckMiddleware - def initialize(app) - @app = app - end - - def call(env) - env['rack.input'].read - env['rack.input'].rewind - @app.call(env) - end - end - - def with_muck_middleware - original_middleware = ActionController::Dispatcher.middleware - middleware = original_middleware.dup - middleware.insert_after ActionDispatch::RewindableInput, MuckMiddleware - ActionController::Dispatcher.middleware = middleware - yield - ActionController::Dispatcher.middleware = original_middleware - end - def with_test_routing with_routing do |set| set.draw do |map| diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb new file mode 100644 index 0000000000..2ddc6cb2b5 --- /dev/null +++ b/actionpack/test/dispatch/response_test.rb @@ -0,0 +1,130 @@ +require 'abstract_unit' + +class ResponseTest < ActiveSupport::TestCase + def setup + @response = ActionDispatch::Response.new + end + + test "simple output" do + @response.body = "Hello, World!" + @response.prepare! + + status, headers, body = @response.to_a + assert_equal 200, status + assert_equal({ + "Content-Type" => "text/html; charset=utf-8", + "Cache-Control" => "private, max-age=0, must-revalidate", + "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"', + "Set-Cookie" => "", + "Content-Length" => "13" + }, headers) + + parts = [] + body.each { |part| parts << part } + assert_equal ["Hello, World!"], parts + end + + test "utf8 output" do + @response.body = [1090, 1077, 1089, 1090].pack("U*") + @response.prepare! + + status, headers, body = @response.to_a + assert_equal 200, status + assert_equal({ + "Content-Type" => "text/html; charset=utf-8", + "Cache-Control" => "private, max-age=0, must-revalidate", + "ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"', + "Set-Cookie" => "", + "Content-Length" => "8" + }, headers) + end + + test "streaming block" do + @response.body = Proc.new do |response, output| + 5.times { |n| output.write(n) } + end + @response.prepare! + + status, headers, body = @response.to_a + assert_equal 200, status + assert_equal({ + "Content-Type" => "text/html; charset=utf-8", + "Cache-Control" => "no-cache", + "Set-Cookie" => "" + }, headers) + + parts = [] + body.each { |part| parts << part.to_s } + assert_equal ["0", "1", "2", "3", "4"], parts + end + + test "content type" do + [204, 304].each do |c| + @response.status = c.to_s + @response.prepare! + status, headers, body = @response.to_a + assert !headers.has_key?("Content-Type"), "#{c} should not have Content-Type header" + end + + [200, 302, 404, 500].each do |c| + @response.status = c.to_s + @response.prepare! + status, headers, body = @response.to_a + assert headers.has_key?("Content-Type"), "#{c} did not have Content-Type header" + end + end + + test "does not include Status header" do + @response.status = "200 OK" + @response.prepare! + status, headers, body = @response.to_a + assert !headers.has_key?('Status') + end + + test "response code" do + @response.status = "200 OK" + assert_equal 200, @response.response_code + + @response.status = "200" + assert_equal 200, @response.response_code + + @response.status = 200 + assert_equal 200, @response.response_code + end + + test "code" do + @response.status = "200 OK" + assert_equal "200", @response.code + + @response.status = "200" + assert_equal "200", @response.code + + @response.status = 200 + assert_equal "200", @response.code + end + + test "message" do + @response.status = "200 OK" + assert_equal "OK", @response.message + + @response.status = "200" + assert_equal "OK", @response.message + + @response.status = 200 + assert_equal "OK", @response.message + end + + test "cookies" do + @response.set_cookie("user_name", :value => "david", :path => "/") + @response.prepare! + status, headers, body = @response.to_a + assert_equal "user_name=david; path=/", headers["Set-Cookie"] + assert_equal({"user_name" => "david"}, @response.cookies) + + @response.set_cookie("login", :value => "foo&bar", :path => "/", :expires => Time.utc(2005, 10, 10,5)) + @response.prepare! + status, headers, body = @response.to_a + assert_equal "user_name=david; path=/\nlogin=foo%26bar; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", headers["Set-Cookie"] + assert_equal({"login" => "foo&bar", "user_name" => "david"}, @response.cookies) + end +end diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index b9bf8cf411..3090a70244 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -10,8 +10,7 @@ class CookieStoreTest < ActionController::IntegrationTest :key => SessionKey, :secret => SessionSecret) Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1') - - SignedBar = "BAh7BjoIZm9vIghiYXI%3D--fef868465920f415f2c0652d6910d3af288a0367" + SignedBar = Verifier.generate(:foo => "bar", :session_id => ActiveSupport::SecureRandom.hex(16)) class TestController < ActionController::Base def no_session_access diff --git a/actionpack/test/dispatch/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb index de6539e1cc..0ff93f1c5d 100644 --- a/actionpack/test/dispatch/session/test_session_test.rb +++ b/actionpack/test/dispatch/session/test_session_test.rb @@ -2,37 +2,30 @@ require 'abstract_unit' require 'stringio' class ActionController::TestSessionTest < ActiveSupport::TestCase - def test_calling_delete_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session assert_deprecated(/use clear instead/){ ActionController::TestSession.new.delete } end - + def test_calling_update_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session assert_deprecated(/use replace instead/){ ActionController::TestSession.new.update } end - + def test_calling_close_raises_deprecation_warning assert_deprecated(/sessions should no longer be closed/){ ActionController::TestSession.new.close } end - - def test_defaults - session = ActionController::TestSession.new - assert_equal({}, session.data) - assert_equal('', session.session_id) - end - + def test_ctor_allows_setting session = ActionController::TestSession.new({:one => 'one', :two => 'two'}) assert_equal('one', session[:one]) assert_equal('two', session[:two]) end - + def test_setting_session_item_sets_item session = ActionController::TestSession.new session[:key] = 'value' assert_equal('value', session[:key]) end - + def test_calling_delete_removes_item session = ActionController::TestSession.new session[:key] = 'value' @@ -40,13 +33,13 @@ class ActionController::TestSessionTest < ActiveSupport::TestCase session.delete(:key) assert_nil(session[:key]) end - + def test_calling_update_with_params_passes_to_attributes session = ActionController::TestSession.new() session.update('key' => 'value') assert_equal('value', session[:key]) end - + def test_clear_emptys_session params = {:one => 'one', :two => 'two'} session = ActionController::TestSession.new({:one => 'one', :two => 'two'}) @@ -54,5 +47,4 @@ class ActionController::TestSessionTest < ActiveSupport::TestCase assert_nil(session[:one]) assert_nil(session[:two]) end - -end
\ No newline at end of file +end diff --git a/actionpack/test/fixtures/layouts/standard.erb b/actionpack/test/fixtures/layouts/standard.html.erb index 368764e6f4..368764e6f4 100644 --- a/actionpack/test/fixtures/layouts/standard.erb +++ b/actionpack/test/fixtures/layouts/standard.html.erb diff --git a/actionpack/test/fixtures/test/render_file_with_locals_and_default.erb b/actionpack/test/fixtures/test/render_file_with_locals_and_default.erb new file mode 100644 index 0000000000..9b4900acc5 --- /dev/null +++ b/actionpack/test/fixtures/test/render_file_with_locals_and_default.erb @@ -0,0 +1 @@ +<%= secret ||= 'one' %>
\ No newline at end of file diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb index 4c82b75cdc..5be8533293 100644 --- a/actionpack/test/template/body_parts_test.rb +++ b/actionpack/test/template/body_parts_test.rb @@ -6,7 +6,7 @@ class BodyPartsTest < ActionController::TestCase class TestController < ActionController::Base def index RENDERINGS.each do |rendering| - response.template.punctuate_body! rendering + @template.punctuate_body! rendering end @performed_render = true end diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index c75e29ed9a..b29b03f99d 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -5,37 +5,13 @@ class CompiledTemplatesTest < Test::Unit::TestCase def setup @compiled_templates = ActionView::Base::CompiledTemplates @compiled_templates.instance_methods.each do |m| - @compiled_templates.send(:remove_method, m) if m =~ /^_run_/ + @compiled_templates.send(:remove_method, m) if m =~ /^_render_template_/ end end - - def test_template_gets_compiled - assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - assert_equal 1, @compiled_templates.instance_methods.size - end - + def test_template_gets_recompiled_when_using_different_keys_in_local_assigns - assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - assert_equal "Hello world!", render(:file => "test/hello_world.erb", :locals => {:foo => "bar"}) - assert_equal 2, @compiled_templates.instance_methods.size - end - - def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_local_assigns - assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - ActionView::Template.any_instance.expects(:compile!).never - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - end - - def test_compiled_template_will_always_be_recompiled_when_template_is_not_cached - ActionView::Template.any_instance.expects(:recompile?).times(3).returns(true) - assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") - ActionView::Template.any_instance.expects(:compile!).times(3) - 3.times { assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } - assert_equal 1, @compiled_templates.instance_methods.size + assert_equal "one", render(:file => "test/render_file_with_locals_and_default.erb") + assert_equal "two", render(:file => "test/render_file_with_locals_and_default.erb", :locals => { :secret => "two" }) end def test_template_changes_are_not_reflected_with_cached_templates @@ -61,14 +37,12 @@ class CompiledTemplatesTest < Test::Unit::TestCase def render_with_cache(*args) view_paths = ActionController::Base.view_paths - assert_equal ActionView::Template::FileSystemPath, view_paths.first.class ActionView::Base.new(view_paths, {}).render(*args) end def render_without_cache(*args) - path = ActionView::Template::FileSystemPath.new(FIXTURE_LOAD_PATH) + path = ActionView::Template::FileSystemPathWithFallback.new(FIXTURE_LOAD_PATH) view_paths = ActionView::Base.process_view_paths(path) - assert_equal ActionView::Template::FileSystemPath, view_paths.first.class ActionView::Base.new(view_paths, {}).render(*args) end diff --git a/actionpack/test/template/output_buffer_test.rb b/actionpack/test/template/output_buffer_test.rb index 6d8eab63dc..bc17f36783 100644 --- a/actionpack/test/template/output_buffer_test.rb +++ b/actionpack/test/template/output_buffer_test.rb @@ -13,23 +13,23 @@ class OutputBufferTest < ActionController::TestCase # Start with the default body parts get :index assert_equal ['foo'], @response.body_parts - assert_nil @response.template.output_buffer + assert_nil @controller.template.output_buffer # Nil output buffer is skipped - @response.template.flush_output_buffer - assert_nil @response.template.output_buffer + @controller.template.flush_output_buffer + assert_nil @controller.template.output_buffer assert_equal ['foo'], @response.body_parts # Empty output buffer is skipped - @response.template.output_buffer = '' - @response.template.flush_output_buffer - assert_equal '', @response.template.output_buffer + @controller.template.output_buffer = '' + @controller.template.flush_output_buffer + assert_equal '', @controller.template.output_buffer assert_equal ['foo'], @response.body_parts # Flushing appends the output buffer to the body parts - @response.template.output_buffer = 'bar' - @response.template.flush_output_buffer - assert_equal '', @response.template.output_buffer + @controller.template.output_buffer = 'bar' + @controller.template.flush_output_buffer + assert_equal '', @controller.template.output_buffer assert_equal ['foo', 'bar'], @response.body_parts end end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 7191df0dfd..71291f009c 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -91,10 +91,6 @@ module RenderTestCases assert_equal "The secret is in the sauce\n", @view.render(:file => "test/dot.directory/render_file_with_ivar") end - def test_render_has_access_current_template - assert_equal "test/template.erb", @view.render(:file => "test/template.erb") - end - def test_render_update # TODO: You should not have to stub out template because template is self! @view.instance_variable_set(:@template, @view) @@ -240,10 +236,6 @@ module RenderTestCases end end - def test_template_with_malformed_template_handler_is_reachable_through_its_exact_filename - assert_equal "Don't render me!", @view.render(:file => 'test/malformed/malformed.html.erb~') - end - def test_render_with_layout assert_equal %(<title></title>\nHello world!\n), @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield") @@ -269,7 +261,7 @@ class CachedViewRenderTest < ActiveSupport::TestCase # Ensure view path cache is primed def setup view_paths = ActionController::Base.view_paths - assert_equal ActionView::Template::FileSystemPath, view_paths.first.class + assert_equal ActionView::Template::FileSystemPathWithFallback, view_paths.first.class setup_view(view_paths) end end @@ -280,9 +272,9 @@ class LazyViewRenderTest < ActiveSupport::TestCase # Test the same thing as above, but make sure the view path # is not eager loaded def setup - path = ActionView::Template::FileSystemPath.new(FIXTURE_LOAD_PATH) + path = ActionView::Template::FileSystemPathWithFallback.new(FIXTURE_LOAD_PATH) view_paths = ActionView::Base.process_view_paths(path) - assert_equal ActionView::Template::FileSystemPath, view_paths.first.class + assert_equal ActionView::Template::FileSystemPathWithFallback, view_paths.first.class setup_view(view_paths) end end |