From 422292dc98cf42b20758025bf55b5b84260aecb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Emin=20=C4=B0NA=C3=87?= Date: Wed, 17 Jun 2015 00:58:50 +0300 Subject: Document, refactor and create test case for ActionDispatch::Response#charset= method --- actionpack/test/dispatch/response_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 7aca251066..f7e7241382 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -42,6 +42,13 @@ class ResponseTest < ActiveSupport::TestCase assert_equal Encoding::UTF_8, response.body.encoding end + def test_response_charset_writer + @response.charset = 'utf-16' + assert_equal 'utf-16', @response.charset + @response.charset = nil + assert_equal 'utf-8', @response.charset + end + test "simple output" do @response.body = "Hello, World!" -- cgit v1.2.3 From 284a9ba8ecbbaac598179af6fc65aed7bcf5785b Mon Sep 17 00:00:00 2001 From: Jerry D'Antonio Date: Mon, 13 Jul 2015 14:22:54 -0400 Subject: Replaced `ActiveSupport::Concurrency::Latch` with concurrent-ruby. The concurrent-ruby gem is a toolset containing many concurrency utilities. Many of these utilities include runtime-specific optimizations when possible. Rather than clutter the Rails codebase with concurrency utilities separate from the core task, such tools can be superseded by similar tools in the more specialized gem. This commit replaces `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch`, which is functionally equivalent. --- actionpack/test/controller/live_stream_test.rb | 28 +++++++++++++------------- actionpack/test/dispatch/live_response_test.rb | 14 ++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/live_stream_test.rb b/actionpack/test/controller/live_stream_test.rb index 0c65270ec1..6161e3f47a 100644 --- a/actionpack/test/controller/live_stream_test.rb +++ b/actionpack/test/controller/live_stream_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/concurrency/latch' +require 'concurrent/atomics' Thread.abort_on_exception = true module ActionController @@ -145,7 +145,7 @@ module ActionController response.headers['Content-Type'] = 'text/event-stream' %w{ hello world }.each do |word| response.stream.write word - latch.await + latch.wait end response.stream.close end @@ -212,7 +212,7 @@ module ActionController # .. plus one more, because the #each frees up a slot: response.stream.write '.' - latch.release + latch.count_down # This write will block, and eventually raise response.stream.write 'x' @@ -233,7 +233,7 @@ module ActionController end logger.info 'Work complete' - latch.release + latch.count_down end end @@ -278,7 +278,7 @@ module ActionController def test_async_stream rubinius_skip "https://github.com/rubinius/rubinius/issues/2934" - @controller.latch = ActiveSupport::Concurrency::Latch.new + @controller.latch = Concurrent::CountDownLatch.new parts = ['hello', 'world'] @controller.request = @request @@ -289,8 +289,8 @@ module ActionController resp.stream.each do |part| assert_equal parts.shift, part ol = @controller.latch - @controller.latch = ActiveSupport::Concurrency::Latch.new - ol.release + @controller.latch = Concurrent::CountDownLatch.new + ol.count_down end } @@ -300,23 +300,23 @@ module ActionController end def test_abort_with_full_buffer - @controller.latch = ActiveSupport::Concurrency::Latch.new + @controller.latch = Concurrent::CountDownLatch.new @request.parameters[:format] = 'plain' @controller.request = @request @controller.response = @response - got_error = ActiveSupport::Concurrency::Latch.new + got_error = Concurrent::CountDownLatch.new @response.stream.on_error do ActionController::Base.logger.warn 'Error while streaming' - got_error.release + got_error.count_down end t = Thread.new(@response) { |resp| resp.await_commit _, _, body = resp.to_a body.each do |part| - @controller.latch.await + @controller.latch.wait body.close break end @@ -325,13 +325,13 @@ module ActionController capture_log_output do |output| @controller.process :overfill_buffer_and_die t.join - got_error.await + got_error.wait assert_match 'Error while streaming', output.rewind && output.read end end def test_ignore_client_disconnect - @controller.latch = ActiveSupport::Concurrency::Latch.new + @controller.latch = Concurrent::CountDownLatch.new @controller.request = @request @controller.response = @response @@ -349,7 +349,7 @@ module ActionController @controller.process :ignore_client_disconnect t.join Timeout.timeout(3) do - @controller.latch.await + @controller.latch.wait end assert_match 'Work complete', output.rewind && output.read end diff --git a/actionpack/test/dispatch/live_response_test.rb b/actionpack/test/dispatch/live_response_test.rb index 512f3a8a7a..5cfa5f7b3b 100644 --- a/actionpack/test/dispatch/live_response_test.rb +++ b/actionpack/test/dispatch/live_response_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/concurrency/latch' +require 'concurrent/atomics' module ActionController module Live @@ -27,18 +27,18 @@ module ActionController end def test_parallel - latch = ActiveSupport::Concurrency::Latch.new + latch = Concurrent::CountDownLatch.new t = Thread.new { @response.stream.write 'foo' - latch.await + latch.wait @response.stream.close } @response.await_commit @response.each do |part| assert_equal 'foo', part - latch.release + latch.count_down end assert t.join end @@ -62,15 +62,15 @@ module ActionController def test_headers_cannot_be_written_after_webserver_reads @response.stream.write 'omg' - latch = ActiveSupport::Concurrency::Latch.new + latch = Concurrent::CountDownLatch.new t = Thread.new { @response.stream.each do |chunk| - latch.release + latch.count_down end } - latch.await + latch.wait assert @response.headers.frozen? e = assert_raises(ActionDispatch::IllegalStateError) do @response.headers['Content-Length'] = "zomg" -- cgit v1.2.3 From d9fe10cb8ab05f6575a06f14991cd938052227dd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 13 Jul 2015 17:52:02 -0700 Subject: only have one TestResponse class --- actionpack/test/controller/action_pack_assertions_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 5b85e83045..017b309af4 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -351,7 +351,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase def test_response_object process :nothing - assert_kind_of ActionController::TestResponse, @response + assert_kind_of ActionDispatch::TestResponse, @response end def test_render_based_on_parameters -- cgit v1.2.3 From 908bc79729fdb3cc2acbd346d9ed34c9286d57cc Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 13 Jul 2015 18:10:36 -0700 Subject: use a lookup table for `assert_response` We shouldn't depend on specific methods imlemented in the TestResponse subclass because the response could actually be a real response object. In the future, we should either push the aliased predicate methods in TestResponse up to the real response object, or remove them --- actionpack/test/assertions/response_assertions_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/assertions/response_assertions_test.rb b/actionpack/test/assertions/response_assertions_test.rb index 5e64cae7e2..82c747680d 100644 --- a/actionpack/test/assertions/response_assertions_test.rb +++ b/actionpack/test/assertions/response_assertions_test.rb @@ -7,7 +7,7 @@ module ActionDispatch include ResponseAssertions FakeResponse = Struct.new(:response_code) do - [:success, :missing, :redirect, :error].each do |sym| + [:successful, :not_found, :redirection, :server_error].each do |sym| define_method("#{sym}?") do sym == response_code end @@ -16,7 +16,7 @@ module ActionDispatch def test_assert_response_predicate_methods [:success, :missing, :redirect, :error].each do |sym| - @response = FakeResponse.new sym + @response = FakeResponse.new RESPONSE_PREDICATES[sym].to_s.sub(/\?/, '').to_sym assert_response sym assert_raises(Minitest::Assertion) { -- cgit v1.2.3 From e26d11c876d11bae09b95df941d14e21ac93e2f0 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Tue, 14 Jul 2015 09:27:42 -0400 Subject: Change AC::TestResponse to AD::TestResponse ActionController::TestResponse was removed in d9fe10c and caused a test failure on Action View as its test case still refers to it. --- actionpack/test/controller/helper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index a96cfa3bf4..3ecfedefd1 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -151,7 +151,7 @@ class HelperTest < ActiveSupport::TestCase assert_equal "test: baz", call_controller(Fun::PdfController, "test").last.body # # request = ActionController::TestRequest.new - # response = ActionController::TestResponse.new + # response = ActionDispatch::TestResponse.new # request.action = 'test' # # assert_equal 'test: baz', Fun::PdfController.process(request, response).body -- cgit v1.2.3 From 9cff2484695243248abcaa9ec1c5b246f1c28209 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 14 Jul 2015 07:46:06 -0700 Subject: only call methods that are on the superclass We want to treat the response object as if it's a real response object (not a test object), so we should only call methods that are on the superclass. --- actionpack/test/controller/action_pack_assertions_test.rb | 4 ++-- actionpack/test/controller/filters_test.rb | 2 +- actionpack/test/dispatch/test_response_test.rb | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 017b309af4..ba8a02916b 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -318,7 +318,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase def test_missing_response_code process :response404 - assert @response.missing? + assert @response.not_found? end def test_client_error_response_code @@ -346,7 +346,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase def test_successful_response_code process :nothing - assert @response.success? + assert @response.successful? end def test_response_object diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 8a6a51c263..958097b56d 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -819,7 +819,7 @@ class FilterTest < ActionController::TestCase response = test_process(RescuedController) end - assert response.success? + assert response.successful? assert_equal("I rescued this: #", response.body) end diff --git a/actionpack/test/dispatch/test_response_test.rb b/actionpack/test/dispatch/test_response_test.rb index dc17668def..a4f9d56a6a 100644 --- a/actionpack/test/dispatch/test_response_test.rb +++ b/actionpack/test/dispatch/test_response_test.rb @@ -11,10 +11,9 @@ class TestResponseTest < ActiveSupport::TestCase end test "helpers" do - assert_response_code_range 200..299, :success? - assert_response_code_range [404], :missing? - assert_response_code_range 300..399, :redirect? - assert_response_code_range 500..599, :error? + assert_response_code_range 200..299, :successful? + assert_response_code_range [404], :not_found? + assert_response_code_range 300..399, :redirection? assert_response_code_range 500..599, :server_error? assert_response_code_range 400..499, :client_error? end -- cgit v1.2.3 From 14a3bd520dd4bbf1247fd3e0071b59c02c115ce0 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 13 Jul 2015 16:43:21 -0400 Subject: Make AC::Parameters not inherited from Hash This is another take at #14384 as we decided to wait until `master` is targeting Rails 5.0. This commit is implementation-complete, as it guarantees that all the public methods on the hash-inherited Parameters are still working (based on test case). We can decide to follow-up later if we want to remove some methods out from Parameters. --- actionpack/test/controller/api/params_wrapper_test.rb | 2 +- actionpack/test/controller/parameters/nested_parameters_test.rb | 2 +- actionpack/test/controller/parameters/parameters_permit_test.rb | 2 -- actionpack/test/controller/test_case_test.rb | 2 +- actionpack/test/controller/webservice_test.rb | 8 +++++++- actionpack/test/dispatch/request/json_params_parsing_test.rb | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/api/params_wrapper_test.rb b/actionpack/test/controller/api/params_wrapper_test.rb index e40a39d829..53b3a0c3cc 100644 --- a/actionpack/test/controller/api/params_wrapper_test.rb +++ b/actionpack/test/controller/api/params_wrapper_test.rb @@ -7,7 +7,7 @@ class ParamsWrapperForApiTest < ActionController::TestCase wrap_parameters :person, format: [:json] def test - self.last_parameters = params.except(:controller, :action) + self.last_parameters = params.except(:controller, :action).to_unsafe_h head :ok end end diff --git a/actionpack/test/controller/parameters/nested_parameters_test.rb b/actionpack/test/controller/parameters/nested_parameters_test.rb index 3b1257e8d5..7151a8567c 100644 --- a/actionpack/test/controller/parameters/nested_parameters_test.rb +++ b/actionpack/test/controller/parameters/nested_parameters_test.rb @@ -136,7 +136,7 @@ class NestedParametersTest < ActiveSupport::TestCase authors_attributes: { :'0' => { name: 'William Shakespeare', age_of_death: '52' }, :'1' => { name: 'Unattributed Assistant' }, - :'2' => { name: %w(injected names)} + :'2' => { name: %w(injected names) } } } }) diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index 2ed486516d..05532ec21b 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -253,7 +253,6 @@ class ParametersPermitTest < ActiveSupport::TestCase assert @params.to_h.is_a? Hash assert_not @params.to_h.is_a? ActionController::Parameters - assert_equal @params.to_hash, @params.to_h end test "to_h returns converted hash when .permit_all_parameters is set" do @@ -284,6 +283,5 @@ class ParametersPermitTest < ActiveSupport::TestCase test "to_unsafe_h returns unfiltered params" do assert @params.to_h.is_a? Hash assert_not @params.to_h.is_a? ActionController::Parameters - assert_equal @params.to_hash, @params.to_unsafe_h end end diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index b991232a14..0a20b2c3fb 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -45,7 +45,7 @@ class TestCaseTest < ActionController::TestCase end def test_params - render text: ::JSON.dump(params) + render text: ::JSON.dump(params.to_unsafe_h) end def test_query_parameters diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb index 21fa670bb6..bd81846a7d 100644 --- a/actionpack/test/controller/webservice_test.rb +++ b/actionpack/test/controller/webservice_test.rb @@ -14,7 +14,13 @@ class WebServiceTest < ActionDispatch::IntegrationTest def dump_params_keys(hash = params) hash.keys.sort.inject("") do |s, k| value = hash[k] - value = Hash === value ? "(#{dump_params_keys(value)})" : "" + + if value.is_a?(Hash) || value.is_a?(ActionController::Parameters) + value = "(#{dump_params_keys(value)})" + else + value = "" + end + s << ", " unless s.empty? s << "#{k}#{value}" end diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index d77341bc64..c2300a0142 100644 --- a/actionpack/test/dispatch/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb @@ -113,7 +113,7 @@ class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest def parse self.class.last_request_parameters = request.request_parameters - self.class.last_parameters = params + self.class.last_parameters = params.to_unsafe_h head :ok end end -- cgit v1.2.3 From ae1b96cfcd0d47afa8d50a1a055a22d375c21fd4 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Fri, 17 Jul 2015 15:00:00 +0200 Subject: Skip a few failing tests on JRuby with the attached tickets --- actionpack/test/controller/parameters/mutators_test.rb | 4 ++++ actionpack/test/dispatch/response_test.rb | 2 ++ actionpack/test/dispatch/routing/concerns_test.rb | 2 ++ 3 files changed, 8 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/parameters/mutators_test.rb b/actionpack/test/controller/parameters/mutators_test.rb index 744d8664be..6c57c4caeb 100644 --- a/actionpack/test/controller/parameters/mutators_test.rb +++ b/actionpack/test/controller/parameters/mutators_test.rb @@ -62,11 +62,15 @@ class ParametersMutatorsTest < ActiveSupport::TestCase end test "select! retains permitted status" do + jruby_skip "https://github.com/jruby/jruby/issues/3137" + @params.permit! assert @params.select! { |k| k != "person" }.permitted? end test "select! retains unpermitted status" do + jruby_skip "https://github.com/jruby/jruby/issues/3137" + assert_not @params.select! { |k| k != "person" }.permitted? end diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 7aca251066..5aa0215e8f 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -171,6 +171,8 @@ class ResponseTest < ActiveSupport::TestCase end test "read content type without charset" do + jruby_skip "https://github.com/jruby/jruby/issues/3138" + original = ActionDispatch::Response.default_charset begin ActionDispatch::Response.default_charset = 'utf-16' diff --git a/actionpack/test/dispatch/routing/concerns_test.rb b/actionpack/test/dispatch/routing/concerns_test.rb index 7ef513b0c8..361ceca677 100644 --- a/actionpack/test/dispatch/routing/concerns_test.rb +++ b/actionpack/test/dispatch/routing/concerns_test.rb @@ -109,6 +109,8 @@ class RoutingConcernsTest < ActionDispatch::IntegrationTest end def test_concerns_executes_block_in_context_of_current_mapper + jruby_skip "https://github.com/jruby/jruby/issues/3143" + mapper = ActionDispatch::Routing::Mapper.new(ActionDispatch::Routing::RouteSet.new) mapper.concern :test_concern do resources :things -- cgit v1.2.3 From 6790228b39dd070b93054c463162de28f67d3ccc Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Sun, 23 Mar 2014 20:16:07 -0400 Subject: Add deprecation warning for `render :text` We've started on discouraging the usage of `render :text` in #12374. This is a follow-up commit to make sure that we print out the deprecation warning. --- .../test/controller/new_base/render_text_test.rb | 53 +++++++++++++++++----- 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/new_base/render_text_test.rb b/actionpack/test/controller/new_base/render_text_test.rb index 10bad57cd6..435bb18dce 100644 --- a/actionpack/test/controller/new_base/render_text_test.rb +++ b/actionpack/test/controller/new_base/render_text_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/deprecation' module RenderText class MinimalController < ActionController::Metal @@ -73,7 +74,10 @@ module RenderText class RenderTextTest < Rack::TestCase test "rendering text from a minimal controller" do - get "/render_text/minimal/index" + ActiveSupport::Deprecation.silence do + get "/render_text/minimal/index" + end + assert_body "Hello World!" assert_status 200 end @@ -82,7 +86,10 @@ module RenderText with_routing do |set| set.draw { get ':controller', action: 'index' } - get "/render_text/simple" + ActiveSupport::Deprecation.silence do + get "/render_text/simple" + end + assert_body "hello david" assert_status 200 end @@ -92,7 +99,9 @@ module RenderText with_routing do |set| set.draw { get ':controller', action: 'index' } - get "/render_text/with_layout" + ActiveSupport::Deprecation.silence do + get "/render_text/with_layout" + end assert_body "hello david" assert_status 200 @@ -100,59 +109,81 @@ module RenderText end test "rendering text, while also providing a custom status code" do - get "/render_text/with_layout/custom_code" + ActiveSupport::Deprecation.silence do + get "/render_text/with_layout/custom_code" + end assert_body "hello world" assert_status 404 end test "rendering text with nil returns an empty body" do - get "/render_text/with_layout/with_nil" + ActiveSupport::Deprecation.silence do + get "/render_text/with_layout/with_nil" + end assert_body "" assert_status 200 end test "Rendering text with nil and custom status code returns an empty body and the status" do - get "/render_text/with_layout/with_nil_and_status" + ActiveSupport::Deprecation.silence do + get "/render_text/with_layout/with_nil_and_status" + end assert_body "" assert_status 403 end test "rendering text with false returns the string 'false'" do - get "/render_text/with_layout/with_false" + ActiveSupport::Deprecation.silence do + get "/render_text/with_layout/with_false" + end assert_body "false" assert_status 200 end test "rendering text with layout: true" do - get "/render_text/with_layout/with_layout_true" + ActiveSupport::Deprecation.silence do + get "/render_text/with_layout/with_layout_true" + end assert_body "hello world, I'm here!" assert_status 200 end test "rendering text with layout: 'greetings'" do - get "/render_text/with_layout/with_custom_layout" + ActiveSupport::Deprecation.silence do + get "/render_text/with_layout/with_custom_layout" + end assert_body "hello world, I wish thee well." assert_status 200 end test "rendering text with layout: false" do - get "/render_text/with_layout/with_layout_false" + ActiveSupport::Deprecation.silence do + get "/render_text/with_layout/with_layout_false" + end assert_body "hello world" assert_status 200 end test "rendering text with layout: nil" do - get "/render_text/with_layout/with_layout_nil" + ActiveSupport::Deprecation.silence do + get "/render_text/with_layout/with_layout_nil" + end assert_body "hello world" assert_status 200 end + + test "rendering text displays deprecation warning" do + assert_deprecated do + get "/render_text/with_layout/with_layout_nil" + end + end end end -- cgit v1.2.3 From 8cb8ce98d903929342e2ca3a54a07ab5196baf93 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 17 Jul 2015 21:48:00 -0400 Subject: Stop using deprecated `render :text` in test This will silence deprecation warnings. Most of the test can be changed from `render :text` to render `:plain` or `render :body` right away. However, there are some tests that needed to be fixed by hand as they actually assert the default Content-Type returned from `render :body`. --- .../test/controller/action_pack_assertions_test.rb | 18 ++-- .../test/controller/api/conditional_get_test.rb | 4 +- actionpack/test/controller/base_test.rb | 2 +- actionpack/test/controller/content_type_test.rb | 26 +++--- .../default_url_options_with_before_action_test.rb | 2 +- actionpack/test/controller/filters_test.rb | 26 +++--- actionpack/test/controller/force_ssl_test.rb | 16 ++-- .../controller/http_basic_authentication_test.rb | 8 +- .../controller/http_digest_authentication_test.rb | 4 +- .../controller/http_token_authentication_test.rb | 6 +- actionpack/test/controller/integration_test.rb | 26 +++--- actionpack/test/controller/live_stream_test.rb | 4 +- actionpack/test/controller/mime/respond_to_test.rb | 104 ++++++++++----------- actionpack/test/controller/new_base/base_test.rb | 6 +- .../new_base/content_negotiation_test.rb | 2 +- .../test/controller/new_base/content_type_test.rb | 18 ++-- actionpack/test/controller/new_base/render_test.rb | 6 +- .../test/controller/permitted_params_test.rb | 4 +- actionpack/test/controller/redirect_test.rb | 4 +- actionpack/test/controller/render_json_test.rb | 2 +- actionpack/test/controller/render_test.rb | 8 +- .../controller/request_forgery_protection_test.rb | 2 +- actionpack/test/controller/rescue_test.rb | 18 ++-- actionpack/test/controller/test_case_test.rb | 52 +++++------ actionpack/test/controller/webservice_test.rb | 4 +- actionpack/test/dispatch/prefix_generation_test.rb | 24 ++--- .../request/multipart_params_parsing_test.rb | 2 +- actionpack/test/dispatch/routing_test.rb | 12 +-- .../test/dispatch/session/cache_store_test.rb | 4 +- .../test/dispatch/session/cookie_store_test.rb | 10 +- .../test/dispatch/session/mem_cache_store_test.rb | 4 +- actionpack/test/dispatch/url_generation_test.rb | 2 +- 32 files changed, 215 insertions(+), 215 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index ba8a02916b..beeafc2e53 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -43,12 +43,12 @@ class ActionPackAssertionsController < ActionController::Base def flash_me flash['hello'] = 'my name is inigo montoya...' - render :text => "Inconceivable!" + render plain: "Inconceivable!" end def flash_me_naked flash.clear - render :text => "wow!" + render plain: "wow!" end def assign_this @@ -57,30 +57,30 @@ class ActionPackAssertionsController < ActionController::Base end def render_based_on_parameters - render :text => "Mr. #{params[:name]}" + render plain: "Mr. #{params[:name]}" end def render_url - render :text => "
#{url_for(:action => 'flash_me', :only_path => true)}
" + render html: "
#{url_for(action: 'flash_me', only_path: true)}
" end def render_text_with_custom_content_type - render :text => "Hello!", :content_type => Mime::RSS + render body: "Hello!", content_type: Mime::RSS end def session_stuffing session['xmas'] = 'turkey' - render :text => "ho ho ho" + render plain: "ho ho ho" end def raise_exception_on_get raise "get" if request.get? - render :text => "request method: #{request.env['REQUEST_METHOD']}" + render plain: "request method: #{request.env['REQUEST_METHOD']}" end def raise_exception_on_post raise "post" if request.post? - render :text => "request method: #{request.env['REQUEST_METHOD']}" + render plain: "request method: #{request.env['REQUEST_METHOD']}" end def render_file_absolute_path @@ -101,7 +101,7 @@ class AssertResponseWithUnexpectedErrorController < ActionController::Base end def show - render :text => "Boom", :status => 500 + render plain: "Boom", status: 500 end end diff --git a/actionpack/test/controller/api/conditional_get_test.rb b/actionpack/test/controller/api/conditional_get_test.rb index d1eb27bf24..b4f1673be0 100644 --- a/actionpack/test/controller/api/conditional_get_test.rb +++ b/actionpack/test/controller/api/conditional_get_test.rb @@ -7,12 +7,12 @@ class ConditionalGetApiController < ActionController::API def one if stale?(last_modified: Time.now.utc.beginning_of_day, etag: [:foo, 123]) - render text: "Hi!" + render plain: "Hi!" end end def two - render text: "Hi!" + render plain: "Hi!" end private diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index b7fe253de7..d9374ce9c3 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -53,7 +53,7 @@ end class ActionMissingController < ActionController::Base def action_missing(action) - render :text => "Response for #{action}" + render plain: "Response for #{action}" end end diff --git a/actionpack/test/controller/content_type_test.rb b/actionpack/test/controller/content_type_test.rb index 89667df3a4..c5bbc479c9 100644 --- a/actionpack/test/controller/content_type_test.rb +++ b/actionpack/test/controller/content_type_test.rb @@ -4,29 +4,29 @@ class OldContentTypeController < ActionController::Base # :ported: def render_content_type_from_body response.content_type = Mime::RSS - render :text => "hello world!" + render body: "hello world!" end # :ported: def render_defaults - render :text => "hello world!" + render body: "hello world!" end # :ported: def render_content_type_from_render - render :text => "hello world!", :content_type => Mime::RSS + render body: "hello world!", :content_type => Mime::RSS end # :ported: def render_charset_from_body response.charset = "utf-16" - render :text => "hello world!" + render body: "hello world!" end # :ported: def render_nil_charset_from_body response.charset = nil - render :text => "hello world!" + render body: "hello world!" end def render_default_for_erb @@ -42,10 +42,10 @@ class OldContentTypeController < ActionController::Base def render_default_content_types_for_respond_to respond_to do |format| - format.html { render :text => "hello world!" } - format.xml { render :action => "render_default_content_types_for_respond_to" } - format.js { render :text => "hello world!" } - format.rss { render :text => "hello world!", :content_type => Mime::XML } + format.html { render body: "hello world!" } + format.xml { render action: "render_default_content_types_for_respond_to" } + format.js { render body: "hello world!" } + format.rss { render body: "hello world!", content_type: Mime::XML } end end end @@ -64,14 +64,14 @@ class ContentTypeTest < ActionController::TestCase def test_render_defaults get :render_defaults assert_equal "utf-8", @response.charset - assert_equal Mime::HTML, @response.content_type + assert_equal Mime::TEXT, @response.content_type end def test_render_changed_charset_default with_default_charset "utf-16" do get :render_defaults assert_equal "utf-16", @response.charset - assert_equal Mime::HTML, @response.content_type + assert_equal Mime::TEXT, @response.content_type end end @@ -92,14 +92,14 @@ class ContentTypeTest < ActionController::TestCase # :ported: def test_charset_from_body get :render_charset_from_body - assert_equal Mime::HTML, @response.content_type + assert_equal Mime::TEXT, @response.content_type assert_equal "utf-16", @response.charset end # :ported: def test_nil_charset_from_body get :render_nil_charset_from_body - assert_equal Mime::HTML, @response.content_type + assert_equal Mime::TEXT, @response.content_type assert_equal "utf-8", @response.charset, @response.headers.inspect end diff --git a/actionpack/test/controller/default_url_options_with_before_action_test.rb b/actionpack/test/controller/default_url_options_with_before_action_test.rb index 230f40d7ad..12fbe0424e 100644 --- a/actionpack/test/controller/default_url_options_with_before_action_test.rb +++ b/actionpack/test/controller/default_url_options_with_before_action_test.rb @@ -6,7 +6,7 @@ class ControllerWithBeforeActionAndDefaultUrlOptions < ActionController::Base after_action { I18n.locale = "en" } def target - render :text => "final response" + render plain: "final response" end def redirect diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 958097b56d..08271012e9 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -40,7 +40,7 @@ class FilterTest < ActionController::TestCase before_action :ensure_login, :except => [:go_wild] def go_wild - render :text => "gobble" + render plain: "gobble" end end @@ -51,7 +51,7 @@ class FilterTest < ActionController::TestCase (1..3).each do |i| define_method "fail_#{i}" do - render :text => i.to_s + render plain: i.to_s end end @@ -222,7 +222,7 @@ class FilterTest < ActionController::TestCase skip_before_action :clean_up_tmp, only: :login, if: -> { true } def login - render text: 'ok' + render plain: 'ok' end end @@ -234,7 +234,7 @@ class FilterTest < ActionController::TestCase skip_before_action :clean_up_tmp, if: -> { true }, except: :login def login - render text: 'ok' + render plain: 'ok' end end @@ -258,11 +258,11 @@ class FilterTest < ActionController::TestCase before_action :ensure_login, :only => :index def index - render :text => 'ok' + render plain: 'ok' end def public - render :text => 'ok' + render plain: 'ok' end end @@ -272,7 +272,7 @@ class FilterTest < ActionController::TestCase before_action :ensure_login def index - render :text => 'ok' + render plain: 'ok' end private @@ -383,7 +383,7 @@ class FilterTest < ActionController::TestCase before_action(AuditFilter) def show - render :text => "hello" + render plain: "hello" end end @@ -421,11 +421,11 @@ class FilterTest < ActionController::TestCase before_action :second, :only => :foo def foo - render :text => 'foo' + render plain: 'foo' end def bar - render :text => 'bar' + render plain: 'bar' end protected @@ -442,7 +442,7 @@ class FilterTest < ActionController::TestCase before_action :choose %w(foo bar baz).each do |action| - define_method(action) { render :text => action } + define_method(action) { render plain: action } end private @@ -471,7 +471,7 @@ class FilterTest < ActionController::TestCase @ran_filter << 'between_before_all_and_after_all' end def show - render :text => 'hello' + render plain: 'hello' end end @@ -481,7 +481,7 @@ class FilterTest < ActionController::TestCase def around(controller) yield rescue ErrorToRescue => ex - controller.__send__ :render, :text => "I rescued this: #{ex.inspect}" + controller.__send__ :render, plain: "I rescued this: #{ex.inspect}" end end diff --git a/actionpack/test/controller/force_ssl_test.rb b/actionpack/test/controller/force_ssl_test.rb index 72ae30eb39..22f1cc7c22 100644 --- a/actionpack/test/controller/force_ssl_test.rb +++ b/actionpack/test/controller/force_ssl_test.rb @@ -2,11 +2,11 @@ require 'abstract_unit' class ForceSSLController < ActionController::Base def banana - render :text => "monkey" + render plain: "monkey" end def cheeseburger - render :text => "sikachu" + render plain: "sikachu" end end @@ -26,7 +26,7 @@ class ForceSSLCustomOptions < ForceSSLController force_ssl :notice => 'Foo, Bar!', :only => :redirect_notice def force_ssl_action - render :text => action_name + render plain: action_name end alias_method :redirect_host, :force_ssl_action @@ -40,15 +40,15 @@ class ForceSSLCustomOptions < ForceSSLController alias_method :redirect_notice, :force_ssl_action def use_flash - render :text => flash[:message] + render plain: flash[:message] end def use_alert - render :text => flash[:alert] + render plain: flash[:alert] end def use_notice - render :text => flash[:notice] + render plain: flash[:notice] end end @@ -85,10 +85,10 @@ end class RedirectToSSL < ForceSSLController def banana - force_ssl_redirect || render(:text => 'monkey') + force_ssl_redirect || render(plain: 'monkey') end def cheeseburger - force_ssl_redirect('secure.cheeseburger.host') || render(:text => 'ihaz') + force_ssl_redirect('secure.cheeseburger.host') || render(plain: 'ihaz') end end diff --git a/actionpack/test/controller/http_basic_authentication_test.rb b/actionpack/test/controller/http_basic_authentication_test.rb index adaf19c2dc..ed3632007d 100644 --- a/actionpack/test/controller/http_basic_authentication_test.rb +++ b/actionpack/test/controller/http_basic_authentication_test.rb @@ -9,19 +9,19 @@ class HttpBasicAuthenticationTest < ActionController::TestCase http_basic_authenticate_with :name => "David", :password => "Goliath", :only => :search def index - render :text => "Hello Secret" + render plain: "Hello Secret" end def display - render :text => 'Definitely Maybe' if @logged_in + render plain: 'Definitely Maybe' if @logged_in end def show - render :text => 'Only for loooooong credentials' + render plain: 'Only for loooooong credentials' end def search - render :text => 'All inline' + render plain: 'All inline' end private diff --git a/actionpack/test/controller/http_digest_authentication_test.rb b/actionpack/test/controller/http_digest_authentication_test.rb index 57964769a7..f06912bd5a 100644 --- a/actionpack/test/controller/http_digest_authentication_test.rb +++ b/actionpack/test/controller/http_digest_authentication_test.rb @@ -10,11 +10,11 @@ class HttpDigestAuthenticationTest < ActionController::TestCase 'dhh' => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":"))} def index - render :text => "Hello Secret" + render plain: "Hello Secret" end def display - render :text => 'Definitely Maybe' if @logged_in + render plain: 'Definitely Maybe' if @logged_in end private diff --git a/actionpack/test/controller/http_token_authentication_test.rb b/actionpack/test/controller/http_token_authentication_test.rb index 802c17b6bf..9c5a01c318 100644 --- a/actionpack/test/controller/http_token_authentication_test.rb +++ b/actionpack/test/controller/http_token_authentication_test.rb @@ -7,15 +7,15 @@ class HttpTokenAuthenticationTest < ActionController::TestCase before_action :authenticate_long_credentials, only: :show def index - render :text => "Hello Secret" + render plain: "Hello Secret" end def display - render :text => 'Definitely Maybe' + render plain: 'Definitely Maybe' end def show - render :text => 'Only for loooooong credentials' + render plain: 'Only for loooooong credentials' end private diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index a6460168cb..0b9be8d671 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -359,28 +359,28 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest class IntegrationController < ActionController::Base def get respond_to do |format| - format.html { render :text => "OK", :status => 200 } - format.js { render :text => "JS OK", :status => 200 } + format.html { render plain: "OK", status: 200 } + format.js { render plain: "JS OK", status: 200 } format.xml { render :xml => "", :status => 200 } end end def get_with_params - render :text => "foo: #{params[:foo]}", :status => 200 + render plain: "foo: #{params[:foo]}", status: 200 end def post - render :text => "Created", :status => 201 + render plain: "Created", status: 201 end def method - render :text => "method: #{request.method.downcase}" + render plain: "method: #{request.method.downcase}" end def cookie_monster cookies["cookie_1"] = nil cookies["cookie_3"] = "chocolate" - render :text => "Gone", :status => 410 + render plain: "Gone", status: 410 end def set_cookie @@ -389,7 +389,7 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest end def get_cookie - render :text => cookies["foo"] + render plain: cookies["foo"] end def redirect @@ -760,7 +760,7 @@ end class ApplicationIntegrationTest < ActionDispatch::IntegrationTest class TestController < ActionController::Base def index - render :text => "index" + render plain: "index" end end @@ -847,7 +847,7 @@ end class EnvironmentFilterIntegrationTest < ActionDispatch::IntegrationTest class TestController < ActionController::Base def post - render :text => "Created", :status => 201 + render plain: "Created", status: 201 end end @@ -880,15 +880,15 @@ end class UrlOptionsIntegrationTest < ActionDispatch::IntegrationTest class FooController < ActionController::Base def index - render :text => "foo#index" + render plain: "foo#index" end def show - render :text => "foo#show" + render plain: "foo#show" end def edit - render :text => "foo#show" + render plain: "foo#show" end end @@ -898,7 +898,7 @@ class UrlOptionsIntegrationTest < ActionDispatch::IntegrationTest end def index - render :text => "foo#index" + render plain: "foo#index" end end diff --git a/actionpack/test/controller/live_stream_test.rb b/actionpack/test/controller/live_stream_test.rb index 6161e3f47a..6ba361f2f7 100644 --- a/actionpack/test/controller/live_stream_test.rb +++ b/actionpack/test/controller/live_stream_test.rb @@ -125,7 +125,7 @@ module ActionController end def render_text - render :text => 'zomg' + render plain: 'zomg' end def default_header @@ -162,7 +162,7 @@ module ActionController end def with_stale - render text: 'stale' if stale?(etag: "123", template: false) + render plain: 'stale' if stale?(etag: "123", template: false) end def exception_in_view diff --git a/actionpack/test/controller/mime/respond_to_test.rb b/actionpack/test/controller/mime/respond_to_test.rb index 71660c87a2..64eb33f78f 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -13,41 +13,41 @@ class RespondToController < ActionController::Base def html_xml_or_rss respond_to do |type| - type.html { render :text => "HTML" } - type.xml { render :text => "XML" } - type.rss { render :text => "RSS" } - type.all { render :text => "Nothing" } + type.html { render body: "HTML" } + type.xml { render body: "XML" } + type.rss { render body: "RSS" } + type.all { render body: "Nothing" } end end def js_or_html respond_to do |type| - type.html { render :text => "HTML" } - type.js { render :text => "JS" } - type.all { render :text => "Nothing" } + type.html { render body: "HTML" } + type.js { render body: "JS" } + type.all { render body: "Nothing" } end end def json_or_yaml respond_to do |type| - type.json { render :text => "JSON" } - type.yaml { render :text => "YAML" } + type.json { render body: "JSON" } + type.yaml { render body: "YAML" } end end def html_or_xml respond_to do |type| - type.html { render :text => "HTML" } - type.xml { render :text => "XML" } - type.all { render :text => "Nothing" } + type.html { render body: "HTML" } + type.xml { render body: "XML" } + type.all { render body: "Nothing" } end end def json_xml_or_html respond_to do |type| - type.json { render :text => 'JSON' } + type.json { render body: 'JSON' } type.xml { render :xml => 'XML' } - type.html { render :text => 'HTML' } + type.html { render body: 'HTML' } end end @@ -56,14 +56,14 @@ class RespondToController < ActionController::Base request.format = :xml respond_to do |type| - type.html { render :text => "HTML" } - type.xml { render :text => "XML" } + type.html { render body: "HTML" } + type.xml { render body: "XML" } end end def just_xml respond_to do |type| - type.xml { render :text => "XML" } + type.xml { render body: "XML" } end end @@ -81,52 +81,52 @@ class RespondToController < ActionController::Base def using_defaults_with_all respond_to do |type| type.html - type.all{ render text: "ALL" } + type.all{ render body: "ALL" } end end def made_for_content_type respond_to do |type| - type.rss { render :text => "RSS" } - type.atom { render :text => "ATOM" } - type.all { render :text => "Nothing" } + type.rss { render body: "RSS" } + type.atom { render body: "ATOM" } + type.all { render body: "Nothing" } end end def custom_type_handling respond_to do |type| - type.html { render :text => "HTML" } - type.custom("application/crazy-xml") { render :text => "Crazy XML" } - type.all { render :text => "Nothing" } + type.html { render body: "HTML" } + type.custom("application/crazy-xml") { render body: "Crazy XML" } + type.all { render body: "Nothing" } end end def custom_constant_handling respond_to do |type| - type.html { render :text => "HTML" } - type.mobile { render :text => "Mobile" } + type.html { render body: "HTML" } + type.mobile { render body: "Mobile" } end end def custom_constant_handling_without_block respond_to do |type| - type.html { render :text => "HTML" } + type.html { render body: "HTML" } type.mobile end end def handle_any respond_to do |type| - type.html { render :text => "HTML" } - type.any(:js, :xml) { render :text => "Either JS or XML" } + type.html { render body: "HTML" } + type.any(:js, :xml) { render body: "Either JS or XML" } end end def handle_any_any respond_to do |type| - type.html { render :text => 'HTML' } - type.any { render :text => 'Whatever you ask for, I got it' } + type.html { render body: 'HTML' } + type.any { render body: 'Whatever you ask for, I got it' } end end @@ -167,15 +167,15 @@ class RespondToController < ActionController::Base request.variant = :mobile respond_to do |type| - type.html { render text: "mobile" } + type.html { render body: "mobile" } end end def multiple_variants_for_format respond_to do |type| type.html do |html| - html.tablet { render text: "tablet" } - html.phone { render text: "phone" } + html.tablet { render body: "tablet" } + html.phone { render body: "phone" } end end end @@ -183,7 +183,7 @@ class RespondToController < ActionController::Base def variant_plus_none_for_format respond_to do |format| format.html do |variant| - variant.phone { render text: "phone" } + variant.phone { render body: "phone" } variant.none end end @@ -191,9 +191,9 @@ class RespondToController < ActionController::Base def variant_inline_syntax respond_to do |format| - format.js { render text: "js" } - format.html.none { render text: "none" } - format.html.phone { render text: "phone" } + format.js { render body: "js" } + format.html.none { render body: "none" } + format.html.phone { render body: "phone" } end end @@ -208,8 +208,8 @@ class RespondToController < ActionController::Base def variant_any respond_to do |format| format.html do |variant| - variant.any(:tablet, :phablet){ render text: "any" } - variant.phone { render text: "phone" } + variant.any(:tablet, :phablet){ render body: "any" } + variant.phone { render body: "phone" } end end end @@ -217,23 +217,23 @@ class RespondToController < ActionController::Base def variant_any_any respond_to do |format| format.html do |variant| - variant.any { render text: "any" } - variant.phone { render text: "phone" } + variant.any { render body: "any" } + variant.phone { render body: "phone" } end end end def variant_inline_any respond_to do |format| - format.html.any(:tablet, :phablet){ render text: "any" } - format.html.phone { render text: "phone" } + format.html.any(:tablet, :phablet){ render body: "any" } + format.html.phone { render body: "phone" } end end def variant_inline_any_any respond_to do |format| - format.html.phone { render text: "phone" } - format.html.any { render text: "any" } + format.html.phone { render body: "phone" } + format.html.any { render body: "any" } end end @@ -246,16 +246,16 @@ class RespondToController < ActionController::Base def variant_any_with_none respond_to do |format| - format.html.any(:none, :phone){ render text: "none or phone" } + format.html.any(:none, :phone){ render body: "none or phone" } end end def format_any_variant_any respond_to do |format| - format.html { render text: "HTML" } + format.html { render body: "HTML" } format.any(:js, :xml) do |variant| - variant.phone{ render text: "phone" } - variant.any(:tablet, :phablet){ render text: "tablet" } + variant.phone{ render body: "phone" } + variant.any(:tablet, :phablet){ render body: "tablet" } end end end @@ -780,7 +780,7 @@ end class RespondToWithBlockOnDefaultRenderController < ActionController::Base def show default_render do - render text: 'default_render yielded' + render body: 'default_render yielded' end end end @@ -794,6 +794,6 @@ class RespondToWithBlockOnDefaultRenderControllerTest < ActionController::TestCa def test_default_render_uses_block_when_no_template_exists get :show assert_equal "default_render yielded", @response.body - assert_equal "text/html", @response.content_type + assert_equal "text/plain", @response.content_type end end diff --git a/actionpack/test/controller/new_base/base_test.rb b/actionpack/test/controller/new_base/base_test.rb index 964f22eb03..0755dafe93 100644 --- a/actionpack/test/controller/new_base/base_test.rb +++ b/actionpack/test/controller/new_base/base_test.rb @@ -6,7 +6,7 @@ module Dispatching before_action :authenticate def index - render :text => "success" + render body: "success" end def modify_response_body @@ -22,7 +22,7 @@ module Dispatching end def show_actions - render :text => "actions: #{action_methods.to_a.sort.join(', ')}" + render body: "actions: #{action_methods.to_a.sort.join(', ')}" end protected @@ -51,7 +51,7 @@ module Dispatching assert_body "success" assert_status 200 - assert_content_type "text/html; charset=utf-8" + assert_content_type "text/plain; charset=utf-8" end # :api: plugin diff --git a/actionpack/test/controller/new_base/content_negotiation_test.rb b/actionpack/test/controller/new_base/content_negotiation_test.rb index c8166280fc..c0e92b3b05 100644 --- a/actionpack/test/controller/new_base/content_negotiation_test.rb +++ b/actionpack/test/controller/new_base/content_negotiation_test.rb @@ -9,7 +9,7 @@ module ContentNegotiation )] def all - render :text => self.formats.inspect + render plain: self.formats.inspect end end diff --git a/actionpack/test/controller/new_base/content_type_test.rb b/actionpack/test/controller/new_base/content_type_test.rb index 88453988dd..0445a837ca 100644 --- a/actionpack/test/controller/new_base/content_type_test.rb +++ b/actionpack/test/controller/new_base/content_type_test.rb @@ -3,16 +3,16 @@ require 'abstract_unit' module ContentType class BaseController < ActionController::Base def index - render :text => "Hello world!" + render body: "Hello world!" end def set_on_response_obj response.content_type = Mime::RSS - render :text => "Hello world!" + render body: "Hello world!" end def set_on_render - render :text => "Hello world!", :content_type => Mime::RSS + render body: "Hello world!", content_type: Mime::RSS end end @@ -30,17 +30,17 @@ module ContentType class CharsetController < ActionController::Base def set_on_response_obj response.charset = "utf-16" - render :text => "Hello world!" + render body: "Hello world!" end def set_as_nil_on_response_obj response.charset = nil - render :text => "Hello world!" + render body: "Hello world!" end end class ExplicitContentTypeTest < Rack::TestCase - test "default response is HTML and UTF8" do + test "default response is text/plain and UTF8" do with_routing do |set| set.draw do get ':controller', :action => 'index' @@ -49,7 +49,7 @@ module ContentType get "/content_type/base" assert_body "Hello world!" - assert_header "Content-Type", "text/html; charset=utf-8" + assert_header "Content-Type", "text/plain; charset=utf-8" end end @@ -99,14 +99,14 @@ module ContentType get "/content_type/charset/set_on_response_obj" assert_body "Hello world!" - assert_header "Content-Type", "text/html; charset=utf-16" + assert_header "Content-Type", "text/plain; charset=utf-16" end test "setting the charset of the response as nil directly on the response object" do get "/content_type/charset/set_as_nil_on_response_obj" assert_body "Hello world!" - assert_header "Content-Type", "text/html; charset=utf-8" + assert_header "Content-Type", "text/plain; charset=utf-8" end end end diff --git a/actionpack/test/controller/new_base/render_test.rb b/actionpack/test/controller/new_base/render_test.rb index 11a19ab783..963f2c2f5c 100644 --- a/actionpack/test/controller/new_base/render_test.rb +++ b/actionpack/test/controller/new_base/render_test.rb @@ -37,14 +37,14 @@ module Render private def secretz - render :text => "FAIL WHALE!" + render plain: "FAIL WHALE!" end end class DoubleRenderController < ActionController::Base def index - render :text => "hello" - render :text => "world" + render plain: "hello" + render plain: "world" end end diff --git a/actionpack/test/controller/permitted_params_test.rb b/actionpack/test/controller/permitted_params_test.rb index 7136fafae5..7c753a45a5 100644 --- a/actionpack/test/controller/permitted_params_test.rb +++ b/actionpack/test/controller/permitted_params_test.rb @@ -2,11 +2,11 @@ require 'abstract_unit' class PeopleController < ActionController::Base def create - render text: params[:person].permitted? ? "permitted" : "forbidden" + render plain: params[:person].permitted? ? "permitted" : "forbidden" end def create_with_permit - render text: params[:person].permit(:name).permitted? ? "permitted" : "forbidden" + render plain: params[:person].permit(:name).permitted? ? "permitted" : "forbidden" end end diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 4f5ca46b04..91b30ede6a 100644 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -3,8 +3,8 @@ require 'abstract_unit' class RedirectController < ActionController::Base # empty method not used anywhere to ensure methods like # `status` and `location` aren't called on `redirect_to` calls - def status; render :text => 'called status'; end - def location; render :text => 'called location'; end + def status; render plain: 'called status'; end + def location; render plain: 'called location'; end def simple_redirect redirect_to :action => "hello_world" diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb index b1ad16bc55..3773900cc4 100644 --- a/actionpack/test/controller/render_json_test.rb +++ b/actionpack/test/controller/render_json_test.rb @@ -28,7 +28,7 @@ class RenderJsonTest < ActionController::TestCase end def render_json_render_to_string - render :text => render_to_string(:json => '[]') + render plain: render_to_string(json: '[]') end def render_json_hello_world diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 43e992d432..9acdc29aeb 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -10,16 +10,16 @@ class TestControllerWithExtraEtags < ActionController::Base etag { nil } def fresh - render text: "stale" if stale?(etag: '123', template: false) + render plain: "stale" if stale?(etag: '123', template: false) end def array - render text: "stale" if stale?(etag: %w(1 2 3), template: false) + render plain: "stale" if stale?(etag: %w(1 2 3), template: false) end def with_template if stale? template: 'test/hello_world' - render text: 'stale' + render plain: 'stale' end end end @@ -622,7 +622,7 @@ class HttpCacheForeverTest < ActionController::TestCase class HttpCacheForeverController < ActionController::Base def cache_me_forever http_cache_forever(public: params[:public], version: params[:version] || 'v1') do - render text: 'hello' + render plain: 'hello' end end end diff --git a/actionpack/test/controller/request_forgery_protection_test.rb b/actionpack/test/controller/request_forgery_protection_test.rb index 7c17aed632..868520a219 100644 --- a/actionpack/test/controller/request_forgery_protection_test.rb +++ b/actionpack/test/controller/request_forgery_protection_test.rb @@ -13,7 +13,7 @@ module RequestForgeryProtectionActions end def unsafe - render :text => 'pwn' + render plain: 'pwn' end def meta diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 2cfd0b8023..e767323773 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -43,8 +43,8 @@ class RescueController < ActionController::Base rescue_from NotAllowed, :with => proc { head :forbidden } rescue_from 'RescueController::NotAllowedToRescueAsString', :with => proc { head :forbidden } - rescue_from InvalidRequest, :with => proc { |exception| render :text => exception.message } - rescue_from 'InvalidRequestToRescueAsString', :with => proc { |exception| render :text => exception.message } + rescue_from InvalidRequest, with: proc { |exception| render plain: exception.message } + rescue_from 'InvalidRequestToRescueAsString', with: proc { |exception| render plain: exception.message } rescue_from BadGateway do head 502 @@ -54,18 +54,18 @@ class RescueController < ActionController::Base end rescue_from ResourceUnavailable do |exception| - render :text => exception.message + render plain: exception.message end rescue_from 'ResourceUnavailableToRescueAsString' do |exception| - render :text => exception.message + render plain: exception.message end rescue_from ActionView::TemplateError do - render :text => 'action_view templater error' + render plain: 'action_view templater error' end rescue_from IOError do - render :text => 'io error' + render plain: 'io error' end before_action(only: :before_action_raises) { raise 'umm nice' } @@ -74,7 +74,7 @@ class RescueController < ActionController::Base end def raises - render :text => 'already rendered' + render plain: 'already rendered' raise "don't panic!" end @@ -302,7 +302,7 @@ class RescueTest < ActionDispatch::IntegrationTest rescue_from RecordInvalid, :with => :show_errors def foo - render :text => "foo" + render plain: "foo" end def invalid @@ -315,7 +315,7 @@ class RescueTest < ActionDispatch::IntegrationTest protected def show_errors(exception) - render :text => exception.message + render plain: exception.message end end diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index 0a20b2c3fb..1c5de983d8 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -6,78 +6,78 @@ require 'rails/engine' class TestCaseTest < ActionController::TestCase class TestController < ActionController::Base def no_op - render text: 'dummy' + render plain: 'dummy' end def set_flash flash["test"] = ">#{flash["test"]}<" - render text: 'ignore me' + render plain: 'ignore me' end def delete_flash flash.delete("test") - render :text => 'ignore me' + render plain: 'ignore me' end def set_flash_now flash.now["test_now"] = ">#{flash["test_now"]}<" - render text: 'ignore me' + render plain: 'ignore me' end def set_session session['string'] = 'A wonder' session[:symbol] = 'it works' - render text: 'Success' + render plain: 'Success' end def reset_the_session reset_session - render text: 'ignore me' + render plain: 'ignore me' end def render_raw_post raise ActiveSupport::TestCase::Assertion, "#raw_post is blank" if request.raw_post.blank? - render text: request.raw_post + render plain: request.raw_post end def render_body - render text: request.body.read + render plain: request.body.read end def test_params - render text: ::JSON.dump(params.to_unsafe_h) + render plain: ::JSON.dump(params.to_unsafe_h) end def test_query_parameters - render text: ::JSON.dump(request.query_parameters) + render plain: ::JSON.dump(request.query_parameters) end def test_request_parameters - render text: request.request_parameters.inspect + render plain: request.request_parameters.inspect end def test_uri - render text: request.fullpath + render plain: request.fullpath end def test_format - render text: request.format + render plain: request.format end def test_query_string - render text: request.query_string + render plain: request.query_string end def test_protocol - render text: request.protocol + render plain: request.protocol end def test_headers - render text: request.headers.env.to_json + render plain: request.headers.env.to_json end def test_html_output - render text: < @@ -99,7 +99,7 @@ HTML def test_xml_output response.content_type = "application/xml" - render text: < area is an empty tag in HTML, raising an error if not in xml mode @@ -108,15 +108,15 @@ XML end def test_only_one_param - render text: (params[:left] && params[:right]) ? "EEP, Both here!" : "OK" + render plain: (params[:left] && params[:right]) ? "EEP, Both here!" : "OK" end def test_remote_addr - render text: (request.remote_addr || "not specified") + render plain: (request.remote_addr || "not specified") end def test_file_upload - render text: params[:file].size + render plain: params[:file].size end def test_send_file @@ -170,7 +170,7 @@ XML before_action { @dynamic_opt = 'opt' } def test_url_options_reset - render text: url_for(params) + render plain: url_for(params) end def default_url_options @@ -997,7 +997,7 @@ module EngineControllerTests class BarController < ActionController::Base def index - render text: 'bar' + render plain: 'bar' end end @@ -1083,7 +1083,7 @@ class AnonymousControllerTest < ActionController::TestCase def setup @controller = Class.new(ActionController::Base) do def index - render text: params[:controller] + render plain: params[:controller] end end.new @@ -1104,11 +1104,11 @@ class RoutingDefaultsTest < ActionController::TestCase def setup @controller = Class.new(ActionController::Base) do def post - render text: request.fullpath + render plain: request.fullpath end def project - render text: request.fullpath + render plain: request.fullpath end end.new diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb index bd81846a7d..b26f037c36 100644 --- a/actionpack/test/controller/webservice_test.rb +++ b/actionpack/test/controller/webservice_test.rb @@ -5,9 +5,9 @@ class WebServiceTest < ActionDispatch::IntegrationTest class TestController < ActionController::Base def assign_parameters if params[:full] - render :text => dump_params_keys + render plain: dump_params_keys else - render :text => (params.keys - ['controller', 'action']).sort.join(", ") + render plain: (params.keys - ['controller', 'action']).sort.join(", ") end end diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb index f90d5499d7..d75e31db62 100644 --- a/actionpack/test/dispatch/prefix_generation_test.rb +++ b/actionpack/test/dispatch/prefix_generation_test.rb @@ -73,26 +73,26 @@ module TestGenerationPrefix include RailsApplication.routes.mounted_helpers def index - render :text => posts_path + render plain: posts_path end def show - render :text => post_path(:id => params[:id]) + render plain: post_path(id: params[:id]) end def url_to_application path = main_app.url_for(:controller => "outside_engine_generating", :action => "index", :only_path => true) - render :text => path + render plain: path end def polymorphic_path_for_engine - render :text => polymorphic_path(Post.new) + render plain: polymorphic_path(Post.new) end def conflicting - render :text => "engine" + render plain: "engine" end end @@ -101,28 +101,28 @@ module TestGenerationPrefix include RailsApplication.routes.url_helpers def index - render :text => blog_engine.post_path(:id => 1) + render plain: blog_engine.post_path(id: 1) end def polymorphic_path_for_engine - render :text => blog_engine.polymorphic_path(Post.new) + render plain: blog_engine.polymorphic_path(Post.new) end def polymorphic_path_for_app - render :text => polymorphic_path(Post.new) + render plain: polymorphic_path(Post.new) end def polymorphic_with_url_for - render :text => blog_engine.url_for(Post.new) + render plain: blog_engine.url_for(Post.new) end def conflicting - render :text => "application" + render plain: "application" end def ivar_usage @blog_engine = "Not the engine route helper" - render :text => blog_engine.post_path(:id => 1) + render plain: blog_engine.post_path(id: 1) end end @@ -378,7 +378,7 @@ module TestGenerationPrefix include RailsApplication.routes.mounted_helpers def show - render :text => post_path(:id => params[:id]) + render plain: post_path(id: params[:id]) 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 50f69c53cb..939a771c65 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -17,7 +17,7 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest end def read - render :text => "File: #{params[:uploaded_data].read}" + render plain: "File: #{params[:uploaded_data].read}" end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 26b8636c2f..b18a9ab647 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3729,7 +3729,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest module ::Admin class StorageFilesController < ActionController::Base def index - render :text => "admin/storage_files#index" + render plain: "admin/storage_files#index" end end end @@ -3824,7 +3824,7 @@ class TestDefaultScope < ActionDispatch::IntegrationTest module ::Blog class PostsController < ActionController::Base def index - render :text => "blog/posts#index" + render plain: "blog/posts#index" end end end @@ -4164,13 +4164,13 @@ end class TestNamedRouteUrlHelpers < ActionDispatch::IntegrationTest class CategoriesController < ActionController::Base def show - render :text => "categories#show" + render plain: "categories#show" end end class ProductsController < ActionController::Base def show - render :text => "products#show" + render plain: "products#show" end end @@ -4265,7 +4265,7 @@ end class TestInvalidUrls < ActionDispatch::IntegrationTest class FooController < ActionController::Base def show - render :text => "foo#show" + render plain: "foo#show" end end @@ -4568,7 +4568,7 @@ end class TestDefaultUrlOptions < ActionDispatch::IntegrationTest class PostsController < ActionController::Base def archive - render :text => "posts#archive" + render plain: "posts#archive" end end diff --git a/actionpack/test/dispatch/session/cache_store_test.rb b/actionpack/test/dispatch/session/cache_store_test.rb index 22a46b0930..e6a70358c8 100644 --- a/actionpack/test/dispatch/session/cache_store_test.rb +++ b/actionpack/test/dispatch/session/cache_store_test.rb @@ -18,11 +18,11 @@ class CacheStoreTest < ActionDispatch::IntegrationTest end def get_session_value - render :text => "foo: #{session[:foo].inspect}" + render plain: "foo: #{session[:foo].inspect}" end def get_session_id - render :text => "#{request.session.id}" + render plain: "#{request.session.id}" end def call_reset_session diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index e7f4235de8..715eb90566 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -16,25 +16,25 @@ class CookieStoreTest < ActionDispatch::IntegrationTest end def persistent_session_id - render :text => session[:session_id] + render plain: session[:session_id] end def set_session_value session[:foo] = "bar" - render :text => Rack::Utils.escape(Verifier.generate(session.to_hash)) + render plain: Rack::Utils.escape(Verifier.generate(session.to_hash)) end def get_session_value - render :text => "foo: #{session[:foo].inspect}" + render plain: "foo: #{session[:foo].inspect}" end def get_session_id - render :text => "id: #{request.session.id}" + render plain: "id: #{request.session.id}" end def get_class_after_reset_session reset_session - render :text => "class: #{session.class}" + render plain: "class: #{session.class}" end def call_session_clear diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb index 9a5d5131c0..6e9107ecbf 100644 --- a/actionpack/test/dispatch/session/mem_cache_store_test.rb +++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb @@ -19,11 +19,11 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest end def get_session_value - render :text => "foo: #{session[:foo].inspect}" + render plain: "foo: #{session[:foo].inspect}" end def get_session_id - render :text => "#{request.session.id}" + render plain: "#{request.session.id}" end def call_reset_session diff --git a/actionpack/test/dispatch/url_generation_test.rb b/actionpack/test/dispatch/url_generation_test.rb index ce1e1d0a6a..fd4ede4d1b 100644 --- a/actionpack/test/dispatch/url_generation_test.rb +++ b/actionpack/test/dispatch/url_generation_test.rb @@ -8,7 +8,7 @@ module TestUrlGeneration class ::MyRouteGeneratingController < ActionController::Base include Routes.url_helpers def index - render :text => foo_path + render plain: foo_path end end -- cgit v1.2.3 From 780af27bf9135be8cc4ae1a9c1ce4c9b4d15fd4b Mon Sep 17 00:00:00 2001 From: Roque Pinel Date: Sat, 18 Jul 2015 18:40:47 -0400 Subject: Fix exception overwritten for parameters fetch method When executing an `ActionController::Parameters#fetch` with a block that raises a `KeyError` the raised `KeyError` will be rescued and converted to an `ActionController::ParameterMissing` exception, covering up the original exception. [Jonas Schubert Erlandsson & Roque Pinel] --- .../test/controller/parameters/parameters_permit_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index 05532ec21b..2dd2826196 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -194,6 +194,19 @@ class ParametersPermitTest < ActiveSupport::TestCase assert_equal "monkey", @params.fetch(:foo) { "monkey" } end + test "fetch doesnt raise ParameterMissing exception if there is a default that is nil" do + assert_equal nil, @params.fetch(:foo, nil) + assert_equal nil, @params.fetch(:foo) { nil } + end + + test 'KeyError in fetch block should not be coverd up' do + params = ActionController::Parameters.new + e = assert_raises(KeyError) do + params.fetch(:missing_key) { {}.fetch(:also_missing) } + end + assert_match(/:also_missing$/, e.message) + end + test "not permitted is sticky beyond merges" do assert !@params.merge(a: "b").permitted? end -- cgit v1.2.3 From 12b0b26df7560ab5199ba830586864085441508f Mon Sep 17 00:00:00 2001 From: Roque Pinel Date: Sun, 19 Jul 2015 22:00:36 -0400 Subject: Fix state being carried over from previous transaction This clears the transaction record state when the transaction finishes with a `:committed` status. Considering the following example where `name` is a required attribute. Before we had `new_record?` returning `true` for a persisted record: ```ruby author = Author.create! name: 'foo' author.name = nil author.save # => false author.new_record? # => true ``` --- actionpack/test/controller/parameters/parameters_permit_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index 2dd2826196..9f7d14e85d 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -199,7 +199,7 @@ class ParametersPermitTest < ActiveSupport::TestCase assert_equal nil, @params.fetch(:foo) { nil } end - test 'KeyError in fetch block should not be coverd up' do + test 'KeyError in fetch block should not be covered up' do params = ActionController::Parameters.new e = assert_raises(KeyError) do params.fetch(:missing_key) { {}.fetch(:also_missing) } -- cgit v1.2.3 From eb55bd34301f26a1f1652f3657f7dbdabdb18157 Mon Sep 17 00:00:00 2001 From: amitkumarsuroliya Date: Mon, 3 Aug 2015 12:28:13 +0530 Subject: Remove duplicity in tests --- actionpack/test/controller/routing_test.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 9bbfb74e72..06ac80356b 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -327,12 +327,6 @@ class LegacyRouteSetTests < ActiveSupport::TestCase assert_equal '/stuff', controller.url_for({ :controller => '/stuff', :only_path => true }) end - def test_ignores_leading_slash - rs.clear! - rs.draw { get '/:controller(/:action(/:id))'} - test_default_setup - end - def test_route_with_colon_first rs.draw do get '/:controller/:action/:id', :action => 'index', :id => nil -- cgit v1.2.3 From 74810392254694050ed736ba540918a6bc8f646a Mon Sep 17 00:00:00 2001 From: Aditya Kapoor Date: Mon, 3 Aug 2015 13:48:15 +0530 Subject: Add missing assertion for test_route_with_colon_first --- actionpack/test/controller/routing_test.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 9bbfb74e72..a333290ade 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -335,9 +335,11 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_route_with_colon_first rs.draw do - get '/:controller/:action/:id', :action => 'index', :id => nil - get ':url', :controller => 'tiny_url', :action => 'translate' + get '/:controller/:action/:id', action: 'index', id: nil + get ':url', controller: 'content', action: 'translate' end + + assert_equal({controller: 'content', action: 'translate', url: 'example'}, rs.recognize_path('/example')) end def test_route_with_regexp_for_controller -- cgit v1.2.3 From b5ae1be2cd1aef2f6ed7a53a4684c6b7eb35304f Mon Sep 17 00:00:00 2001 From: Kohei Suzuki Date: Tue, 4 Aug 2015 21:26:28 +0900 Subject: Add failing spec on utf8 filename with percent character --- .../test/dispatch/request/multipart_params_parsing_test.rb | 11 +++++++++++ actionpack/test/fixtures/multipart/utf8_filename | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 actionpack/test/fixtures/multipart/utf8_filename (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index 939a771c65..b36fbd3c76 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -63,6 +63,17 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest assert_equal 'contents', file.read end + test "parses utf8 filename with percent character" do + params = parse_multipart('utf8_filename') + assert_equal %w(file foo), params.keys.sort + assert_equal 'bar', params['foo'] + + file = params['file'] + assert_equal 'ファイル%名.txt', file.original_filename + assert_equal "text/plain", file.content_type + assert_equal 'contents', file.read + end + test "parses boundary problem file" do params = parse_multipart('boundary_problem_file') assert_equal %w(file foo), params.keys.sort diff --git a/actionpack/test/fixtures/multipart/utf8_filename b/actionpack/test/fixtures/multipart/utf8_filename new file mode 100644 index 0000000000..60738d53b0 --- /dev/null +++ b/actionpack/test/fixtures/multipart/utf8_filename @@ -0,0 +1,10 @@ +--AaB03x +Content-Disposition: form-data; name="foo" + +bar +--AaB03x +Content-Disposition: form-data; name="file"; filename="ファイル%名.txt" +Content-Type: text/plain + +contents +--AaB03x-- -- cgit v1.2.3 From 3004cc817794527fa44c727eea87e20b65c686ce Mon Sep 17 00:00:00 2001 From: Matthew Gerrior Date: Fri, 27 Jun 2014 17:27:41 -0400 Subject: Adds missing argument handling for ActionController::TestSession to allow testing controllers that use session#fetch with a default value. --- actionpack/test/dispatch/session/test_session_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb index d30461a623..59c030176b 100644 --- a/actionpack/test/dispatch/session/test_session_test.rb +++ b/actionpack/test/dispatch/session/test_session_test.rb @@ -40,4 +40,14 @@ class ActionController::TestSessionTest < ActiveSupport::TestCase assert_equal %w(one two), session.keys assert_equal %w(1 2), session.values end + + def test_fetch_returns_default + session = ActionController::TestSession.new(one: '1') + assert_equal('2', session.fetch(:two, '2')) + end + + def test_fetch_returns_block_value + session = ActionController::TestSession.new(one: '1') + assert_equal(2, session.fetch('2') { |key| key.to_i }) + end end -- cgit v1.2.3 From 8f27d6036a2ddc3cb7a7ad98afa2666ec163c2c3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 6 Aug 2015 15:12:19 -0700 Subject: use a request object to reduce string allocations and not know about ENV keys --- actionpack/test/dispatch/static_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb index 95971b3a0e..13dec8b618 100644 --- a/actionpack/test/dispatch/static_test.rb +++ b/actionpack/test/dispatch/static_test.rb @@ -156,7 +156,7 @@ module StaticTests def test_does_not_modify_path_info file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js" - env = {'PATH_INFO' => file_name, 'HTTP_ACCEPT_ENCODING' => 'gzip'} + env = {'PATH_INFO' => file_name, 'HTTP_ACCEPT_ENCODING' => 'gzip', "REQUEST_METHOD" => 'POST'} @app.call(env) assert_equal file_name, env['PATH_INFO'] end -- cgit v1.2.3 From 6d85804bc6aeecce5669fb4b0d7b33c069deff3a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 6 Aug 2015 15:59:30 -0700 Subject: ExceptionWrapper doesn't need to know about `env` ExceptionWrapper only cares about the backtrace cleaner, so lets just pass the cleaner to the wrapper. It does not need to know that env exists or what key the backtrace cleaner is stored in --- actionpack/test/dispatch/exception_wrapper_test.rb | 32 ++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/exception_wrapper_test.rb b/actionpack/test/dispatch/exception_wrapper_test.rb index 7a29a7ff97..3dac582407 100644 --- a/actionpack/test/dispatch/exception_wrapper_test.rb +++ b/actionpack/test/dispatch/exception_wrapper_test.rb @@ -19,15 +19,13 @@ module ActionDispatch setup do Rails.stubs(:root).returns(Pathname.new('.')) - cleaner = ActiveSupport::BacktraceCleaner.new - cleaner.add_silencer { |line| line !~ /^lib/ } - - @environment = { 'action_dispatch.backtrace_cleaner' => cleaner } + @cleaner = ActiveSupport::BacktraceCleaner.new + @cleaner.add_silencer { |line| line !~ /^lib/ } end test '#source_extracts fetches source fragments for every backtrace entry' do exception = TestError.new("lib/file.rb:42:in `index'") - wrapper = ExceptionWrapper.new({}, exception) + wrapper = ExceptionWrapper.new(nil, exception) wrapper.expects(:source_fragment).with('lib/file.rb', 42).returns('foo') @@ -37,7 +35,7 @@ module ActionDispatch test '#source_extracts works with Windows paths' do exc = TestError.new("c:/path/to/rails/app/controller.rb:27:in 'index':") - wrapper = ExceptionWrapper.new({}, exc) + wrapper = ExceptionWrapper.new(nil, exc) wrapper.expects(:source_fragment).with('c:/path/to/rails/app/controller.rb', 27).returns('nothing') assert_equal [ code: 'nothing', line_number: 27 ], wrapper.source_extracts @@ -46,7 +44,7 @@ module ActionDispatch test '#source_extracts works with non standard backtrace' do exc = TestError.new('invalid') - wrapper = ExceptionWrapper.new({}, exc) + wrapper = ExceptionWrapper.new(nil, exc) wrapper.expects(:source_fragment).with('invalid', 0).returns('nothing') assert_equal [ code: 'nothing', line_number: 0 ], wrapper.source_extracts @@ -54,14 +52,14 @@ module ActionDispatch test '#application_trace returns traces only from the application' do exception = TestError.new(caller.prepend("lib/file.rb:42:in `index'")) - wrapper = ExceptionWrapper.new(@environment, exception) + wrapper = ExceptionWrapper.new(@cleaner, exception) assert_equal [ "lib/file.rb:42:in `index'" ], wrapper.application_trace end test '#application_trace cannot be nil' do - nil_backtrace_wrapper = ExceptionWrapper.new(@environment, BadlyDefinedError.new) - nil_cleaner_wrapper = ExceptionWrapper.new({}, BadlyDefinedError.new) + nil_backtrace_wrapper = ExceptionWrapper.new(@cleaner, BadlyDefinedError.new) + nil_cleaner_wrapper = ExceptionWrapper.new(nil, BadlyDefinedError.new) assert_equal [], nil_backtrace_wrapper.application_trace assert_equal [], nil_cleaner_wrapper.application_trace @@ -69,14 +67,14 @@ module ActionDispatch test '#framework_trace returns traces outside the application' do exception = TestError.new(caller.prepend("lib/file.rb:42:in `index'")) - wrapper = ExceptionWrapper.new(@environment, exception) + wrapper = ExceptionWrapper.new(@cleaner, exception) assert_equal caller, wrapper.framework_trace end test '#framework_trace cannot be nil' do - nil_backtrace_wrapper = ExceptionWrapper.new(@environment, BadlyDefinedError.new) - nil_cleaner_wrapper = ExceptionWrapper.new({}, BadlyDefinedError.new) + nil_backtrace_wrapper = ExceptionWrapper.new(@cleaner, BadlyDefinedError.new) + nil_cleaner_wrapper = ExceptionWrapper.new(nil, BadlyDefinedError.new) assert_equal [], nil_backtrace_wrapper.framework_trace assert_equal [], nil_cleaner_wrapper.framework_trace @@ -84,14 +82,14 @@ module ActionDispatch test '#full_trace returns application and framework traces' do exception = TestError.new(caller.prepend("lib/file.rb:42:in `index'")) - wrapper = ExceptionWrapper.new(@environment, exception) + wrapper = ExceptionWrapper.new(@cleaner, exception) assert_equal exception.backtrace, wrapper.full_trace end test '#full_trace cannot be nil' do - nil_backtrace_wrapper = ExceptionWrapper.new(@environment, BadlyDefinedError.new) - nil_cleaner_wrapper = ExceptionWrapper.new({}, BadlyDefinedError.new) + nil_backtrace_wrapper = ExceptionWrapper.new(@cleaner, BadlyDefinedError.new) + nil_cleaner_wrapper = ExceptionWrapper.new(nil, BadlyDefinedError.new) assert_equal [], nil_backtrace_wrapper.full_trace assert_equal [], nil_cleaner_wrapper.full_trace @@ -99,7 +97,7 @@ module ActionDispatch test '#traces returns every trace by category enumerated with an index' do exception = TestError.new("lib/file.rb:42:in `index'", "/gems/rack.rb:43:in `index'") - wrapper = ExceptionWrapper.new(@environment, exception) + wrapper = ExceptionWrapper.new(@cleaner, exception) assert_equal({ 'Application Trace' => [ id: 0, trace: "lib/file.rb:42:in `index'" ], -- cgit v1.2.3 From a278630f5f1312f6986a866d3bc455c1056e554e Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Thu, 6 Aug 2015 17:22:22 -0700 Subject: do not add common ports to HTTP_HOST - webservers do not do it - it makes redirect urls ugly when request.host is used for redirection --- actionpack/test/controller/integration_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 0b9be8d671..dc4c32b07e 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -755,6 +755,25 @@ class MetalIntegrationTest < ActionDispatch::IntegrationTest assert_equal "http://test.com/", @request.env["HTTP_REFERER"] end + def test_ignores_common_ports_in_host + get "http://test.com" + assert_equal "test.com", @request.env["HTTP_HOST"] + + get "https://test.com" + assert_equal "test.com", @request.env["HTTP_HOST"] + end + + def test_keeps_uncommon_ports_in_host + get "http://test.com:123" + assert_equal "test.com:123", @request.env["HTTP_HOST"] + + get "http://test.com:443" + assert_equal "test.com:443", @request.env["HTTP_HOST"] + + get "https://test.com:80" + assert_equal "test.com:80", @request.env["HTTP_HOST"] + end + end class ApplicationIntegrationTest < ActionDispatch::IntegrationTest -- cgit v1.2.3 From 27eddbb332c4adb533e0699e4b1532c3bd4de222 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 7 Aug 2015 12:03:13 -0700 Subject: simplify the Middleware constructor We should do the hard work outside the constructor. Also fix the tests to not directly construct middleware objects, but to go through the stack object. --- .../dispatch/middleware_stack/middleware_test.rb | 63 +++++++++------------- 1 file changed, 24 insertions(+), 39 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/middleware_stack/middleware_test.rb b/actionpack/test/dispatch/middleware_stack/middleware_test.rb index 9607f026db..6366d37aa4 100644 --- a/actionpack/test/dispatch/middleware_stack/middleware_test.rb +++ b/actionpack/test/dispatch/middleware_stack/middleware_test.rb @@ -12,65 +12,50 @@ module ActionDispatch }.each do |name, klass| define_method("test_#{name}_klass") do - mw = Middleware.new klass - assert_equal klass, mw.klass + stack = ActionDispatch::MiddlewareStack.new + stack.use klass + assert_equal klass, stack.first.klass end define_method("test_#{name}_==") do - mw1 = Middleware.new klass - mw2 = Middleware.new klass - assert_equal mw1, mw2 + stack = ActionDispatch::MiddlewareStack.new + stack.use klass + stack.use klass + assert_equal 2, stack.size + assert_equal stack.first, stack.last end end + attr_reader :stack + + def setup + @stack = ActionDispatch::MiddlewareStack.new + end + def test_string_class - mw = Middleware.new Omg.name - assert_equal Omg, mw.klass + stack = ActionDispatch::MiddlewareStack.new + stack.use Omg.name + assert_equal Omg, stack.first.klass end def test_double_equal_works_with_classes k = Class.new - mw = Middleware.new k - assert_operator mw, :==, k + stack.use k + assert_operator stack.first, :==, k - result = mw != Class.new + result = stack.first != Class.new assert result, 'middleware should not equal other anon class' end def test_double_equal_works_with_strings - mw = Middleware.new Omg - assert_operator mw, :==, Omg.name + stack.use Omg + assert_operator stack.first, :==, Omg.name end def test_double_equal_normalizes_strings - mw = Middleware.new Omg - assert_operator mw, :==, "::#{Omg.name}" - end - - def test_middleware_loads_classnames_from_cache - mw = Class.new(Middleware) { - attr_accessor :classcache - }.new(Omg.name) - - fake_cache = { mw.name => Omg } - mw.classcache = fake_cache - - assert_equal Omg, mw.klass - - fake_cache[mw.name] = Middleware - assert_equal Middleware, mw.klass - end - - def test_middleware_always_returns_class - mw = Class.new(Middleware) { - attr_accessor :classcache - }.new(Omg) - - fake_cache = { mw.name => Middleware } - mw.classcache = fake_cache - - assert_equal Omg, mw.klass + stack.use Omg + assert_operator stack.first, :==, "::#{Omg.name}" end end end -- cgit v1.2.3 From 83b767cef90abfc4c2ee9f4b451b0215501fae9a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 7 Aug 2015 14:26:21 -0700 Subject: Using strings or symbols for middleware class names is deprecated. Convert things like this: middleware.use "Foo::Bar" to this: middleware.use Foo::Bar --- actionpack/test/abstract_unit.rb | 14 ++++----- .../dispatch/middleware_stack/middleware_test.rb | 6 ---- actionpack/test/dispatch/middleware_stack_test.rb | 36 ++++++++++++---------- 3 files changed, 26 insertions(+), 30 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index cc610b6d75..771df5a0b2 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -123,13 +123,13 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase def self.build_app(routes = nil) RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware| - middleware.use "ActionDispatch::ShowExceptions", ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public") - middleware.use "ActionDispatch::DebugExceptions" - middleware.use "ActionDispatch::Callbacks" - middleware.use "ActionDispatch::ParamsParser" - middleware.use "ActionDispatch::Cookies" - middleware.use "ActionDispatch::Flash" - middleware.use "Rack::Head" + middleware.use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public") + middleware.use ActionDispatch::DebugExceptions + middleware.use ActionDispatch::Callbacks + middleware.use ActionDispatch::ParamsParser + middleware.use ActionDispatch::Cookies + middleware.use ActionDispatch::Flash + middleware.use Rack::Head yield(middleware) if block_given? end end diff --git a/actionpack/test/dispatch/middleware_stack/middleware_test.rb b/actionpack/test/dispatch/middleware_stack/middleware_test.rb index 6366d37aa4..28f9fa317b 100644 --- a/actionpack/test/dispatch/middleware_stack/middleware_test.rb +++ b/actionpack/test/dispatch/middleware_stack/middleware_test.rb @@ -33,12 +33,6 @@ module ActionDispatch @stack = ActionDispatch::MiddlewareStack.new end - def test_string_class - stack = ActionDispatch::MiddlewareStack.new - stack.use Omg.name - assert_equal Omg, stack.first.klass - end - def test_double_equal_works_with_classes k = Class.new stack.use k diff --git a/actionpack/test/dispatch/middleware_stack_test.rb b/actionpack/test/dispatch/middleware_stack_test.rb index 948a690979..354e95cf30 100644 --- a/actionpack/test/dispatch/middleware_stack_test.rb +++ b/actionpack/test/dispatch/middleware_stack_test.rb @@ -25,17 +25,21 @@ class MiddlewareStackTest < ActiveSupport::TestCase end test "use should push middleware as a string onto the stack" do - assert_difference "@stack.size" do - @stack.use "MiddlewareStackTest::BazMiddleware" + assert_deprecated do + assert_difference "@stack.size" do + @stack.use "MiddlewareStackTest::BazMiddleware" + end + assert_equal BazMiddleware, @stack.last.klass end - assert_equal BazMiddleware, @stack.last.klass end test "use should push middleware as a symbol onto the stack" do - assert_difference "@stack.size" do - @stack.use :"MiddlewareStackTest::BazMiddleware" + assert_deprecated do + assert_difference "@stack.size" do + @stack.use :"MiddlewareStackTest::BazMiddleware" + end + assert_equal BazMiddleware, @stack.last.klass end - assert_equal BazMiddleware, @stack.last.klass end test "use should push middleware class with arguments onto the stack" do @@ -88,8 +92,10 @@ class MiddlewareStackTest < ActiveSupport::TestCase end test "unshift adds a new middleware at the beginning of the stack" do - @stack.unshift :"MiddlewareStackTest::BazMiddleware" - assert_equal BazMiddleware, @stack.first.klass + assert_deprecated do + @stack.unshift :"MiddlewareStackTest::BazMiddleware" + assert_equal BazMiddleware, @stack.first.klass + end end test "raise an error on invalid index" do @@ -103,15 +109,11 @@ class MiddlewareStackTest < ActiveSupport::TestCase end test "lazy evaluates middleware class" do - assert_difference "@stack.size" do - @stack.use "MiddlewareStackTest::BazMiddleware" + assert_deprecated do + assert_difference "@stack.size" do + @stack.use "MiddlewareStackTest::BazMiddleware" + end + assert_equal BazMiddleware, @stack.last.klass end - assert_equal BazMiddleware, @stack.last.klass - end - - test "lazy compares so unloaded constants are not loaded" do - @stack.use "UnknownMiddleware" - @stack.use :"MiddlewareStackTest::BazMiddleware" - assert @stack.include?("::MiddlewareStackTest::BazMiddleware") end end -- cgit v1.2.3 From 2a3c47ff5d4ed7391d8a2d02a6baa1f1f55a8df3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 7 Aug 2015 15:35:39 -0700 Subject: finish deprecating handling strings and symbols since we only work with instances of classes, it greatly simplifies the `Middleware` implementation. --- actionpack/test/controller/flash_test.rb | 2 +- .../dispatch/middleware_stack/middleware_test.rb | 56 ---------------------- actionpack/test/dispatch/middleware_stack_test.rb | 19 +++++++- .../test/dispatch/session/cache_store_test.rb | 2 +- .../test/dispatch/session/cookie_store_test.rb | 2 +- 5 files changed, 20 insertions(+), 61 deletions(-) delete mode 100644 actionpack/test/dispatch/middleware_stack/middleware_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index 64543f0659..b063d769a4 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -329,7 +329,7 @@ class FlashIntegrationTest < ActionDispatch::IntegrationTest @app = self.class.build_app(set) do |middleware| middleware.use ActionDispatch::Session::CookieStore, :key => SessionKey middleware.use ActionDispatch::Flash - middleware.delete "ActionDispatch::ShowExceptions" + middleware.delete ActionDispatch::ShowExceptions end yield diff --git a/actionpack/test/dispatch/middleware_stack/middleware_test.rb b/actionpack/test/dispatch/middleware_stack/middleware_test.rb deleted file mode 100644 index 28f9fa317b..0000000000 --- a/actionpack/test/dispatch/middleware_stack/middleware_test.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'abstract_unit' -require 'action_dispatch/middleware/stack' - -module ActionDispatch - class MiddlewareStack - class MiddlewareTest < ActiveSupport::TestCase - class Omg; end - - { - 'concrete' => Omg, - 'anonymous' => Class.new - }.each do |name, klass| - - define_method("test_#{name}_klass") do - stack = ActionDispatch::MiddlewareStack.new - stack.use klass - assert_equal klass, stack.first.klass - end - - define_method("test_#{name}_==") do - stack = ActionDispatch::MiddlewareStack.new - stack.use klass - stack.use klass - assert_equal 2, stack.size - assert_equal stack.first, stack.last - end - - end - - attr_reader :stack - - def setup - @stack = ActionDispatch::MiddlewareStack.new - end - - def test_double_equal_works_with_classes - k = Class.new - stack.use k - assert_operator stack.first, :==, k - - result = stack.first != Class.new - assert result, 'middleware should not equal other anon class' - end - - def test_double_equal_works_with_strings - stack.use Omg - assert_operator stack.first, :==, Omg.name - end - - def test_double_equal_normalizes_strings - stack.use Omg - assert_operator stack.first, :==, "::#{Omg.name}" - end - end - end -end diff --git a/actionpack/test/dispatch/middleware_stack_test.rb b/actionpack/test/dispatch/middleware_stack_test.rb index 354e95cf30..33aa616474 100644 --- a/actionpack/test/dispatch/middleware_stack_test.rb +++ b/actionpack/test/dispatch/middleware_stack_test.rb @@ -4,6 +4,7 @@ class MiddlewareStackTest < ActiveSupport::TestCase class FooMiddleware; end class BarMiddleware; end class BazMiddleware; end + class HiyaMiddleware; end class BlockMiddleware attr_reader :block def initialize(&block) @@ -17,6 +18,20 @@ class MiddlewareStackTest < ActiveSupport::TestCase @stack.use BarMiddleware end + def test_delete_with_string_is_deprecated + assert_deprecated do + assert_difference "@stack.size", -1 do + @stack.delete FooMiddleware.name + end + end + end + + def test_delete_works + assert_difference "@stack.size", -1 do + @stack.delete FooMiddleware + end + end + test "use should push middleware as class onto the stack" do assert_difference "@stack.size" do @stack.use BazMiddleware @@ -100,11 +115,11 @@ class MiddlewareStackTest < ActiveSupport::TestCase test "raise an error on invalid index" do assert_raise RuntimeError do - @stack.insert("HiyaMiddleware", BazMiddleware) + @stack.insert(HiyaMiddleware, BazMiddleware) end assert_raise RuntimeError do - @stack.insert_after("HiyaMiddleware", BazMiddleware) + @stack.insert_after(HiyaMiddleware, BazMiddleware) end end diff --git a/actionpack/test/dispatch/session/cache_store_test.rb b/actionpack/test/dispatch/session/cache_store_test.rb index e6a70358c8..dbb996973d 100644 --- a/actionpack/test/dispatch/session/cache_store_test.rb +++ b/actionpack/test/dispatch/session/cache_store_test.rb @@ -170,7 +170,7 @@ class CacheStoreTest < ActionDispatch::IntegrationTest @app = self.class.build_app(set) do |middleware| @cache = ActiveSupport::Cache::MemoryStore.new middleware.use ActionDispatch::Session::CacheStore, :key => '_session_id', :cache => @cache - middleware.delete "ActionDispatch::ShowExceptions" + middleware.delete ActionDispatch::ShowExceptions end yield diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index 715eb90566..e432c65c62 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -348,7 +348,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest @app = self.class.build_app(set) do |middleware| middleware.use ActionDispatch::Session::CookieStore, options - middleware.delete "ActionDispatch::ShowExceptions" + middleware.delete ActionDispatch::ShowExceptions end yield -- cgit v1.2.3 From 1f80f3a3738a57be6e36901ef60645fabb6576a9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 7 Aug 2015 16:17:22 -0700 Subject: remove vestigial code Looks like this was left over from converting Rails to Rack. I think it's safe to remove now. --- actionpack/test/controller/new_base/metal_test.rb | 43 ----------------------- 1 file changed, 43 deletions(-) delete mode 100644 actionpack/test/controller/new_base/metal_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/controller/new_base/metal_test.rb b/actionpack/test/controller/new_base/metal_test.rb deleted file mode 100644 index 537b93387a..0000000000 --- a/actionpack/test/controller/new_base/metal_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'abstract_unit' - -module MetalTest - class MetalMiddleware < ActionController::Middleware - def call(env) - if env["PATH_INFO"] =~ /authed/ - app.call(env) - else - [401, headers, "Not authed!"] - end - end - end - - class Endpoint - def call(env) - [200, {}, "Hello World"] - end - end - - class TestMiddleware < ActiveSupport::TestCase - def setup - @app = Rack::Builder.new do - use MetalTest::MetalMiddleware - run MetalTest::Endpoint.new - end.to_app - end - - test "it can call the next app by using @app" do - env = Rack::MockRequest.env_for("/authed") - response = @app.call(env) - - assert_equal ["Hello World"], response[2] - end - - test "it can return a response using the normal AC::Metal techniques" do - env = Rack::MockRequest.env_for("/") - response = @app.call(env) - - assert_equal ["Not authed!"], response[2] - assert_equal 401, response[0] - end - end -end -- cgit v1.2.3 From 2992b1c04c555c6483245257eab16026dd0fd889 Mon Sep 17 00:00:00 2001 From: Xavier Shay Date: Sun, 7 Jul 2013 14:34:46 -0700 Subject: Allow a custom dispatcher to be provided to routing. --- actionpack/test/abstract_unit.rb | 12 ++++-------- actionpack/test/dispatch/mapper_test.rb | 4 ++++ actionpack/test/dispatch/routing_test.rb | 15 ++++++--------- 3 files changed, 14 insertions(+), 17 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 771df5a0b2..5a49fb3cb8 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -149,14 +149,10 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase end end - def self.stub_controllers - old_dispatcher = ActionDispatch::Routing::RouteSet::Dispatcher - ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher } - ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, StubDispatcher } - yield ActionDispatch::Routing::RouteSet.new - ensure - ActionDispatch::Routing::RouteSet.module_eval { remove_const :Dispatcher } - ActionDispatch::Routing::RouteSet.module_eval { const_set :Dispatcher, old_dispatcher } + def self.stub_controllers(config = nil) + route_set = ActionDispatch::Routing::RouteSet.new(*[config].compact) + route_set.dispatcher_class = StubDispatcher + yield route_set end def with_routing(&block) diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 889f9a4736..aed1d914f9 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -19,6 +19,10 @@ module ActionDispatch ActionDispatch::Request end + def dispatcher_class + RouteSet::Dispatcher + end + def add_route(*args) routes << args end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index b18a9ab647..280b258da6 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -168,12 +168,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end def test_session_singleton_resource_for_api_app - self.class.stub_controllers do |_| - config = ActionDispatch::Routing::RouteSet::Config.new - config.api_only = true - - routes = ActionDispatch::Routing::RouteSet.new(config) + config = ActionDispatch::Routing::RouteSet::Config.new + config.api_only = true + self.class.stub_controllers(config) do |routes| routes.draw do resource :session do get :create @@ -550,11 +548,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end def test_projects_for_api_app - self.class.stub_controllers do |_| - config = ActionDispatch::Routing::RouteSet::Config.new - config.api_only = true + config = ActionDispatch::Routing::RouteSet::Config.new + config.api_only = true - routes = ActionDispatch::Routing::RouteSet.new(config) + self.class.stub_controllers(config) do |routes| routes.draw do resources :projects, controller: :project end -- cgit v1.2.3 From c8b82955836cfff2795464e8acc7592e3c192a51 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 8 Aug 2015 10:15:35 -0400 Subject: Refactor to remove DrawOnce module We were doing extra work that could be pushed off to Integration test and SharedRoutes. Creating an extra module isn't necessary when those are created by their respective classes. --- actionpack/test/abstract_unit.rb | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 771df5a0b2..09d55133e9 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -63,6 +63,10 @@ FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') SharedTestRoutes = ActionDispatch::Routing::RouteSet.new +SharedTestRoutes.draw do + get ':controller(/:action)' +end + module ActionDispatch module SharedRoutes def before_setup @@ -70,35 +74,10 @@ module ActionDispatch super end end - - # Hold off drawing routes until all the possible controller classes - # have been loaded. - module DrawOnce - class << self - attr_accessor :drew - end - self.drew = false - - def before_setup - super - return if DrawOnce.drew - - SharedTestRoutes.draw do - get ':controller(/:action)' - end - - ActionDispatch::IntegrationTest.app.routes.draw do - get ':controller(/:action)' - end - - DrawOnce.drew = true - end - end end module ActiveSupport class TestCase - include ActionDispatch::DrawOnce if RUBY_ENGINE == "ruby" && PROCESS_COUNT > 0 parallelize_me! end @@ -119,8 +98,6 @@ class RoutedRackApp end class ActionDispatch::IntegrationTest < ActiveSupport::TestCase - include ActionDispatch::SharedRoutes - def self.build_app(routes = nil) RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware| middleware.use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public") @@ -136,6 +113,10 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase self.app = build_app + app.routes.draw do + get ':controller(/:action)' + end + # Stub Rails dispatcher so it does not get controller references and # simply return the controller#action as Rack::Body. class StubDispatcher < ::ActionDispatch::Routing::RouteSet::Dispatcher -- cgit v1.2.3 From 12f08acbacf823041dae27afd1a1a1458bb1e3fa Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 8 Aug 2015 10:27:23 -0400 Subject: Fix deprecation warning in tests Using the string version of the class reference is now deprecated when referencing middleware. This should be written as a class not as a string. Deprecation warning that this change fixes: ``` DEPRECATION WARNING: Passing strings or symbols to the middleware builder is deprecated, please change them to actual class references. For example: "ActionDispatch::ShowExceptions" => ActionDispatch::ShowExceptions ``` --- actionpack/test/dispatch/session/mem_cache_store_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb index 6e9107ecbf..3fed9bad4f 100644 --- a/actionpack/test/dispatch/session/mem_cache_store_test.rb +++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb @@ -192,7 +192,7 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest @app = self.class.build_app(set) do |middleware| middleware.use ActionDispatch::Session::MemCacheStore, :key => '_session_id', :namespace => "mem_cache_store_test:#{SecureRandom.hex(10)}" - middleware.delete "ActionDispatch::ShowExceptions" + middleware.delete ActionDispatch::ShowExceptions end yield -- cgit v1.2.3 From 286cb890de8bbb01559683a3715387de2cb0af5f Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 8 Aug 2015 11:44:11 -0400 Subject: Refactor route assertion methods in resources test The tests and methods were hard to read with `options[:options]` all over the place. This refactoring makes the code easier to understand. The change came out of work for moving the underlying code of controller tests to integraiton tests. --- actionpack/test/controller/resources_test.rb | 101 ++++++++++++++------------- 1 file changed, 51 insertions(+), 50 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 5a279639cc..04d6cc1792 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -1128,14 +1128,14 @@ class ResourcesTest < ActionController::TestCase end def assert_restful_routes_for(controller_name, options = {}) - options[:options] ||= {} - options[:options][:controller] = options[:controller] || controller_name.to_s + route_options = (options[:options] ||= {}).dup + route_options[:controller] = options[:controller] || controller_name.to_s if options[:shallow] options[:shallow_options] ||= {} - options[:shallow_options][:controller] = options[:options][:controller] + options[:shallow_options][:controller] = route_options[:controller] else - options[:shallow_options] = options[:options] + options[:shallow_options] = route_options end new_action = @routes.resources_path_names[:new] || "new" @@ -1154,7 +1154,7 @@ class ResourcesTest < ActionController::TestCase edit_member_path = "#{member_path}/#{edit_action}" formatted_edit_member_path = "#{member_path}/#{edit_action}.xml" - with_options(options[:options]) do |controller| + with_options(route_options) do |controller| controller.assert_routing collection_path, :action => 'index' controller.assert_routing new_path, :action => 'new' controller.assert_routing "#{collection_path}.xml", :action => 'index', :format => 'xml' @@ -1168,23 +1168,23 @@ class ResourcesTest < ActionController::TestCase controller.assert_routing formatted_edit_member_path, :action => 'edit', :id => '1', :format => 'xml' end - assert_recognizes(options[:options].merge(:action => 'index'), :path => collection_path, :method => :get) - assert_recognizes(options[:options].merge(:action => 'new'), :path => new_path, :method => :get) - assert_recognizes(options[:options].merge(:action => 'create'), :path => collection_path, :method => :post) + assert_recognizes(route_options.merge(:action => 'index'), :path => collection_path, :method => :get) + assert_recognizes(route_options.merge(:action => 'new'), :path => new_path, :method => :get) + assert_recognizes(route_options.merge(:action => 'create'), :path => collection_path, :method => :post) assert_recognizes(options[:shallow_options].merge(:action => 'show', :id => '1'), :path => member_path, :method => :get) assert_recognizes(options[:shallow_options].merge(:action => 'edit', :id => '1'), :path => edit_member_path, :method => :get) assert_recognizes(options[:shallow_options].merge(:action => 'update', :id => '1'), :path => member_path, :method => :put) assert_recognizes(options[:shallow_options].merge(:action => 'destroy', :id => '1'), :path => member_path, :method => :delete) - assert_recognizes(options[:options].merge(:action => 'index', :format => 'xml'), :path => "#{collection_path}.xml", :method => :get) - assert_recognizes(options[:options].merge(:action => 'new', :format => 'xml'), :path => "#{new_path}.xml", :method => :get) - assert_recognizes(options[:options].merge(:action => 'create', :format => 'xml'), :path => "#{collection_path}.xml", :method => :post) + assert_recognizes(route_options.merge(:action => 'index', :format => 'xml'), :path => "#{collection_path}.xml", :method => :get) + assert_recognizes(route_options.merge(:action => 'new', :format => 'xml'), :path => "#{new_path}.xml", :method => :get) + assert_recognizes(route_options.merge(:action => 'create', :format => 'xml'), :path => "#{collection_path}.xml", :method => :post) assert_recognizes(options[:shallow_options].merge(:action => 'show', :id => '1', :format => 'xml'), :path => "#{member_path}.xml", :method => :get) assert_recognizes(options[:shallow_options].merge(:action => 'edit', :id => '1', :format => 'xml'), :path => formatted_edit_member_path, :method => :get) assert_recognizes(options[:shallow_options].merge(:action => 'update', :id => '1', :format => 'xml'), :path => "#{member_path}.xml", :method => :put) assert_recognizes(options[:shallow_options].merge(:action => 'destroy', :id => '1', :format => 'xml'), :path => "#{member_path}.xml", :method => :delete) - yield options[:options] if block_given? + yield route_options if block_given? end # test named routes like foo_path and foos_path map to the correct options. @@ -1195,20 +1195,20 @@ class ResourcesTest < ActionController::TestCase end singular_name ||= controller_name.to_s.singularize - options[:options] ||= {} - options[:options][:controller] = options[:controller] || controller_name.to_s + route_options = (options[:options] ||= {}).dup + route_options[:controller] = options[:controller] || controller_name.to_s if options[:shallow] options[:shallow_options] ||= {} - options[:shallow_options][:controller] = options[:options][:controller] + options[:shallow_options][:controller] = route_options[:controller] else - options[:shallow_options] = options[:options] + options[:shallow_options] = route_options end - @controller = "#{options[:options][:controller].camelize}Controller".constantize.new + @controller = "#{route_options[:controller].camelize}Controller".constantize.new @controller.singleton_class.include(@routes.url_helpers) - get :index, params: options[:options] - options[:options].delete :action + get :index, params: route_options + route_options.delete :action path = "#{options[:as] || controller_name}" shallow_path = "/#{options[:shallow] ? options[:namespace] : options[:path_prefix]}#{path}" @@ -1223,29 +1223,29 @@ class ResourcesTest < ActionController::TestCase edit_action = options[:path_names][:edit] || "edit" end - assert_named_route "#{full_path}", "#{name_prefix}#{controller_name}_path", options[:options] - assert_named_route "#{full_path}.xml", "#{name_prefix}#{controller_name}_path", options[:options].merge(:format => 'xml') + assert_named_route "#{full_path}", "#{name_prefix}#{controller_name}_path", route_options + assert_named_route "#{full_path}.xml", "#{name_prefix}#{controller_name}_path", route_options.merge(:format => 'xml') assert_named_route "#{shallow_path}/1", "#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1') assert_named_route "#{shallow_path}/1.xml", "#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1', :format => 'xml') - assert_named_route "#{full_path}/#{new_action}", "new_#{name_prefix}#{singular_name}_path", options[:options] - assert_named_route "#{full_path}/#{new_action}.xml", "new_#{name_prefix}#{singular_name}_path", options[:options].merge(:format => 'xml') + assert_named_route "#{full_path}/#{new_action}", "new_#{name_prefix}#{singular_name}_path", route_options + assert_named_route "#{full_path}/#{new_action}.xml", "new_#{name_prefix}#{singular_name}_path", route_options.merge(:format => 'xml') assert_named_route "#{shallow_path}/1/#{edit_action}", "edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1') assert_named_route "#{shallow_path}/1/#{edit_action}.xml", "edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1', :format => 'xml') - yield options[:options] if block_given? + yield route_options if block_given? end def assert_singleton_routes_for(singleton_name, options = {}) - options[:options] ||= {} - options[:options][:controller] = options[:controller] || singleton_name.to_s.pluralize + route_options = (options[:options] ||= {}).dup + route_options[:controller] = options[:controller] || singleton_name.to_s.pluralize full_path = "/#{options[:path_prefix]}#{options[:as] || singleton_name}" new_path = "#{full_path}/new" edit_path = "#{full_path}/edit" formatted_edit_path = "#{full_path}/edit.xml" - with_options options[:options] do |controller| + with_options route_options do |controller| controller.assert_routing full_path, :action => 'show' controller.assert_routing new_path, :action => 'new' controller.assert_routing edit_path, :action => 'edit' @@ -1254,40 +1254,41 @@ class ResourcesTest < ActionController::TestCase controller.assert_routing formatted_edit_path, :action => 'edit', :format => 'xml' end - assert_recognizes(options[:options].merge(:action => 'show'), :path => full_path, :method => :get) - assert_recognizes(options[:options].merge(:action => 'new'), :path => new_path, :method => :get) - assert_recognizes(options[:options].merge(:action => 'edit'), :path => edit_path, :method => :get) - assert_recognizes(options[:options].merge(:action => 'create'), :path => full_path, :method => :post) - assert_recognizes(options[:options].merge(:action => 'update'), :path => full_path, :method => :put) - assert_recognizes(options[:options].merge(:action => 'destroy'), :path => full_path, :method => :delete) + assert_recognizes(route_options.merge(:action => 'show'), :path => full_path, :method => :get) + assert_recognizes(route_options.merge(:action => 'new'), :path => new_path, :method => :get) + assert_recognizes(route_options.merge(:action => 'edit'), :path => edit_path, :method => :get) + assert_recognizes(route_options.merge(:action => 'create'), :path => full_path, :method => :post) + assert_recognizes(route_options.merge(:action => 'update'), :path => full_path, :method => :put) + assert_recognizes(route_options.merge(:action => 'destroy'), :path => full_path, :method => :delete) - assert_recognizes(options[:options].merge(:action => 'show', :format => 'xml'), :path => "#{full_path}.xml", :method => :get) - assert_recognizes(options[:options].merge(:action => 'new', :format => 'xml'), :path => "#{new_path}.xml", :method => :get) - assert_recognizes(options[:options].merge(:action => 'edit', :format => 'xml'), :path => formatted_edit_path, :method => :get) - assert_recognizes(options[:options].merge(:action => 'create', :format => 'xml'), :path => "#{full_path}.xml", :method => :post) - assert_recognizes(options[:options].merge(:action => 'update', :format => 'xml'), :path => "#{full_path}.xml", :method => :put) - assert_recognizes(options[:options].merge(:action => 'destroy', :format => 'xml'), :path => "#{full_path}.xml", :method => :delete) + assert_recognizes(route_options.merge(:action => 'show', :format => 'xml'), :path => "#{full_path}.xml", :method => :get) + assert_recognizes(route_options.merge(:action => 'new', :format => 'xml'), :path => "#{new_path}.xml", :method => :get) + assert_recognizes(route_options.merge(:action => 'edit', :format => 'xml'), :path => formatted_edit_path, :method => :get) + assert_recognizes(route_options.merge(:action => 'create', :format => 'xml'), :path => "#{full_path}.xml", :method => :post) + assert_recognizes(route_options.merge(:action => 'update', :format => 'xml'), :path => "#{full_path}.xml", :method => :put) + assert_recognizes(route_options.merge(:action => 'destroy', :format => 'xml'), :path => "#{full_path}.xml", :method => :delete) - yield options[:options] if block_given? + yield route_options if block_given? end def assert_singleton_named_routes_for(singleton_name, options = {}) - (options[:options] ||= {})[:controller] ||= singleton_name.to_s.pluralize - @controller = "#{options[:options][:controller].camelize}Controller".constantize.new + route_options = (options[:options] ||= {}).dup + controller_name = route_options[:controller] || options[:controller] || singleton_name.to_s.pluralize + @controller = "#{controller_name.camelize}Controller".constantize.new @controller.singleton_class.include(@routes.url_helpers) - get :show, params: options[:options] - options[:options].delete :action + get :show, params: route_options + route_options.delete :action full_path = "/#{options[:path_prefix]}#{options[:as] || singleton_name}" name_prefix = options[:name_prefix] - assert_named_route "#{full_path}", "#{name_prefix}#{singleton_name}_path", options[:options] - assert_named_route "#{full_path}.xml", "#{name_prefix}#{singleton_name}_path", options[:options].merge(:format => 'xml') + assert_named_route "#{full_path}", "#{name_prefix}#{singleton_name}_path", route_options + assert_named_route "#{full_path}.xml", "#{name_prefix}#{singleton_name}_path", route_options.merge(:format => 'xml') - assert_named_route "#{full_path}/new", "new_#{name_prefix}#{singleton_name}_path", options[:options] - assert_named_route "#{full_path}/new.xml", "new_#{name_prefix}#{singleton_name}_path", options[:options].merge(:format => 'xml') - assert_named_route "#{full_path}/edit", "edit_#{name_prefix}#{singleton_name}_path", options[:options] - assert_named_route "#{full_path}/edit.xml", "edit_#{name_prefix}#{singleton_name}_path", options[:options].merge(:format => 'xml') + assert_named_route "#{full_path}/new", "new_#{name_prefix}#{singleton_name}_path", route_options + assert_named_route "#{full_path}/new.xml", "new_#{name_prefix}#{singleton_name}_path", route_options.merge(:format => 'xml') + assert_named_route "#{full_path}/edit", "edit_#{name_prefix}#{singleton_name}_path", route_options + assert_named_route "#{full_path}/edit.xml", "edit_#{name_prefix}#{singleton_name}_path", route_options.merge(:format => 'xml') end def assert_named_route(expected, route, options) -- cgit v1.2.3 From 97bbde76009daa7f4ebdf8a59943cfbbebe4da04 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 11 Aug 2015 07:56:32 -0700 Subject: pull up the "options.delete(:controller)" logic we want to try to pull this logic up to where the user actually passed in "controller" so that it's close to the related call. That way when we're down the stack, we don't need to wonder "why are we doing this?" --- actionpack/test/dispatch/mapper_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index aed1d914f9..18daa62425 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -41,8 +41,8 @@ module ActionDispatch end def test_mapping_requirements - options = { :controller => 'foo', :action => 'bar', :via => :get } - m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, options) + options = { :action => 'bar', :via => :get } + m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, 'foo', options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3 From 5935e4c882b89d539d7a1441263bc265d397cf8e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 11 Aug 2015 13:54:25 -0700 Subject: push option decomposition up a bit more I think we can find the original place where `action` is added to the options hash now. --- actionpack/test/dispatch/mapper_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 18daa62425..0a7550eb4a 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -41,8 +41,8 @@ module ActionDispatch end def test_mapping_requirements - options = { :action => 'bar', :via => :get } - m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, 'foo', options) + options = { :via => :get } + m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3 From dec2f52fa494c5adf8805ec227ed60d911a6fb4a Mon Sep 17 00:00:00 2001 From: Dennis Suratna Date: Tue, 11 Aug 2015 15:25:38 -0700 Subject: Authorization scheme should be case insensitive. Fixes #21199 --- actionpack/test/controller/http_basic_authentication_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/http_basic_authentication_test.rb b/actionpack/test/controller/http_basic_authentication_test.rb index ed3632007d..0a5e5402b9 100644 --- a/actionpack/test/controller/http_basic_authentication_test.rb +++ b/actionpack/test/controller/http_basic_authentication_test.rb @@ -100,6 +100,14 @@ class HttpBasicAuthenticationTest < ActionController::TestCase assert_no_match(/\n/, result) end + test "succesful authentication with uppercase authorization scheme" do + @request.env['HTTP_AUTHORIZATION'] = "BASIC #{::Base64.encode64("lifo:world")}" + get :index + + assert_response :success + assert_equal 'Hello Secret', @response.body, 'Authentication failed when authorization scheme BASIC' + end + test "authentication request without credential" do get :display -- cgit v1.2.3 From 97d7dc48d68e4c20c17e315c8f4d3f045ed97f5a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 11 Aug 2015 16:15:55 -0700 Subject: pull `to` up this way we don't have to insert / delete it from the options hash so many times. --- actionpack/test/dispatch/mapper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 0a7550eb4a..b0815c41c8 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -42,7 +42,7 @@ module ActionDispatch def test_mapping_requirements options = { :via => :get } - m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', options) + m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3 From b59ff24207c39ec69ab2d792c5ebb4e77c871f51 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 12 Aug 2015 13:43:32 -0700 Subject: pull `via` extraction up We're going to try pulling this up further, and check `via` validity sooner. This way we don't have to do a bunch of processing on `options` hashes only to find out that the route is incorrect --- actionpack/test/dispatch/mapper_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index b0815c41c8..5376ed70dd 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -41,8 +41,8 @@ module ActionDispatch end def test_mapping_requirements - options = { :via => :get } - m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, options) + options = { } + m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3 From 4c641c6e362238afbe76b9a1c9d06339f2a805c4 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 12 Aug 2015 14:12:17 -0700 Subject: add a test for adding "via" using `scope` --- actionpack/test/dispatch/mapper_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 5376ed70dd..bd9786899f 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -47,6 +47,15 @@ module ActionDispatch assert_equal(/.+?/, requirements[:rest]) end + def test_via_scope + fakeset = FakeSet.new + mapper = Mapper.new fakeset + mapper.scope(via: :put) do + mapper.match '/', :to => 'posts#index', :as => :main + end + assert_equal ["PUT"], fakeset.conditions.first[:request_method] + end + def test_map_slash fakeset = FakeSet.new mapper = Mapper.new fakeset -- cgit v1.2.3 From b46c67fb472fc78c7b2aa225cba041ffe4d5c061 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 12 Aug 2015 14:20:15 -0700 Subject: pull `via` all the way out of `add_route` --- actionpack/test/dispatch/mapper_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index bd9786899f..e36f1718ac 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -40,6 +40,14 @@ module ActionDispatch Mapper.new FakeSet.new end + def test_blows_up_without_via + fakeset = FakeSet.new + mapper = Mapper.new fakeset + assert_raises(ArgumentError) do + mapper.match '/', :to => 'posts#index', :as => :main + end + end + def test_mapping_requirements options = { } m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], options) -- cgit v1.2.3 From 1c9431753939b9987416debf839d5707efe4dc18 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 12 Aug 2015 14:30:40 -0700 Subject: add a method to `Scope` for getting mapping options Eventually we don't want to expose the "options" hash from scope, only read values from it. Lets start by adding a reader method. --- actionpack/test/dispatch/mapper_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index e36f1718ac..9076dab0c0 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -50,7 +50,8 @@ module ActionDispatch def test_mapping_requirements options = { } - m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], options) + scope = Mapper::Scope.new({}) + m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3 From e2735b2b32db5de76c39d953b1e6339ecb19e24d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 12 Aug 2015 15:17:21 -0700 Subject: add a regression test for adding arbitrary keys to `scope` --- actionpack/test/dispatch/mapper_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 9076dab0c0..3071890521 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -27,6 +27,10 @@ module ActionDispatch routes << args end + def defaults + routes.map { |x| x[3] } + end + def conditions routes.map { |x| x[1] } end @@ -48,6 +52,17 @@ module ActionDispatch end end + def test_random_keys + fakeset = FakeSet.new + mapper = Mapper.new fakeset + mapper.scope(omg: :awesome) do + mapper.get '/', :to => 'posts#index', :as => :main + end + assert_equal({:omg=>:awesome, :controller=>"posts", :action=>"index"}, + fakeset.defaults.first) + assert_equal ["GET"], fakeset.conditions.first[:request_method] + end + def test_mapping_requirements options = { } scope = Mapper::Scope.new({}) -- cgit v1.2.3 From d61e3c79dc85a5ae86ed00fc9352a5d1d84c0f3f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 12 Aug 2015 16:24:26 -0700 Subject: add a regression test for scoped `format` params This just ensures that `format` is applied to things inside the scope --- actionpack/test/dispatch/mapper_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 3071890521..edc6987e97 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -52,6 +52,17 @@ module ActionDispatch end end + def test_scoped_formatted + fakeset = FakeSet.new + mapper = Mapper.new fakeset + mapper.scope(format: true) do + mapper.get '/foo', :to => 'posts#index', :as => :main + end + assert_equal({:controller=>"posts", :action=>"index"}, + fakeset.defaults.first) + assert_equal "/foo.:format", fakeset.conditions.first[:path_info] + end + def test_random_keys fakeset = FakeSet.new mapper = Mapper.new fakeset -- cgit v1.2.3 From ec895189e4bed93f40ba96af7319a5fc046ad621 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 12 Aug 2015 16:29:33 -0700 Subject: pull `formatted` up the stack this reduces the number of times we have to mutate the options hash. --- actionpack/test/dispatch/mapper_test.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index edc6987e97..6ce0e34ec3 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -52,6 +52,15 @@ module ActionDispatch end end + def test_unscoped_formatted + fakeset = FakeSet.new + mapper = Mapper.new fakeset + mapper.get '/foo', :to => 'posts#index', :as => :main, :format => true + assert_equal({:controller=>"posts", :action=>"index"}, + fakeset.defaults.first) + assert_equal "/foo.:format", fakeset.conditions.first[:path_info] + end + def test_scoped_formatted fakeset = FakeSet.new mapper = Mapper.new fakeset @@ -77,7 +86,7 @@ module ActionDispatch def test_mapping_requirements options = { } scope = Mapper::Scope.new({}) - m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], options) + m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], nil, options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3 From 33dc653466c0058740611259956712a9027801b3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Aug 2015 13:40:55 -0700 Subject: raise if `anchor` is passed to `scope` The `anchor` parameter [is overridden](https://github.com/rails/rails/blob/b4b4a611d0eb9aa1c640c5f521c6a43bf2a65bab/actionpack/lib/action_dispatch/routing/mapper.rb#L1528) unless it is directly passed to `match`, so setting it in a scope must be a mistake. --- actionpack/test/dispatch/mapper_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 6ce0e34ec3..8734380008 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -44,6 +44,15 @@ module ActionDispatch Mapper.new FakeSet.new end + def test_scope_raises_on_anchor + fakeset = FakeSet.new + mapper = Mapper.new fakeset + assert_raises(ArgumentError) do + mapper.scope(anchor: false) do + end + end + end + def test_blows_up_without_via fakeset = FakeSet.new mapper = Mapper.new fakeset -- cgit v1.2.3 From aef421ed9da6a48582876e49e103a9af586a2c8b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Aug 2015 13:54:56 -0700 Subject: pull `anchor` extraction up this way we don't have to mutate the options hash so far away from where the user passed it in --- actionpack/test/dispatch/mapper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 8734380008..4a72bfa048 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -95,7 +95,7 @@ module ActionDispatch def test_mapping_requirements options = { } scope = Mapper::Scope.new({}) - m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], nil, options) + m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], nil, nil, options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3 From e38a456faf6d4ab90c1ea7a3f9310ea47af35049 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Aug 2015 13:58:16 -0700 Subject: remove anchor from mapping the same value that is extracted from the options hash earlier is returned, so we don't need to pass it in in the first place. The caller already has the data, so stop passing it around. --- actionpack/test/dispatch/mapper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 4a72bfa048..8734380008 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -95,7 +95,7 @@ module ActionDispatch def test_mapping_requirements options = { } scope = Mapper::Scope.new({}) - m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], nil, nil, options) + m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], nil, options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3 From b778f6348bb5f00fc5fe8b6209c1a3f796126255 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Aug 2015 14:04:02 -0700 Subject: remove `as` the caller already has access to `as`, so we can stop passing it around. --- actionpack/test/dispatch/mapper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 8734380008..9a3a29b903 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -95,7 +95,7 @@ module ActionDispatch def test_mapping_requirements options = { } scope = Mapper::Scope.new({}) - m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], nil, options) + m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', 'foo', 'bar', nil, [:get], nil, options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3 From 45d594fa53ce838110dcbddc1cf05af490b460a2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Aug 2015 14:15:04 -0700 Subject: pull up options_constrants extraction --- actionpack/test/dispatch/mapper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 9a3a29b903..7ba946aa7f 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -95,7 +95,7 @@ module ActionDispatch def test_mapping_requirements options = { } scope = Mapper::Scope.new({}) - m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', 'foo', 'bar', nil, [:get], nil, options) + m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', 'foo', 'bar', nil, [:get], nil, {}, options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3 From 4868692687f2904d2a02c1d6cd09882b6916cc5f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Aug 2015 15:16:25 -0700 Subject: pass anchor directly to `Pattern` the caller already has it, there is no reason to pack it in to an object and just throw that object away. --- actionpack/test/journey/path/pattern_test.rb | 27 ++++++++--------- actionpack/test/journey/route_test.rb | 2 +- actionpack/test/journey/router_test.rb | 44 ++++++++++++++-------------- actionpack/test/journey/routes_test.rb | 4 +-- 4 files changed, 38 insertions(+), 39 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/journey/path/pattern_test.rb b/actionpack/test/journey/path/pattern_test.rb index 6939b426f6..2efa89b298 100644 --- a/actionpack/test/journey/path/pattern_test.rb +++ b/actionpack/test/journey/path/pattern_test.rb @@ -24,7 +24,7 @@ module ActionDispatch { :controller => /.+/ }, ["/", ".", "?"] ) - path = Pattern.new strexp + path = Pattern.new strexp, true assert_equal(expected, path.to_regexp) end end @@ -46,10 +46,9 @@ module ActionDispatch strexp = Router::Strexp.build( path, { :controller => /.+/ }, - ["/", ".", "?"], - false + ["/", ".", "?"] ) - path = Pattern.new strexp + path = Pattern.new strexp, false assert_equal(expected, path.to_regexp) end end @@ -72,7 +71,7 @@ module ActionDispatch { :controller => /.+/ }, ["/", ".", "?"] ) - path = Pattern.new strexp + path = Pattern.new strexp, true assert_equal(expected, path.names) end end @@ -87,7 +86,7 @@ module ActionDispatch )/x }, ["/", ".", "?"] ) - path = Pattern.new strexp + path = Pattern.new strexp, true assert_match(path, '/page/tender') assert_match(path, '/page/love') assert_no_match(path, '/page/loving') @@ -110,7 +109,7 @@ module ActionDispatch { :name => /\d+/ }, ["/", ".", "?"] ) - path = Pattern.new strexp + path = Pattern.new strexp, true assert_match(path, '/123') assert_no_match(path, '/') end @@ -121,7 +120,7 @@ module ActionDispatch { :name => /(tender|love)/ }, ["/", ".", "?"] ) - path = Pattern.new strexp + path = Pattern.new strexp, true assert_match(path, '/page/tender') assert_match(path, '/page/love') assert_no_match(path, '/page/loving') @@ -137,7 +136,7 @@ module ActionDispatch assert_equal requirements, strexp.requirements - path = Pattern.new strexp + path = Pattern.new strexp, true nodes = path.ast.grep(Nodes::Symbol) assert_equal 2, nodes.length nodes.each do |node| @@ -151,7 +150,7 @@ module ActionDispatch { :name => /(tender|love)/ }, ["/", ".", "?"] ) - path = Pattern.new strexp + path = Pattern.new strexp, true match = path.match '/page/tender' assert_equal 'tender', match[1] assert_equal 2, match.length @@ -163,7 +162,7 @@ module ActionDispatch { :name => /t(((ender|love)))()/ }, ["/", ".", "?"] ) - path = Pattern.new strexp + path = Pattern.new strexp, true match = path.match '/page/tender/10' assert_equal 'tender', match[1] assert_equal '10', match[2] @@ -178,7 +177,7 @@ module ActionDispatch { :foo => z }, ["/", ".", "?"] ) - path = Pattern.new strexp + path = Pattern.new strexp, true assert_equal(%r{\A/page/(#{z})\Z}, path.to_regexp) end @@ -188,7 +187,7 @@ module ActionDispatch { :name => /(tender|love)/i }, ["/", ".", "?"] ) - path = Pattern.new strexp + path = Pattern.new strexp, true assert_match(path, '/page/TENDER/aaron') assert_match(path, '/page/loVE/aaron') assert_no_match(path, '/page/loVE/AAron') @@ -196,7 +195,7 @@ module ActionDispatch def test_to_regexp_with_strexp strexp = Router::Strexp.build('/:controller', { }, ["/", ".", "?"]) - path = Pattern.new strexp + path = Pattern.new strexp, true x = %r{\A/([^/.?]+)\Z} assert_equal(x.source, path.source) diff --git a/actionpack/test/journey/route_test.rb b/actionpack/test/journey/route_test.rb index eff96a0abc..14cb3a259c 100644 --- a/actionpack/test/journey/route_test.rb +++ b/actionpack/test/journey/route_test.rb @@ -27,7 +27,7 @@ module ActionDispatch def test_path_requirements_override_defaults strexp = Router::Strexp.build(':name', { name: /love/ }, ['/']) - path = Path::Pattern.new strexp + path = Path::Pattern.new strexp, true defaults = { name: 'tender' } route = Route.new('name', nil, path, nil, [], defaults) assert_equal(/love/, route.requirements[:name]) diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index 802fb93c69..cd8c77f1c1 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -33,7 +33,7 @@ module ActionDispatch router = Router.new(routes) exp = Router::Strexp.build '/foo-bar-baz', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.new exp, true routes.add_route nil, path, {}, [], {:id => nil}, {} @@ -50,7 +50,7 @@ module ActionDispatch #match the escaped version of /ほげ exp = Router::Strexp.build '/%E3%81%BB%E3%81%92', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.new exp, true routes.add_route nil, path, {}, [], {:id => nil}, {} @@ -69,7 +69,7 @@ module ActionDispatch requirements = { :hello => /world/ } exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.new exp, true routes.add_route nil, path, requirements, [], {:id => nil}, {} @@ -89,7 +89,7 @@ module ActionDispatch requirements = { :hello => /mom/ } exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.new exp, true router.routes.add_route nil, path, requirements, [], {:id => nil}, {} @@ -116,7 +116,7 @@ module ActionDispatch router = Router.new(routes) exp = Router::Strexp.build '/bar', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.new exp, true routes.add_route nil, path, {}, [], {}, {} @@ -152,8 +152,8 @@ module ActionDispatch def test_required_parts_verified_are_anchored add_routes @router, [ - Router::Strexp.build("/foo/:id", { :id => /\d/ }, ['/', '.', '?'], false) - ] + Router::Strexp.build("/foo/:id", { :id => /\d/ }, ['/', '.', '?']) + ], false assert_raises(ActionController::UrlGenerationError) do @formatter.generate(nil, { :id => '10' }, { }) @@ -162,8 +162,8 @@ module ActionDispatch def test_required_parts_are_verified_when_building add_routes @router, [ - Router::Strexp.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) - ] + Router::Strexp.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?']) + ], false path, _ = @formatter.generate(nil, { :id => '10' }, { }) assert_equal '/foo/10', path @@ -175,8 +175,8 @@ module ActionDispatch def test_only_required_parts_are_verified add_routes @router, [ - Router::Strexp.build("/foo(/:id)", {:id => /\d/}, ['/', '.', '?'], false) - ] + Router::Strexp.build("/foo(/:id)", {:id => /\d/}, ['/', '.', '?']) + ], false path, _ = @formatter.generate(nil, { :id => '10' }, { }) assert_equal '/foo/10', path @@ -190,8 +190,8 @@ module ActionDispatch def test_knows_what_parts_are_missing_from_named_route route_name = "gorby_thunderhorse" - pattern = Router::Strexp.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) - path = Path::Pattern.new pattern + pattern = Router::Strexp.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?']) + path = Path::Pattern.new pattern, false @router.routes.add_route nil, path, {}, [], {}, route_name error = assert_raises(ActionController::UrlGenerationError) do @@ -249,8 +249,8 @@ module ActionDispatch def test_recognize_with_unbound_regexp add_routes @router, [ - Router::Strexp.build("/foo", { }, ['/', '.', '?'], false) - ] + Router::Strexp.build("/foo", { }, ['/', '.', '?']) + ], false env = rails_env 'PATH_INFO' => '/foo/bar' @@ -262,8 +262,8 @@ module ActionDispatch def test_bound_regexp_keeps_path_info add_routes @router, [ - Router::Strexp.build("/foo", { }, ['/', '.', '?'], true) - ] + Router::Strexp.build("/foo", { }, ['/', '.', '?']) + ], true env = rails_env 'PATH_INFO' => '/foo' @@ -329,8 +329,8 @@ module ActionDispatch def test_generate_slash params = [ [:controller, "tasks"], [:action, "show"] ] - str = Router::Strexp.build("/", Hash[params], ['/', '.', '?'], true) - path = Path::Pattern.new str + str = Router::Strexp.build("/", Hash[params], ['/', '.', '?']) + path = Path::Pattern.new str, true @router.routes.add_route @app, path, {}, [], {}, {} @@ -503,7 +503,7 @@ module ActionDispatch { :controller => /.+?/ }, ["/", ".", "?"] ) - path = Path::Pattern.new strexp + path = Path::Pattern.new strexp, true app = Object.new route = @router.routes.add_route(app, path, {}, [], {}, {}) @@ -610,12 +610,12 @@ module ActionDispatch private - def add_routes router, paths + def add_routes router, paths, anchor = true paths.each do |path| if String === path path = Path::Pattern.from_string path else - path = Path::Pattern.new path + path = Path::Pattern.new path, anchor end router.routes.add_route @app, path, {}, [], {}, {} end diff --git a/actionpack/test/journey/routes_test.rb b/actionpack/test/journey/routes_test.rb index b9dac8751c..c7555e68ee 100644 --- a/actionpack/test/journey/routes_test.rb +++ b/actionpack/test/journey/routes_test.rb @@ -10,7 +10,7 @@ module ActionDispatch def test_clear routes = Routes.new exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.new exp, true requirements = { :hello => /world/ } routes.add_route nil, path, requirements, [], {:id => nil}, {} @@ -52,7 +52,7 @@ module ActionDispatch strexp = Router::Strexp.build( "/hello/:who", { who: /\d/ }, ['/', '.', '?'] ) - path = Path::Pattern.new strexp + path = Path::Pattern.new strexp, true custom_route = @routes.add_route nil, path, {}, [], {}, {} assert_equal [custom_route], @routes.custom_routes -- cgit v1.2.3 From 947ebe9a6d516271092853f8164c414f126cff6e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Aug 2015 15:42:46 -0700 Subject: remove Strexp This was a useless object. We can just directly construct a Path::Pattern object without a Strexp object. --- actionpack/test/journey/path/pattern_test.rb | 71 +++++++++++++--------------- actionpack/test/journey/route_test.rb | 3 +- actionpack/test/journey/router_test.rb | 53 +++++++++------------ actionpack/test/journey/routes_test.rb | 8 ++-- 4 files changed, 61 insertions(+), 74 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/journey/path/pattern_test.rb b/actionpack/test/journey/path/pattern_test.rb index 2efa89b298..7b97379bd5 100644 --- a/actionpack/test/journey/path/pattern_test.rb +++ b/actionpack/test/journey/path/pattern_test.rb @@ -19,12 +19,12 @@ module ActionDispatch '/:foo|*bar' => %r{\A/(?:([^/.?]+)|(.+))\Z}, }.each do |path, expected| define_method(:"test_to_regexp_#{path}") do - strexp = Router::Strexp.build( + path = Pattern.build( path, { :controller => /.+/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp, true assert_equal(expected, path.to_regexp) end end @@ -43,12 +43,12 @@ module ActionDispatch '/:foo|*bar' => %r{\A/(?:([^/.?]+)|(.+))}, }.each do |path, expected| define_method(:"test_to_non_anchored_regexp_#{path}") do - strexp = Router::Strexp.build( + path = Pattern.build( path, { :controller => /.+/ }, - ["/", ".", "?"] + ["/", ".", "?"], + false ) - path = Pattern.new strexp, false assert_equal(expected, path.to_regexp) end end @@ -66,27 +66,27 @@ module ActionDispatch '/:controller/*foo/bar' => %w{ controller foo }, }.each do |path, expected| define_method(:"test_names_#{path}") do - strexp = Router::Strexp.build( + path = Pattern.build( path, { :controller => /.+/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp, true assert_equal(expected, path.names) end end def test_to_regexp_with_extended_group - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name', { :name => / #ROFL (tender|love #MAO )/x }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp, true assert_match(path, '/page/tender') assert_match(path, '/page/love') assert_no_match(path, '/page/loving') @@ -104,23 +104,23 @@ module ActionDispatch end def test_to_regexp_match_non_optional - strexp = Router::Strexp.build( + path = Pattern.build( '/:name', { :name => /\d+/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp, true assert_match(path, '/123') assert_no_match(path, '/') end def test_to_regexp_with_group - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name', { :name => /(tender|love)/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp, true assert_match(path, '/page/tender') assert_match(path, '/page/love') assert_no_match(path, '/page/loving') @@ -128,15 +128,13 @@ module ActionDispatch def test_ast_sets_regular_expressions requirements = { :name => /(tender|love)/, :value => /./ } - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name/:value', requirements, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - assert_equal requirements, strexp.requirements - - path = Pattern.new strexp, true nodes = path.ast.grep(Nodes::Symbol) assert_equal 2, nodes.length nodes.each do |node| @@ -145,24 +143,24 @@ module ActionDispatch end def test_match_data_with_group - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name', { :name => /(tender|love)/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp, true match = path.match '/page/tender' assert_equal 'tender', match[1] assert_equal 2, match.length end def test_match_data_with_multi_group - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name/:id', { :name => /t(((ender|love)))()/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp, true match = path.match '/page/tender/10' assert_equal 'tender', match[1] assert_equal '10', match[2] @@ -172,30 +170,29 @@ module ActionDispatch def test_star_with_custom_re z = /\d+/ - strexp = Router::Strexp.build( + path = Pattern.build( '/page/*foo', { :foo => z }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp, true assert_equal(%r{\A/page/(#{z})\Z}, path.to_regexp) end def test_insensitive_regexp_with_group - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name/aaron', { :name => /(tender|love)/i }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp, true assert_match(path, '/page/TENDER/aaron') assert_match(path, '/page/loVE/aaron') assert_no_match(path, '/page/loVE/AAron') end def test_to_regexp_with_strexp - strexp = Router::Strexp.build('/:controller', { }, ["/", ".", "?"]) - path = Pattern.new strexp, true + path = Pattern.build('/:controller', { }, ["/", ".", "?"], true) x = %r{\A/([^/.?]+)\Z} assert_equal(x.source, path.source) diff --git a/actionpack/test/journey/route_test.rb b/actionpack/test/journey/route_test.rb index 14cb3a259c..cdd59a3316 100644 --- a/actionpack/test/journey/route_test.rb +++ b/actionpack/test/journey/route_test.rb @@ -26,8 +26,7 @@ module ActionDispatch end def test_path_requirements_override_defaults - strexp = Router::Strexp.build(':name', { name: /love/ }, ['/']) - path = Path::Pattern.new strexp, true + path = Path::Pattern.build(':name', { name: /love/ }, ['/'], true) defaults = { name: 'tender' } route = Route.new('name', nil, path, nil, [], defaults) assert_equal(/love/, route.requirements[:name]) diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index cd8c77f1c1..5c6d9645fb 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -32,8 +32,7 @@ module ActionDispatch def test_dashes router = Router.new(routes) - exp = Router::Strexp.build '/foo-bar-baz', {}, ['/.?'] - path = Path::Pattern.new exp, true + path = Path::Pattern.build '/foo-bar-baz', {}, ['/.?'], true routes.add_route nil, path, {}, [], {:id => nil}, {} @@ -49,8 +48,7 @@ module ActionDispatch router = Router.new(routes) #match the escaped version of /ほげ - exp = Router::Strexp.build '/%E3%81%BB%E3%81%92', {}, ['/.?'] - path = Path::Pattern.new exp, true + path = Path::Pattern.build '/%E3%81%BB%E3%81%92', {}, ['/.?'], true routes.add_route nil, path, {}, [], {:id => nil}, {} @@ -68,8 +66,7 @@ module ActionDispatch requirements = { :hello => /world/ } - exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?'] - path = Path::Pattern.new exp, true + path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true routes.add_route nil, path, requirements, [], {:id => nil}, {} @@ -88,8 +85,7 @@ module ActionDispatch requirements = { :hello => /mom/ } - exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?'] - path = Path::Pattern.new exp, true + path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true router.routes.add_route nil, path, requirements, [], {:id => nil}, {} @@ -115,8 +111,7 @@ module ActionDispatch def test_request_class_overrides_path_info router = Router.new(routes) - exp = Router::Strexp.build '/bar', {}, ['/.?'] - path = Path::Pattern.new exp, true + path = Path::Pattern.build '/bar', {}, ['/.?'], true routes.add_route nil, path, {}, [], {}, {} @@ -133,8 +128,8 @@ module ActionDispatch def test_regexp_first_precedence add_routes @router, [ - Router::Strexp.build("/whois/:domain", {:domain => /\w+\.[\w\.]+/}, ['/', '.', '?']), - Router::Strexp.build("/whois/:id(.:format)", {}, ['/', '.', '?']) + Path::Pattern.build("/whois/:domain", {:domain => /\w+\.[\w\.]+/}, ['/', '.', '?'], true), + Path::Pattern.build("/whois/:id(.:format)", {}, ['/', '.', '?'], true) ] env = rails_env 'PATH_INFO' => '/whois/example.com' @@ -152,8 +147,8 @@ module ActionDispatch def test_required_parts_verified_are_anchored add_routes @router, [ - Router::Strexp.build("/foo/:id", { :id => /\d/ }, ['/', '.', '?']) - ], false + Path::Pattern.build("/foo/:id", { :id => /\d/ }, ['/', '.', '?'], false) + ] assert_raises(ActionController::UrlGenerationError) do @formatter.generate(nil, { :id => '10' }, { }) @@ -162,8 +157,8 @@ module ActionDispatch def test_required_parts_are_verified_when_building add_routes @router, [ - Router::Strexp.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?']) - ], false + Path::Pattern.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) + ] path, _ = @formatter.generate(nil, { :id => '10' }, { }) assert_equal '/foo/10', path @@ -175,8 +170,8 @@ module ActionDispatch def test_only_required_parts_are_verified add_routes @router, [ - Router::Strexp.build("/foo(/:id)", {:id => /\d/}, ['/', '.', '?']) - ], false + Path::Pattern.build("/foo(/:id)", {:id => /\d/}, ['/', '.', '?'], false) + ] path, _ = @formatter.generate(nil, { :id => '10' }, { }) assert_equal '/foo/10', path @@ -190,8 +185,7 @@ module ActionDispatch def test_knows_what_parts_are_missing_from_named_route route_name = "gorby_thunderhorse" - pattern = Router::Strexp.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?']) - path = Path::Pattern.new pattern, false + path = Path::Pattern.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) @router.routes.add_route nil, path, {}, [], {}, route_name error = assert_raises(ActionController::UrlGenerationError) do @@ -249,8 +243,8 @@ module ActionDispatch def test_recognize_with_unbound_regexp add_routes @router, [ - Router::Strexp.build("/foo", { }, ['/', '.', '?']) - ], false + Path::Pattern.build("/foo", { }, ['/', '.', '?'], false) + ] env = rails_env 'PATH_INFO' => '/foo/bar' @@ -262,8 +256,8 @@ module ActionDispatch def test_bound_regexp_keeps_path_info add_routes @router, [ - Router::Strexp.build("/foo", { }, ['/', '.', '?']) - ], true + Path::Pattern.build("/foo", { }, ['/', '.', '?'], true) + ] env = rails_env 'PATH_INFO' => '/foo' @@ -329,8 +323,7 @@ module ActionDispatch def test_generate_slash params = [ [:controller, "tasks"], [:action, "show"] ] - str = Router::Strexp.build("/", Hash[params], ['/', '.', '?']) - path = Path::Pattern.new str, true + path = Path::Pattern.build("/", Hash[params], ['/', '.', '?'], true) @router.routes.add_route @app, path, {}, [], {}, {} @@ -498,12 +491,12 @@ module ActionDispatch end def test_namespaced_controller - strexp = Router::Strexp.build( + path = Path::Pattern.build( "/:controller(/:action(/:id))", { :controller => /.+?/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Path::Pattern.new strexp, true app = Object.new route = @router.routes.add_route(app, path, {}, [], {}, {}) @@ -615,7 +608,7 @@ module ActionDispatch if String === path path = Path::Pattern.from_string path else - path = Path::Pattern.new path, anchor + path end router.routes.add_route @app, path, {}, [], {}, {} end diff --git a/actionpack/test/journey/routes_test.rb b/actionpack/test/journey/routes_test.rb index c7555e68ee..6853cefc01 100644 --- a/actionpack/test/journey/routes_test.rb +++ b/actionpack/test/journey/routes_test.rb @@ -9,8 +9,7 @@ module ActionDispatch def test_clear routes = Routes.new - exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?'] - path = Path::Pattern.new exp, true + path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true requirements = { :hello => /world/ } routes.add_route nil, path, requirements, [], {:id => nil}, {} @@ -49,10 +48,9 @@ module ActionDispatch assert_equal [anchored_route], @routes.anchored_routes assert_equal [], @routes.custom_routes - strexp = Router::Strexp.build( - "/hello/:who", { who: /\d/ }, ['/', '.', '?'] + path = Path::Pattern.build( + "/hello/:who", { who: /\d/ }, ['/', '.', '?'], false ) - path = Path::Pattern.new strexp, true custom_route = @routes.add_route nil, path, {}, [], {}, {} assert_equal [custom_route], @routes.custom_routes -- cgit v1.2.3 From 715abbbb33a0715b5b8476132b7fd7c20b9e0df1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 09:19:22 -0700 Subject: stop adding path_info to the conditions hash we don't need to keep adding it and deleting if from hashes. --- actionpack/test/dispatch/mapper_test.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 7ba946aa7f..10ef00ca50 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -67,7 +67,7 @@ module ActionDispatch mapper.get '/foo', :to => 'posts#index', :as => :main, :format => true assert_equal({:controller=>"posts", :action=>"index"}, fakeset.defaults.first) - assert_equal "/foo.:format", fakeset.conditions.first[:path_info] + assert_equal "/foo.:format", fakeset.conditions.first[:parsed_path_info].to_s end def test_scoped_formatted @@ -78,7 +78,7 @@ module ActionDispatch end assert_equal({:controller=>"posts", :action=>"index"}, fakeset.defaults.first) - assert_equal "/foo.:format", fakeset.conditions.first[:path_info] + assert_equal "/foo.:format", fakeset.conditions.first[:parsed_path_info].to_s end def test_random_keys @@ -113,7 +113,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/', :to => 'posts#index', :as => :main - assert_equal '/', fakeset.conditions.first[:path_info] + assert_equal '/', fakeset.conditions.first[:parsed_path_info].to_s end def test_map_more_slashes @@ -122,14 +122,14 @@ module ActionDispatch # FIXME: is this a desired behavior? mapper.get '/one/two/', :to => 'posts#index', :as => :main - assert_equal '/one/two(.:format)', fakeset.conditions.first[:path_info] + assert_equal '/one/two(.:format)', fakeset.conditions.first[:parsed_path_info].to_s end def test_map_wildcard fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/*path', :to => 'pages#show' - assert_equal '/*path(.:format)', fakeset.conditions.first[:path_info] + assert_equal '/*path(.:format)', fakeset.conditions.first[:parsed_path_info].to_s assert_equal(/.+?/, fakeset.requirements.first[:path]) end @@ -137,7 +137,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/*path/foo/:bar', :to => 'pages#show' - assert_equal '/*path/foo/:bar(.:format)', fakeset.conditions.first[:path_info] + assert_equal '/*path/foo/:bar(.:format)', fakeset.conditions.first[:parsed_path_info].to_s assert_equal(/.+?/, fakeset.requirements.first[:path]) end @@ -145,7 +145,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/*foo/*bar', :to => 'pages#show' - assert_equal '/*foo/*bar(.:format)', fakeset.conditions.first[:path_info] + assert_equal '/*foo/*bar(.:format)', fakeset.conditions.first[:parsed_path_info].to_s assert_equal(/.+?/, fakeset.requirements.first[:foo]) assert_equal(/.+?/, fakeset.requirements.first[:bar]) end @@ -154,7 +154,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/*path', :to => 'pages#show', :format => false - assert_equal '/*path', fakeset.conditions.first[:path_info] + assert_equal '/*path', fakeset.conditions.first[:parsed_path_info].to_s assert_nil fakeset.requirements.first[:path] end @@ -162,7 +162,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/*path', :to => 'pages#show', :format => true - assert_equal '/*path.:format', fakeset.conditions.first[:path_info] + assert_equal '/*path.:format', fakeset.conditions.first[:parsed_path_info].to_s end def test_raising_helpful_error_on_invalid_arguments -- cgit v1.2.3 From 61437232a9205ae4890f6d7491a97217b63c45c1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 09:45:44 -0700 Subject: extract ast finding to a method I'm going to reimplement this using route objects, so it will be easier if we just change ast access to go through a method rather than hashes --- actionpack/test/dispatch/mapper_test.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 10ef00ca50..9049391930 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -38,6 +38,10 @@ module ActionDispatch def requirements routes.map { |x| x[2] } end + + def asts + conditions.map { |hash| hash[:parsed_path_info] } + end end def test_initialize @@ -67,7 +71,7 @@ module ActionDispatch mapper.get '/foo', :to => 'posts#index', :as => :main, :format => true assert_equal({:controller=>"posts", :action=>"index"}, fakeset.defaults.first) - assert_equal "/foo.:format", fakeset.conditions.first[:parsed_path_info].to_s + assert_equal "/foo.:format", fakeset.asts.first.to_s end def test_scoped_formatted @@ -78,7 +82,7 @@ module ActionDispatch end assert_equal({:controller=>"posts", :action=>"index"}, fakeset.defaults.first) - assert_equal "/foo.:format", fakeset.conditions.first[:parsed_path_info].to_s + assert_equal "/foo.:format", fakeset.asts.first.to_s end def test_random_keys @@ -113,7 +117,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/', :to => 'posts#index', :as => :main - assert_equal '/', fakeset.conditions.first[:parsed_path_info].to_s + assert_equal '/', fakeset.asts.first.to_s end def test_map_more_slashes @@ -122,14 +126,14 @@ module ActionDispatch # FIXME: is this a desired behavior? mapper.get '/one/two/', :to => 'posts#index', :as => :main - assert_equal '/one/two(.:format)', fakeset.conditions.first[:parsed_path_info].to_s + assert_equal '/one/two(.:format)', fakeset.asts.first.to_s end def test_map_wildcard fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/*path', :to => 'pages#show' - assert_equal '/*path(.:format)', fakeset.conditions.first[:parsed_path_info].to_s + assert_equal '/*path(.:format)', fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:path]) end @@ -137,7 +141,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/*path/foo/:bar', :to => 'pages#show' - assert_equal '/*path/foo/:bar(.:format)', fakeset.conditions.first[:parsed_path_info].to_s + assert_equal '/*path/foo/:bar(.:format)', fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:path]) end @@ -145,7 +149,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/*foo/*bar', :to => 'pages#show' - assert_equal '/*foo/*bar(.:format)', fakeset.conditions.first[:parsed_path_info].to_s + assert_equal '/*foo/*bar(.:format)', fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:foo]) assert_equal(/.+?/, fakeset.requirements.first[:bar]) end @@ -154,7 +158,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/*path', :to => 'pages#show', :format => false - assert_equal '/*path', fakeset.conditions.first[:parsed_path_info].to_s + assert_equal '/*path', fakeset.asts.first.to_s assert_nil fakeset.requirements.first[:path] end @@ -162,7 +166,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.get '/*path', :to => 'pages#show', :format => true - assert_equal '/*path.:format', fakeset.conditions.first[:parsed_path_info].to_s + assert_equal '/*path.:format', fakeset.asts.first.to_s end def test_raising_helpful_error_on_invalid_arguments -- cgit v1.2.3 From 60adf118a622bebe55f9e2cdfcf94287d3c031a7 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 09:49:53 -0700 Subject: implement the `asts` method in terms of paths / patterns Eventually I want to eliminate the FakeSet test class --- actionpack/test/dispatch/mapper_test.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 9049391930..dab15a909e 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -4,17 +4,20 @@ module ActionDispatch module Routing class MapperTest < ActiveSupport::TestCase class FakeSet < ActionDispatch::Routing::RouteSet - attr_reader :routes - alias :set :routes - def initialize - @routes = [] + @my_routes = [] + super end def resources_path_names {} end + def add_route(*args) + @my_routes << args + super + end + def request_class ActionDispatch::Request end @@ -23,24 +26,20 @@ module ActionDispatch RouteSet::Dispatcher end - def add_route(*args) - routes << args - end - def defaults - routes.map { |x| x[3] } + @my_routes.map { |x| x[3] } end def conditions - routes.map { |x| x[1] } + @my_routes.map { |x| x[1] } end def requirements - routes.map { |x| x[2] } + @my_routes.map { |x| x[2] } end def asts - conditions.map { |hash| hash[:parsed_path_info] } + routes.map(&:path).map(&:spec) end end -- cgit v1.2.3 From c3284e2a36e92af1a2ad3bdbc1c74523811f3ad2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 10:05:03 -0700 Subject: implement `requirements` in terms of routes --- actionpack/test/dispatch/mapper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index dab15a909e..4155a44c39 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -35,7 +35,7 @@ module ActionDispatch end def requirements - @my_routes.map { |x| x[2] } + routes.map(&:path).map(&:requirements) end def asts -- cgit v1.2.3 From 7fa6600b52b7477a958473d504415b7610d39b34 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 10:20:28 -0700 Subject: use predicate methods instead of hard coding verb strings also change the feeler to subclass AD::Request so that it has all the methods that Request has --- actionpack/test/dispatch/routing_test.rb | 3 ++- actionpack/test/journey/router_test.rb | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 280b258da6..6e8d7ca7a9 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3618,7 +3618,7 @@ private end class TestAltApp < ActionDispatch::IntegrationTest - class AltRequest + class AltRequest < ActionDispatch::Request attr_accessor :path_parameters, :path_info, :script_name attr_reader :env @@ -3627,6 +3627,7 @@ class TestAltApp < ActionDispatch::IntegrationTest @env = env @path_info = "/" @script_name = "" + super end def request_method diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index 5c6d9645fb..427d63d75d 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -13,7 +13,10 @@ module ActionDispatch @formatter = Formatter.new(@routes) end - class FakeRequestFeeler < Struct.new(:env, :called) + class FakeRequestFeeler < ActionDispatch::Request + attr_writer :env + attr_accessor :called + def new env self.env = env self @@ -23,10 +26,6 @@ module ActionDispatch self.called = true 'world' end - - def path_info; env['PATH_INFO']; end - def request_method; env['REQUEST_METHOD']; end - def ip; env['REMOTE_ADDR']; end end def test_dashes -- cgit v1.2.3 From aaaa67902ee1d129a6907e4ebd726f383ad7002b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 10:39:22 -0700 Subject: pull up path parsing `add_route` needs the AST, so rather than shove it in a hash and delete later, lets move parsing up the stack so we can pass down later --- actionpack/test/dispatch/mapper_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 4155a44c39..0c506a13bf 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -98,7 +98,8 @@ module ActionDispatch def test_mapping_requirements options = { } scope = Mapper::Scope.new({}) - m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', 'foo', 'bar', nil, [:get], nil, {}, options) + ast = Journey::Parser.parse '/store/:name(*rest)' + m = Mapper::Mapping.build(scope, FakeSet.new, ast, 'foo', 'bar', nil, [:get], nil, {}, options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end -- cgit v1.2.3 From b592c5b607e4879c0b603bf636cf6d11e9f4b8d2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 10:44:49 -0700 Subject: pass the path ast down now we don't need to add it to a hash and delete it from the hash later just to pass it around --- actionpack/test/dispatch/mapper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 0c506a13bf..289fb69b8b 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -27,7 +27,7 @@ module ActionDispatch end def defaults - @my_routes.map { |x| x[3] } + @my_routes.map { |x| x[4] } end def conditions -- cgit v1.2.3 From b10b279b97b0174d6e157d03845921f04f19d0ad Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 11:55:50 -0700 Subject: deprecate passing a string for both the beginning path and :path option --- actionpack/test/dispatch/routing_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 6e8d7ca7a9..332a550de0 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -361,9 +361,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end def test_pagemarks + tc = self draw do scope "pagemark", :controller => "pagemarks", :as => :pagemark do - get "new", :path => "build" + tc.assert_deprecated do + get "new", :path => "build" + end post "create", :as => "" put "update" get "remove", :action => :destroy, :as => :remove -- cgit v1.2.3 From 5ba6966766e67af4ae0028c4429acbd280a100a2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 14:41:48 -0700 Subject: pass the mapping object to build_route now that we aren't doing options manipulations, we can just pass the mapping object down and read values from it. --- actionpack/test/dispatch/mapper_test.rb | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 289fb69b8b..8c1b53041a 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -4,20 +4,10 @@ module ActionDispatch module Routing class MapperTest < ActiveSupport::TestCase class FakeSet < ActionDispatch::Routing::RouteSet - def initialize - @my_routes = [] - super - end - def resources_path_names {} end - def add_route(*args) - @my_routes << args - super - end - def request_class ActionDispatch::Request end @@ -27,11 +17,11 @@ module ActionDispatch end def defaults - @my_routes.map { |x| x[4] } + routes.map(&:defaults) end def conditions - @my_routes.map { |x| x[1] } + routes.map(&:constraints) end def requirements @@ -92,7 +82,7 @@ module ActionDispatch end assert_equal({:omg=>:awesome, :controller=>"posts", :action=>"index"}, fakeset.defaults.first) - assert_equal ["GET"], fakeset.conditions.first[:request_method] + assert_equal(/^GET$/, fakeset.conditions.first[:request_method]) end def test_mapping_requirements @@ -100,8 +90,7 @@ module ActionDispatch scope = Mapper::Scope.new({}) ast = Journey::Parser.parse '/store/:name(*rest)' m = Mapper::Mapping.build(scope, FakeSet.new, ast, 'foo', 'bar', nil, [:get], nil, {}, options) - _, _, requirements, _ = m.to_route - assert_equal(/.+?/, requirements[:rest]) + assert_equal(/.+?/, m.requirements[:rest]) end def test_via_scope @@ -110,7 +99,7 @@ module ActionDispatch mapper.scope(via: :put) do mapper.match '/', :to => 'posts#index', :as => :main end - assert_equal ["PUT"], fakeset.conditions.first[:request_method] + assert_equal(/^PUT$/, fakeset.conditions.first[:request_method]) end def test_map_slash -- cgit v1.2.3 From 6c48d9392fe964640fe5721fcd27bb170613cc27 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 16:13:26 -0700 Subject: pass pass the mapping object down the add_route stack then we can let the mapping object derive stuff that the Route object needs. --- actionpack/test/dispatch/mapper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 8c1b53041a..eca4ca8e0e 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -89,7 +89,7 @@ module ActionDispatch options = { } scope = Mapper::Scope.new({}) ast = Journey::Parser.parse '/store/:name(*rest)' - m = Mapper::Mapping.build(scope, FakeSet.new, ast, 'foo', 'bar', nil, [:get], nil, {}, options) + m = Mapper::Mapping.build(scope, FakeSet.new, ast, 'foo', 'bar', nil, [:get], nil, {}, true, options) assert_equal(/.+?/, m.requirements[:rest]) end -- cgit v1.2.3 From 4bdd92d9fd731b69ba6e12e6e45dd5bbb3ffd6dd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 16:25:03 -0700 Subject: rm add_route2 refactor the tests with a backwards compatible method call so we can rm add_route2 from the journey router --- actionpack/test/journey/router_test.rb | 58 +++++++++++++++++++--------------- actionpack/test/journey/routes_test.rb | 34 +++++++++++--------- 2 files changed, 51 insertions(+), 41 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index 427d63d75d..bddfbe7ef0 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -33,7 +33,7 @@ module ActionDispatch path = Path::Pattern.build '/foo-bar-baz', {}, ['/.?'], true - routes.add_route nil, path, {}, [], {:id => nil}, {} + add_route nil, path, {}, [], {:id => nil}, {} env = rails_env 'PATH_INFO' => '/foo-bar-baz' called = false @@ -49,7 +49,7 @@ module ActionDispatch #match the escaped version of /ほげ path = Path::Pattern.build '/%E3%81%BB%E3%81%92', {}, ['/.?'], true - routes.add_route nil, path, {}, [], {:id => nil}, {} + add_route nil, path, {}, [], {:id => nil}, {} env = rails_env 'PATH_INFO' => '/%E3%81%BB%E3%81%92' called = false @@ -67,7 +67,7 @@ module ActionDispatch path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true - routes.add_route nil, path, requirements, [], {:id => nil}, {} + add_route nil, path, requirements, [], {:id => nil}, {} env = rails_env({'PATH_INFO' => '/foo/10'}, klass) router.recognize(env) do |r, params| @@ -86,7 +86,7 @@ module ActionDispatch path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true - router.routes.add_route nil, path, requirements, [], {:id => nil}, {} + add_route nil, path, requirements, [], {:id => nil}, {} env = rails_env({'PATH_INFO' => '/foo/10'}, klass) router.recognize(env) do |r, params| @@ -112,7 +112,7 @@ module ActionDispatch path = Path::Pattern.build '/bar', {}, ['/.?'], true - routes.add_route nil, path, {}, [], {}, {} + add_route nil, path, {}, [], {}, {} env = rails_env({'PATH_INFO' => '/foo', 'custom.path_info' => '/bar'}, CustomPathRequest) @@ -185,7 +185,7 @@ module ActionDispatch def test_knows_what_parts_are_missing_from_named_route route_name = "gorby_thunderhorse" path = Path::Pattern.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) - @router.routes.add_route nil, path, {}, [], {}, route_name + add_route nil, path, {}, [], {}, route_name error = assert_raises(ActionController::UrlGenerationError) do @formatter.generate(route_name, { }, { }) @@ -227,7 +227,7 @@ module ActionDispatch def test_defaults_merge_correctly path = Path::Pattern.from_string '/foo(/:id)' - @router.routes.add_route nil, path, {}, [], {:id => nil}, {} + add_route nil, path, {}, [], {:id => nil}, {} env = rails_env 'PATH_INFO' => '/foo/10' @router.recognize(env) do |r, params| @@ -310,7 +310,7 @@ module ActionDispatch def test_nil_path_parts_are_ignored path = Path::Pattern.from_string "/:controller(/:action(.:format))" - @router.routes.add_route @app, path, {}, [], {}, {} + add_route @app, path, {}, [], {}, {} params = { :controller => "tasks", :format => nil } extras = { :action => 'lol' } @@ -324,7 +324,7 @@ module ActionDispatch [:action, "show"] ] path = Path::Pattern.build("/", Hash[params], ['/', '.', '?'], true) - @router.routes.add_route @app, path, {}, [], {}, {} + add_route @app, path, {}, [], {}, {} path, _ = @formatter.generate(nil, Hash[params], {}) assert_equal '/', path @@ -332,7 +332,7 @@ module ActionDispatch def test_generate_calls_param_proc path = Path::Pattern.from_string '/:controller(/:action)' - @router.routes.add_route @app, path, {}, [], {}, {} + add_route @app, path, {}, [], {}, {} parameterized = [] params = [ [:controller, "tasks"], @@ -349,7 +349,7 @@ module ActionDispatch def test_generate_id path = Path::Pattern.from_string '/:controller(/:action)' - @router.routes.add_route @app, path, {}, [], {}, {} + add_route @app, path, {}, [], {}, {} path, params = @formatter.generate( nil, {:id=>1, :controller=>"tasks", :action=>"show"}, {}) @@ -359,7 +359,7 @@ module ActionDispatch def test_generate_escapes path = Path::Pattern.from_string '/:controller(/:action)' - @router.routes.add_route @app, path, {}, [], {}, {} + add_route @app, path, {}, [], {}, {} path, _ = @formatter.generate(nil, { :controller => "tasks", @@ -370,7 +370,7 @@ module ActionDispatch def test_generate_escapes_with_namespaced_controller path = Path::Pattern.from_string '/:controller(/:action)' - @router.routes.add_route @app, path, {}, [], {}, {} + add_route @app, path, {}, [], {}, {} path, _ = @formatter.generate( nil, { :controller => "admin/tasks", @@ -381,7 +381,7 @@ module ActionDispatch def test_generate_extra_params path = Path::Pattern.from_string '/:controller(/:action)' - @router.routes.add_route @app, path, {}, [], {}, {} + add_route @app, path, {}, [], {}, {} path, params = @formatter.generate( nil, { :id => 1, @@ -395,7 +395,7 @@ module ActionDispatch def test_generate_missing_keys_no_matches_different_format_keys path = Path::Pattern.from_string '/:controller/:action/:name' - @router.routes.add_route @app, path, {}, [], {}, {} + add_route @app, path, {}, [], {}, {} primarty_parameters = { :id => 1, :controller => "tasks", @@ -422,7 +422,7 @@ module ActionDispatch def test_generate_uses_recall_if_needed path = Path::Pattern.from_string '/:controller(/:action(/:id))' - @router.routes.add_route @app, path, {}, [], {}, {} + add_route @app, path, {}, [], {}, {} path, params = @formatter.generate( nil, @@ -434,7 +434,7 @@ module ActionDispatch def test_generate_with_name path = Path::Pattern.from_string '/:controller(/:action)' - @router.routes.add_route @app, path, {}, [], {}, "tasks" + add_route @app, path, {}, [], {}, "tasks" path, params = @formatter.generate( "tasks", @@ -452,7 +452,7 @@ module ActionDispatch define_method("test_recognize_#{expected.keys.map(&:to_s).join('_')}") do path = Path::Pattern.from_string "/:controller(/:action(/:id))" app = Object.new - route = @router.routes.add_route(app, path, {}, [], {}, {}) + route = add_route(app, path, {}, [], {}, {}) env = rails_env 'PATH_INFO' => request_path called = false @@ -474,7 +474,7 @@ module ActionDispatch define_method("test_recognize_#{name}") do path = Path::Pattern.from_string '/:segment/*splat' app = Object.new - route = @router.routes.add_route(app, path, {}, [], {}, {}) + route = add_route(app, path, {}, [], {}, {}) env = rails_env 'PATH_INFO' => request_path called = false @@ -497,7 +497,7 @@ module ActionDispatch true ) app = Object.new - route = @router.routes.add_route(app, path, {}, [], {}, {}) + route = add_route(app, path, {}, [], {}, {}) env = rails_env 'PATH_INFO' => '/admin/users/show/10' called = false @@ -518,7 +518,7 @@ module ActionDispatch def test_recognize_literal path = Path::Pattern.from_string "/books(/:action(.:format))" app = Object.new - route = @router.routes.add_route(app, path, {}, [], {:controller => 'books'}) + route = add_route(app, path, {}, [], {:controller => 'books'}) env = rails_env 'PATH_INFO' => '/books/list.rss' expected = { :controller => 'books', :action => 'list', :format => 'rss' } @@ -536,7 +536,7 @@ module ActionDispatch path = Path::Pattern.from_string "/books(/:action(.:format))" app = Object.new conditions = { request_method: 'HEAD' } - @router.routes.add_route(app, path, conditions, [], {}) + add_route(app, path, conditions, [], {}) env = rails_env( 'PATH_INFO' => '/books/list.rss', @@ -557,7 +557,7 @@ module ActionDispatch conditions = { :request_method => 'GET' } - @router.routes.add_route(app, path, conditions, [], {}) + add_route(app, path, conditions, [], {}) env = rails_env 'PATH_INFO' => '/books/list.rss', "REQUEST_METHOD" => "HEAD" @@ -574,7 +574,7 @@ module ActionDispatch path = Path::Pattern.from_string "/books(/:action(.:format))" app = Object.new conditions = { request_method: 'GET' } - @router.routes.add_route(app, path, conditions, [], {}) + add_route(app, path, conditions, [], {}) env = rails_env 'PATH_INFO' => '/books/list.rss', "REQUEST_METHOD" => "POST" @@ -589,7 +589,7 @@ module ActionDispatch conditions = conditions.dup conditions[:request_method] = 'POST' - post = @router.routes.add_route(app, path, conditions, [], {}) + post = add_route(app, path, conditions, [], {}) called = false @router.recognize(env) do |r, params| @@ -609,7 +609,7 @@ module ActionDispatch else path end - router.routes.add_route @app, path, {}, [], {}, {} + add_route @app, path, {}, [], {}, {} end end @@ -636,6 +636,12 @@ module ActionDispatch "CONTENT_LENGTH" => "0" }.merge env end + + MyMapping = Struct.new(:application, :path, :conditions, :required_defaults, :defaults) + + def add_route(app, path, conditions, required_defaults, defaults, name = nil) + @routes.add_route(name, MyMapping.new(app, path, conditions, required_defaults, defaults)) + end end end end diff --git a/actionpack/test/journey/routes_test.rb b/actionpack/test/journey/routes_test.rb index 6853cefc01..01566f0148 100644 --- a/actionpack/test/journey/routes_test.rb +++ b/actionpack/test/journey/routes_test.rb @@ -3,16 +3,24 @@ require 'abstract_unit' module ActionDispatch module Journey class TestRoutes < ActiveSupport::TestCase - setup do + attr_reader :routes + + def setup @routes = Routes.new + super + end + + MyMapping = Struct.new(:application, :path, :conditions, :required_defaults, :defaults) + + def add_route(app, path, conditions, required_defaults, defaults, name = nil) + @routes.add_route(name, MyMapping.new(app, path, conditions, required_defaults, defaults)) end def test_clear - routes = Routes.new path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true requirements = { :hello => /world/ } - routes.add_route nil, path, requirements, [], {:id => nil}, {} + add_route nil, path, requirements, [], {:id => nil}, {} assert_not routes.empty? assert_equal 1, routes.length @@ -22,29 +30,27 @@ module ActionDispatch end def test_ast - routes = Routes.new path = Path::Pattern.from_string '/hello' - routes.add_route nil, path, {}, [], {}, {} + add_route nil, path, {}, [], {}, {} ast = routes.ast - routes.add_route nil, path, {}, [], {}, {} + add_route nil, path, {}, [], {}, {} assert_not_equal ast, routes.ast end def test_simulator_changes - routes = Routes.new path = Path::Pattern.from_string '/hello' - routes.add_route nil, path, {}, [], {}, {} + add_route nil, path, {}, [], {}, {} sim = routes.simulator - routes.add_route nil, path, {}, [], {}, {} + add_route nil, path, {}, [], {}, {} assert_not_equal sim, routes.simulator end def test_partition_route path = Path::Pattern.from_string '/hello' - anchored_route = @routes.add_route nil, path, {}, [], {}, {} + anchored_route = add_route nil, path, {}, [], {}, {} assert_equal [anchored_route], @routes.anchored_routes assert_equal [], @routes.custom_routes @@ -52,19 +58,17 @@ module ActionDispatch "/hello/:who", { who: /\d/ }, ['/', '.', '?'], false ) - custom_route = @routes.add_route nil, path, {}, [], {}, {} + custom_route = add_route nil, path, {}, [], {}, {} assert_equal [custom_route], @routes.custom_routes assert_equal [anchored_route], @routes.anchored_routes end def test_first_name_wins - routes = Routes.new - one = Path::Pattern.from_string '/hello' two = Path::Pattern.from_string '/aaron' - routes.add_route nil, one, {}, [], {}, 'aaron' - routes.add_route nil, two, {}, [], {}, 'aaron' + add_route nil, one, {}, [], {}, 'aaron' + add_route nil, two, {}, [], {}, 'aaron' assert_equal '/hello', routes.named_routes['aaron'].path.spec.to_s end -- cgit v1.2.3 From a293812bffbc6e634e1a6e6794e9dec537d522a3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Aug 2015 18:04:49 -0700 Subject: only keep one hash of named routes The outer router object already keeps a hash of named routes, so we should just use that. --- actionpack/test/journey/router_test.rb | 11 ++++++----- actionpack/test/journey/routes_test.rb | 16 ++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index bddfbe7ef0..8a1414de8e 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -8,9 +8,10 @@ module ActionDispatch def setup @app = Routing::RouteSet::Dispatcher.new({}) - @routes = Routes.new - @router = Router.new(@routes) - @formatter = Formatter.new(@routes) + @route_set = ActionDispatch::Routing::RouteSet.new + @routes = @route_set.router.routes + @router = @route_set.router + @formatter = @route_set.formatter end class FakeRequestFeeler < ActionDispatch::Request @@ -184,8 +185,8 @@ module ActionDispatch def test_knows_what_parts_are_missing_from_named_route route_name = "gorby_thunderhorse" - path = Path::Pattern.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) - add_route nil, path, {}, [], {}, route_name + mapper = ActionDispatch::Routing::Mapper.new @route_set + mapper.get "/foo/:id", :as => route_name, :id => /\d+/, :to => "foo#bar" error = assert_raises(ActionController::UrlGenerationError) do @formatter.generate(route_name, { }, { }) diff --git a/actionpack/test/journey/routes_test.rb b/actionpack/test/journey/routes_test.rb index 01566f0148..bbe3228bf2 100644 --- a/actionpack/test/journey/routes_test.rb +++ b/actionpack/test/journey/routes_test.rb @@ -6,7 +6,9 @@ module ActionDispatch attr_reader :routes def setup - @routes = Routes.new + @route_set = ActionDispatch::Routing::RouteSet.new + @routes = @route_set.router.routes + @router = @route_set.router super end @@ -64,13 +66,11 @@ module ActionDispatch end def test_first_name_wins - one = Path::Pattern.from_string '/hello' - two = Path::Pattern.from_string '/aaron' - - add_route nil, one, {}, [], {}, 'aaron' - add_route nil, two, {}, [], {}, 'aaron' - - assert_equal '/hello', routes.named_routes['aaron'].path.spec.to_s + mapper = ActionDispatch::Routing::Mapper.new @route_set + mapper.get "/hello", to: "foo#bar", as: 'aaron' + assert_raise(ArgumentError) do + mapper.get "/aaron", to: "foo#bar", as: 'aaron' + end end end end -- cgit v1.2.3 From 703275ba70efbefb3358052b6ba750443eff1a28 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 15 Aug 2015 14:31:53 -0700 Subject: use the mapper to build the routing table We should build the routes using the user facing API which is `Mapper`. This frees up the library internals to change as we see fit. IOW we shouldn't be testing internals. --- actionpack/test/journey/router_test.rb | 289 ++++++++++----------------------- actionpack/test/journey/routes_test.rb | 45 ++--- 2 files changed, 103 insertions(+), 231 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index 8a1414de8e..d512dae4e7 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -4,7 +4,7 @@ require 'abstract_unit' module ActionDispatch module Journey class TestRouter < ActiveSupport::TestCase - attr_reader :routes + attr_reader :routes, :mapper def setup @app = Routing::RouteSet::Dispatcher.new({}) @@ -12,125 +12,35 @@ module ActionDispatch @routes = @route_set.router.routes @router = @route_set.router @formatter = @route_set.formatter - end - - class FakeRequestFeeler < ActionDispatch::Request - attr_writer :env - attr_accessor :called - - def new env - self.env = env - self - end - - def hello - self.called = true - 'world' - end + @mapper = ActionDispatch::Routing::Mapper.new @route_set end def test_dashes - router = Router.new(routes) - - path = Path::Pattern.build '/foo-bar-baz', {}, ['/.?'], true - - add_route nil, path, {}, [], {:id => nil}, {} + mapper.get '/foo-bar-baz', to: 'foo#bar' env = rails_env 'PATH_INFO' => '/foo-bar-baz' called = false - router.recognize(env) do |r, params| + @router.recognize(env) do |r, params| called = true end assert called end def test_unicode - router = Router.new(routes) + mapper.get '/ほげ', to: 'foo#bar' #match the escaped version of /ほげ - path = Path::Pattern.build '/%E3%81%BB%E3%81%92', {}, ['/.?'], true - - add_route nil, path, {}, [], {:id => nil}, {} - env = rails_env 'PATH_INFO' => '/%E3%81%BB%E3%81%92' called = false - router.recognize(env) do |r, params| + @router.recognize(env) do |r, params| called = true end assert called end - def test_request_class_and_requirements_success - klass = FakeRequestFeeler.new nil - router = Router.new(routes) - - requirements = { :hello => /world/ } - - path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true - - add_route nil, path, requirements, [], {:id => nil}, {} - - env = rails_env({'PATH_INFO' => '/foo/10'}, klass) - router.recognize(env) do |r, params| - assert_equal({:id => '10'}, params) - end - - assert klass.called, 'hello should have been called' - assert_equal env.env, klass.env - end - - def test_request_class_and_requirements_fail - klass = FakeRequestFeeler.new nil - router = Router.new(routes) - - requirements = { :hello => /mom/ } - - path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true - - add_route nil, path, requirements, [], {:id => nil}, {} - - env = rails_env({'PATH_INFO' => '/foo/10'}, klass) - router.recognize(env) do |r, params| - flunk 'route should not be found' - end - - assert klass.called, 'hello should have been called' - assert_equal env.env, klass.env - end - - class CustomPathRequest < ActionDispatch::Request - def path_info - env['custom.path_info'] - end - - def path_info=(x) - env['custom.path_info'] = x - end - end - - def test_request_class_overrides_path_info - router = Router.new(routes) - - path = Path::Pattern.build '/bar', {}, ['/.?'], true - - add_route nil, path, {}, [], {}, {} - - env = rails_env({'PATH_INFO' => '/foo', - 'custom.path_info' => '/bar'}, CustomPathRequest) - - recognized = false - router.recognize(env) do |r, params| - recognized = true - end - - assert recognized, "route should have been recognized" - end - def test_regexp_first_precedence - add_routes @router, [ - Path::Pattern.build("/whois/:domain", {:domain => /\w+\.[\w\.]+/}, ['/', '.', '?'], true), - Path::Pattern.build("/whois/:id(.:format)", {}, ['/', '.', '?'], true) - ] + mapper.get "/whois/:domain", :domain => /\w+\.[\w\.]+/, to: "foo#bar" + mapper.get "/whois/:id(.:format)", to: "foo#baz" env = rails_env 'PATH_INFO' => '/whois/example.com' @@ -142,25 +52,21 @@ module ActionDispatch r = list.first - assert_equal '/whois/:domain', r.path.spec.to_s + assert_equal '/whois/:domain(.:format)', r.path.spec.to_s end def test_required_parts_verified_are_anchored - add_routes @router, [ - Path::Pattern.build("/foo/:id", { :id => /\d/ }, ['/', '.', '?'], false) - ] + mapper.get "/foo/:id", :id => /\d/, anchor: false, to: "foo#bar" assert_raises(ActionController::UrlGenerationError) do - @formatter.generate(nil, { :id => '10' }, { }) + @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => '10' }, { }) end end def test_required_parts_are_verified_when_building - add_routes @router, [ - Path::Pattern.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) - ] + mapper.get "/foo/:id", :id => /\d+/, anchor: false, to: "foo#bar" - path, _ = @formatter.generate(nil, { :id => '10' }, { }) + path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => '10' }, { }) assert_equal '/foo/10', path assert_raises(ActionController::UrlGenerationError) do @@ -169,17 +75,15 @@ module ActionDispatch end def test_only_required_parts_are_verified - add_routes @router, [ - Path::Pattern.build("/foo(/:id)", {:id => /\d/}, ['/', '.', '?'], false) - ] + mapper.get "/foo(/:id)", :id => /\d/, :to => "foo#bar" - path, _ = @formatter.generate(nil, { :id => '10' }, { }) + path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => '10' }, { }) assert_equal '/foo/10', path - path, _ = @formatter.generate(nil, { }, { }) + path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar" }, { }) assert_equal '/foo', path - path, _ = @formatter.generate(nil, { :id => 'aa' }, { }) + path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => 'aa' }, { }) assert_equal '/foo/aa', path end @@ -206,7 +110,7 @@ module ActionDispatch end def test_X_Cascade - add_routes @router, [ "/messages(.:format)" ] + mapper.get "/messages(.:format)", to: "foo#bar" resp = @router.serve(rails_env({ 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/lol' })) assert_equal ['Not Found'], resp.last assert_equal 'pass', resp[1]['X-Cascade'] @@ -227,24 +131,21 @@ module ActionDispatch end def test_defaults_merge_correctly - path = Path::Pattern.from_string '/foo(/:id)' - add_route nil, path, {}, [], {:id => nil}, {} + mapper.get '/foo(/:id)', to: "foo#bar", id: nil env = rails_env 'PATH_INFO' => '/foo/10' @router.recognize(env) do |r, params| - assert_equal({:id => '10'}, params) + assert_equal({:id => '10', :controller => "foo", :action => "bar"}, params) end env = rails_env 'PATH_INFO' => '/foo' @router.recognize(env) do |r, params| - assert_equal({:id => nil}, params) + assert_equal({:id => nil, :controller => "foo", :action => "bar"}, params) end end def test_recognize_with_unbound_regexp - add_routes @router, [ - Path::Pattern.build("/foo", { }, ['/', '.', '?'], false) - ] + mapper.get "/foo", anchor: false, to: "foo#bar" env = rails_env 'PATH_INFO' => '/foo/bar' @@ -255,9 +156,7 @@ module ActionDispatch end def test_bound_regexp_keeps_path_info - add_routes @router, [ - Path::Pattern.build("/foo", { }, ['/', '.', '?'], true) - ] + mapper.get "/foo", to: "foo#bar" env = rails_env 'PATH_INFO' => '/foo' @@ -270,12 +169,14 @@ module ActionDispatch end def test_path_not_found - add_routes @router, [ + [ "/messages(.:format)", "/messages/new(.:format)", "/messages/:id/edit(.:format)", "/messages/:id(.:format)" - ] + ].each do |path| + mapper.get path, to: "foo#bar" + end env = rails_env 'PATH_INFO' => '/messages/unknown/path' yielded = false @@ -286,32 +187,29 @@ module ActionDispatch end def test_required_part_in_recall - add_routes @router, [ "/messages/:a/:b" ] + mapper.get "/messages/:a/:b", to: "foo#bar" - path, _ = @formatter.generate(nil, { :a => 'a' }, { :b => 'b' }) + path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :a => 'a' }, { :b => 'b' }) assert_equal "/messages/a/b", path end def test_splat_in_recall - add_routes @router, [ "/*path" ] + mapper.get "/*path", to: "foo#bar" - path, _ = @formatter.generate(nil, { }, { :path => 'b' }) + path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar" }, { :path => 'b' }) assert_equal "/b", path end def test_recall_should_be_used_when_scoring - add_routes @router, [ - "/messages/:action(/:id(.:format))", - "/messages/:id(.:format)" - ] + mapper.get "/messages/:action(/:id(.:format))", to: 'foo#bar' + mapper.get "/messages/:id(.:format)", to: 'bar#baz' - path, _ = @formatter.generate(nil, { :id => 10 }, { :action => 'index' }) + path, _ = @formatter.generate(nil, { :controller => "foo", :id => 10 }, { :action => 'index' }) assert_equal "/messages/index/10", path end def test_nil_path_parts_are_ignored - path = Path::Pattern.from_string "/:controller(/:action(.:format))" - add_route @app, path, {}, [], {}, {} + mapper.get "/:controller(/:action(.:format))", to: "tasks#lol" params = { :controller => "tasks", :format => nil } extras = { :action => 'lol' } @@ -323,17 +221,14 @@ module ActionDispatch def test_generate_slash params = [ [:controller, "tasks"], [:action, "show"] ] - path = Path::Pattern.build("/", Hash[params], ['/', '.', '?'], true) - - add_route @app, path, {}, [], {}, {} + mapper.get "/", Hash[params] path, _ = @formatter.generate(nil, Hash[params], {}) assert_equal '/', path end def test_generate_calls_param_proc - path = Path::Pattern.from_string '/:controller(/:action)' - add_route @app, path, {}, [], {}, {} + mapper.get '/:controller(/:action)', to: "foo#bar" parameterized = [] params = [ [:controller, "tasks"], @@ -349,8 +244,7 @@ module ActionDispatch end def test_generate_id - path = Path::Pattern.from_string '/:controller(/:action)' - add_route @app, path, {}, [], {}, {} + mapper.get '/:controller(/:action)', to: 'foo#bar' path, params = @formatter.generate( nil, {:id=>1, :controller=>"tasks", :action=>"show"}, {}) @@ -359,8 +253,7 @@ module ActionDispatch end def test_generate_escapes - path = Path::Pattern.from_string '/:controller(/:action)' - add_route @app, path, {}, [], {}, {} + mapper.get '/:controller(/:action)', to: "foo#bar" path, _ = @formatter.generate(nil, { :controller => "tasks", @@ -370,8 +263,7 @@ module ActionDispatch end def test_generate_escapes_with_namespaced_controller - path = Path::Pattern.from_string '/:controller(/:action)' - add_route @app, path, {}, [], {}, {} + mapper.get '/:controller(/:action)', to: "foo#bar" path, _ = @formatter.generate( nil, { :controller => "admin/tasks", @@ -381,8 +273,7 @@ module ActionDispatch end def test_generate_extra_params - path = Path::Pattern.from_string '/:controller(/:action)' - add_route @app, path, {}, [], {}, {} + mapper.get '/:controller(/:action)', to: "foo#bar" path, params = @formatter.generate( nil, { :id => 1, @@ -395,8 +286,7 @@ module ActionDispatch end def test_generate_missing_keys_no_matches_different_format_keys - path = Path::Pattern.from_string '/:controller/:action/:name' - add_route @app, path, {}, [], {}, {} + mapper.get '/:controller/:action/:name', to: "foo#bar" primarty_parameters = { :id => 1, :controller => "tasks", @@ -422,8 +312,7 @@ module ActionDispatch end def test_generate_uses_recall_if_needed - path = Path::Pattern.from_string '/:controller(/:action(/:id))' - add_route @app, path, {}, [], {}, {} + mapper.get '/:controller(/:action(/:id))', to: "foo#bar" path, params = @formatter.generate( nil, @@ -434,8 +323,7 @@ module ActionDispatch end def test_generate_with_name - path = Path::Pattern.from_string '/:controller(/:action)' - add_route @app, path, {}, [], {}, "tasks" + mapper.get '/:controller(/:action)', to: 'foo#bar', as: 'tasks' path, params = @formatter.generate( "tasks", @@ -451,16 +339,15 @@ module ActionDispatch '/content/show/10' => { :controller => 'content', :action => 'show', :id => "10" }, }.each do |request_path, expected| define_method("test_recognize_#{expected.keys.map(&:to_s).join('_')}") do - path = Path::Pattern.from_string "/:controller(/:action(/:id))" - app = Object.new - route = add_route(app, path, {}, [], {}, {}) + mapper.get "/:controller(/:action(/:id))", to: 'foo#bar' + route = @routes.first env = rails_env 'PATH_INFO' => request_path called = false @router.recognize(env) do |r, params| assert_equal route, r - assert_equal(expected, params) + assert_equal({ :action => "bar" }.merge(expected), params) called = true end @@ -473,16 +360,15 @@ module ActionDispatch :splat => ['/segment/a/b%20c+d', { :segment => 'segment', :splat => 'a/b c+d' }] }.each do |name, (request_path, expected)| define_method("test_recognize_#{name}") do - path = Path::Pattern.from_string '/:segment/*splat' - app = Object.new - route = add_route(app, path, {}, [], {}, {}) + mapper.get '/:segment/*splat', to: 'foo#bar' env = rails_env 'PATH_INFO' => request_path called = false + route = @routes.first @router.recognize(env) do |r, params| assert_equal route, r - assert_equal(expected, params) + assert_equal(expected.merge(:controller=>"foo", :action=>"bar"), params) called = true end @@ -491,14 +377,8 @@ module ActionDispatch end def test_namespaced_controller - path = Path::Pattern.build( - "/:controller(/:action(/:id))", - { :controller => /.+?/ }, - ["/", ".", "?"], - true - ) - app = Object.new - route = add_route(app, path, {}, [], {}, {}) + mapper.get "/:controller(/:action(/:id))", { :controller => /.+?/ } + route = @routes.first env = rails_env 'PATH_INFO' => '/admin/users/show/10' called = false @@ -517,9 +397,8 @@ module ActionDispatch end def test_recognize_literal - path = Path::Pattern.from_string "/books(/:action(.:format))" - app = Object.new - route = add_route(app, path, {}, [], {:controller => 'books'}) + mapper.get "/books(/:action(.:format))", controller: "books" + route = @routes.first env = rails_env 'PATH_INFO' => '/books/list.rss' expected = { :controller => 'books', :action => 'list', :format => 'rss' } @@ -534,10 +413,7 @@ module ActionDispatch end def test_recognize_head_route - path = Path::Pattern.from_string "/books(/:action(.:format))" - app = Object.new - conditions = { request_method: 'HEAD' } - add_route(app, path, conditions, [], {}) + mapper.match "/books(/:action(.:format))", via: 'head', to: 'foo#bar' env = rails_env( 'PATH_INFO' => '/books/list.rss', @@ -553,12 +429,7 @@ module ActionDispatch end def test_recognize_head_request_as_get_route - path = Path::Pattern.from_string "/books(/:action(.:format))" - app = Object.new - conditions = { - :request_method => 'GET' - } - add_route(app, path, conditions, [], {}) + mapper.get "/books(/:action(.:format))", to: 'foo#bar' env = rails_env 'PATH_INFO' => '/books/list.rss', "REQUEST_METHOD" => "HEAD" @@ -571,11 +442,8 @@ module ActionDispatch assert called end - def test_recognize_cares_about_verbs - path = Path::Pattern.from_string "/books(/:action(.:format))" - app = Object.new - conditions = { request_method: 'GET' } - add_route(app, path, conditions, [], {}) + def test_recognize_cares_about_get_verbs + mapper.match "/books(/:action(.:format))", to: "foo#bar", via: :get env = rails_env 'PATH_INFO' => '/books/list.rss', "REQUEST_METHOD" => "POST" @@ -586,21 +454,48 @@ module ActionDispatch end assert_not called + end - conditions = conditions.dup - conditions[:request_method] = 'POST' + def test_recognize_cares_about_post_verbs + mapper.match "/books(/:action(.:format))", to: "foo#bar", via: :post - post = add_route(app, path, conditions, [], {}) + env = rails_env 'PATH_INFO' => '/books/list.rss', + "REQUEST_METHOD" => "POST" called = false @router.recognize(env) do |r, params| - assert_equal post, r called = true end assert called end + def test_multi_verb_recognition + mapper.match "/books(/:action(.:format))", to: "foo#bar", via: [:post, :get] + + %w( POST GET ).each do |verb| + env = rails_env 'PATH_INFO' => '/books/list.rss', + "REQUEST_METHOD" => verb + + called = false + @router.recognize(env) do |r, params| + called = true + end + + assert called + end + + env = rails_env 'PATH_INFO' => '/books/list.rss', + "REQUEST_METHOD" => 'PUT' + + called = false + @router.recognize(env) do |r, params| + called = true + end + + assert_not called + end + private def add_routes router, paths, anchor = true @@ -637,12 +532,6 @@ module ActionDispatch "CONTENT_LENGTH" => "0" }.merge env end - - MyMapping = Struct.new(:application, :path, :conditions, :required_defaults, :defaults) - - def add_route(app, path, conditions, required_defaults, defaults, name = nil) - @routes.add_route(name, MyMapping.new(app, path, conditions, required_defaults, defaults)) - end end end end diff --git a/actionpack/test/journey/routes_test.rb b/actionpack/test/journey/routes_test.rb index bbe3228bf2..f8293dfc5f 100644 --- a/actionpack/test/journey/routes_test.rb +++ b/actionpack/test/journey/routes_test.rb @@ -3,27 +3,19 @@ require 'abstract_unit' module ActionDispatch module Journey class TestRoutes < ActiveSupport::TestCase - attr_reader :routes + attr_reader :routes, :mapper def setup @route_set = ActionDispatch::Routing::RouteSet.new @routes = @route_set.router.routes @router = @route_set.router + @mapper = ActionDispatch::Routing::Mapper.new @route_set super end - MyMapping = Struct.new(:application, :path, :conditions, :required_defaults, :defaults) - - def add_route(app, path, conditions, required_defaults, defaults, name = nil) - @routes.add_route(name, MyMapping.new(app, path, conditions, required_defaults, defaults)) - end - def test_clear - path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true - requirements = { :hello => /world/ } - - add_route nil, path, requirements, [], {:id => nil}, {} - assert_not routes.empty? + mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron' + assert_not_predicate routes, :empty? assert_equal 1, routes.length routes.clear @@ -32,41 +24,32 @@ module ActionDispatch end def test_ast - path = Path::Pattern.from_string '/hello' - - add_route nil, path, {}, [], {}, {} + mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron' ast = routes.ast - add_route nil, path, {}, [], {}, {} + mapper.get "/foo(/:id)", to: "foo#bar", as: 'gorby' assert_not_equal ast, routes.ast end def test_simulator_changes - path = Path::Pattern.from_string '/hello' - - add_route nil, path, {}, [], {}, {} + mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron' sim = routes.simulator - add_route nil, path, {}, [], {}, {} + mapper.get "/foo(/:id)", to: "foo#bar", as: 'gorby' assert_not_equal sim, routes.simulator end def test_partition_route - path = Path::Pattern.from_string '/hello' + mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron' - anchored_route = add_route nil, path, {}, [], {}, {} - assert_equal [anchored_route], @routes.anchored_routes - assert_equal [], @routes.custom_routes + assert_equal 1, @routes.anchored_routes.length + assert_predicate @routes.custom_routes, :empty? - path = Path::Pattern.build( - "/hello/:who", { who: /\d/ }, ['/', '.', '?'], false - ) + mapper.get "/hello/:who", to: "foo#bar", as: 'bar', who: /\d/ - custom_route = add_route nil, path, {}, [], {}, {} - assert_equal [custom_route], @routes.custom_routes - assert_equal [anchored_route], @routes.anchored_routes + assert_equal 1, @routes.custom_routes.length + assert_equal 1, @routes.anchored_routes.length end def test_first_name_wins - mapper = ActionDispatch::Routing::Mapper.new @route_set mapper.get "/hello", to: "foo#bar", as: 'aaron' assert_raise(ArgumentError) do mapper.get "/aaron", to: "foo#bar", as: 'aaron' -- cgit v1.2.3 From e9777ef62e95be79fee01fea9e7420726d5ff792 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 17 Aug 2015 13:29:54 -0700 Subject: default pattern to use a joined string The string we create is almost always the same, so rather than joining all the time, lets join once, then reuse that string everywhere. --- actionpack/test/journey/path/pattern_test.rb | 26 ++++++++++++++------------ actionpack/test/journey/route_test.rb | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/journey/path/pattern_test.rb b/actionpack/test/journey/path/pattern_test.rb index 7b97379bd5..72858f5eda 100644 --- a/actionpack/test/journey/path/pattern_test.rb +++ b/actionpack/test/journey/path/pattern_test.rb @@ -4,6 +4,8 @@ module ActionDispatch module Journey module Path class TestPattern < ActiveSupport::TestCase + SEPARATORS = ["/", ".", "?"].join + x = /.+/ { '/:controller(/:action)' => %r{\A/(#{x})(?:/([^/.?]+))?\Z}, @@ -22,7 +24,7 @@ module ActionDispatch path = Pattern.build( path, { :controller => /.+/ }, - ["/", ".", "?"], + SEPARATORS, true ) assert_equal(expected, path.to_regexp) @@ -46,7 +48,7 @@ module ActionDispatch path = Pattern.build( path, { :controller => /.+/ }, - ["/", ".", "?"], + SEPARATORS, false ) assert_equal(expected, path.to_regexp) @@ -69,7 +71,7 @@ module ActionDispatch path = Pattern.build( path, { :controller => /.+/ }, - ["/", ".", "?"], + SEPARATORS, true ) assert_equal(expected, path.names) @@ -84,7 +86,7 @@ module ActionDispatch (tender|love #MAO )/x }, - ["/", ".", "?"], + SEPARATORS, true ) assert_match(path, '/page/tender') @@ -107,7 +109,7 @@ module ActionDispatch path = Pattern.build( '/:name', { :name => /\d+/ }, - ["/", ".", "?"], + SEPARATORS, true ) assert_match(path, '/123') @@ -118,7 +120,7 @@ module ActionDispatch path = Pattern.build( '/page/:name', { :name => /(tender|love)/ }, - ["/", ".", "?"], + SEPARATORS, true ) assert_match(path, '/page/tender') @@ -131,7 +133,7 @@ module ActionDispatch path = Pattern.build( '/page/:name/:value', requirements, - ["/", ".", "?"], + SEPARATORS, true ) @@ -146,7 +148,7 @@ module ActionDispatch path = Pattern.build( '/page/:name', { :name => /(tender|love)/ }, - ["/", ".", "?"], + SEPARATORS, true ) match = path.match '/page/tender' @@ -158,7 +160,7 @@ module ActionDispatch path = Pattern.build( '/page/:name/:id', { :name => /t(((ender|love)))()/ }, - ["/", ".", "?"], + SEPARATORS, true ) match = path.match '/page/tender/10' @@ -173,7 +175,7 @@ module ActionDispatch path = Pattern.build( '/page/*foo', { :foo => z }, - ["/", ".", "?"], + SEPARATORS, true ) assert_equal(%r{\A/page/(#{z})\Z}, path.to_regexp) @@ -183,7 +185,7 @@ module ActionDispatch path = Pattern.build( '/page/:name/aaron', { :name => /(tender|love)/i }, - ["/", ".", "?"], + SEPARATORS, true ) assert_match(path, '/page/TENDER/aaron') @@ -192,7 +194,7 @@ module ActionDispatch end def test_to_regexp_with_strexp - path = Pattern.build('/:controller', { }, ["/", ".", "?"], true) + path = Pattern.build('/:controller', { }, SEPARATORS, true) x = %r{\A/([^/.?]+)\Z} assert_equal(x.source, path.source) diff --git a/actionpack/test/journey/route_test.rb b/actionpack/test/journey/route_test.rb index cdd59a3316..75e41193b4 100644 --- a/actionpack/test/journey/route_test.rb +++ b/actionpack/test/journey/route_test.rb @@ -26,7 +26,7 @@ module ActionDispatch end def test_path_requirements_override_defaults - path = Path::Pattern.build(':name', { name: /love/ }, ['/'], true) + path = Path::Pattern.build(':name', { name: /love/ }, '/', true) defaults = { name: 'tender' } route = Route.new('name', nil, path, nil, [], defaults) assert_equal(/love/, route.requirements[:name]) -- cgit v1.2.3 From 1ce74b009f0a5bbb9e5f5fe1c037c77437fd0be9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 17 Aug 2015 16:07:39 -0700 Subject: introduce an alternate constructor for Route objects I want to change the real constructor to take a particular parameter for matching the request method --- actionpack/test/journey/route_test.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/journey/route_test.rb b/actionpack/test/journey/route_test.rb index 75e41193b4..dcb82a6741 100644 --- a/actionpack/test/journey/route_test.rb +++ b/actionpack/test/journey/route_test.rb @@ -7,7 +7,7 @@ module ActionDispatch app = Object.new path = Path::Pattern.from_string '/:controller(/:action(/:id(.:format)))' defaults = {} - route = Route.new("name", app, path, {}, [], defaults) + route = Route.build("name", app, path, {}, [], defaults) assert_equal app, route.app assert_equal path, route.path @@ -18,7 +18,7 @@ module ActionDispatch app = Object.new path = Path::Pattern.from_string '/:controller(/:action(/:id(.:format)))' defaults = {} - route = Route.new("name", app, path, {}, [], defaults) + route = Route.build("name", app, path, {}, [], defaults) route.ast.grep(Nodes::Terminal).each do |node| assert_equal route, node.memo @@ -28,27 +28,27 @@ module ActionDispatch def test_path_requirements_override_defaults path = Path::Pattern.build(':name', { name: /love/ }, '/', true) defaults = { name: 'tender' } - route = Route.new('name', nil, path, nil, [], defaults) + route = Route.build('name', nil, path, nil, [], defaults) assert_equal(/love/, route.requirements[:name]) end def test_ip_address path = Path::Pattern.from_string '/messages/:id(.:format)' - route = Route.new("name", nil, path, {:ip => '192.168.1.1'}, [], + route = Route.build("name", nil, path, {:ip => '192.168.1.1'}, [], { :controller => 'foo', :action => 'bar' }) assert_equal '192.168.1.1', route.ip end def test_default_ip path = Path::Pattern.from_string '/messages/:id(.:format)' - route = Route.new("name", nil, path, {}, [], + route = Route.build("name", nil, path, {}, [], { :controller => 'foo', :action => 'bar' }) assert_equal(//, route.ip) end def test_format_with_star path = Path::Pattern.from_string '/:controller/*extra' - route = Route.new("name", nil, path, {}, [], + route = Route.build("name", nil, path, {}, [], { :controller => 'foo', :action => 'bar' }) assert_equal '/foo/himom', route.format({ :controller => 'foo', @@ -58,7 +58,7 @@ module ActionDispatch def test_connects_all_match path = Path::Pattern.from_string '/:controller(/:action(/:id(.:format)))' - route = Route.new("name", nil, path, {:action => 'bar'}, [], { :controller => 'foo' }) + route = Route.build("name", nil, path, {:action => 'bar'}, [], { :controller => 'foo' }) assert_equal '/foo/bar/10', route.format({ :controller => 'foo', @@ -69,21 +69,21 @@ module ActionDispatch def test_extras_are_not_included_if_optional path = Path::Pattern.from_string '/page/:id(/:action)' - route = Route.new("name", nil, path, { }, [], { :action => 'show' }) + route = Route.build("name", nil, path, { }, [], { :action => 'show' }) assert_equal '/page/10', route.format({ :id => 10 }) end def test_extras_are_not_included_if_optional_with_parameter path = Path::Pattern.from_string '(/sections/:section)/pages/:id' - route = Route.new("name", nil, path, { }, [], { :action => 'show' }) + route = Route.build("name", nil, path, { }, [], { :action => 'show' }) assert_equal '/pages/10', route.format({:id => 10}) end def test_extras_are_not_included_if_optional_parameter_is_nil path = Path::Pattern.from_string '(/sections/:section)/pages/:id' - route = Route.new("name", nil, path, { }, [], { :action => 'show' }) + route = Route.build("name", nil, path, { }, [], { :action => 'show' }) assert_equal '/pages/10', route.format({:id => 10, :section => nil}) end @@ -93,10 +93,10 @@ module ActionDispatch defaults = {:controller=>"pages", :action=>"show"} path = Path::Pattern.from_string "/page/:id(/:action)(.:format)" - specific = Route.new "name", nil, path, constraints, [:controller, :action], defaults + specific = Route.build "name", nil, path, constraints, [:controller, :action], defaults path = Path::Pattern.from_string "/:controller(/:action(/:id))(.:format)" - generic = Route.new "name", nil, path, constraints, [], {} + generic = Route.build "name", nil, path, constraints, [], {} knowledge = {:id=>20, :controller=>"pages", :action=>"show"} -- cgit v1.2.3 From c42db41f54adbcd981cbd4cc725e342fb3591176 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 17 Aug 2015 16:30:53 -0700 Subject: routes are always constructed with a hash for the conditions --- actionpack/test/controller/resources_test.rb | 2 +- actionpack/test/dispatch/mapper_test.rb | 4 ++-- actionpack/test/journey/route_test.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 04d6cc1792..2bdbbad38c 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -505,7 +505,7 @@ class ResourcesTest < ActionController::TestCase routes = @routes.routes routes.each do |route| routes.each do |r| - next if route === r # skip the comparison instance + next if route == r # skip the comparison instance assert_not_equal [route.conditions, route.path.spec.to_s], [r.conditions, r.path.spec.to_s] end end diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index eca4ca8e0e..f35ffd8845 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -82,7 +82,7 @@ module ActionDispatch end assert_equal({:omg=>:awesome, :controller=>"posts", :action=>"index"}, fakeset.defaults.first) - assert_equal(/^GET$/, fakeset.conditions.first[:request_method]) + assert_equal(/^GET$/, fakeset.routes.first.verb) end def test_mapping_requirements @@ -99,7 +99,7 @@ module ActionDispatch mapper.scope(via: :put) do mapper.match '/', :to => 'posts#index', :as => :main end - assert_equal(/^PUT$/, fakeset.conditions.first[:request_method]) + assert_equal(/^PUT$/, fakeset.routes.first.verb) end def test_map_slash diff --git a/actionpack/test/journey/route_test.rb b/actionpack/test/journey/route_test.rb index dcb82a6741..22c3b8113d 100644 --- a/actionpack/test/journey/route_test.rb +++ b/actionpack/test/journey/route_test.rb @@ -28,7 +28,7 @@ module ActionDispatch def test_path_requirements_override_defaults path = Path::Pattern.build(':name', { name: /love/ }, '/', true) defaults = { name: 'tender' } - route = Route.build('name', nil, path, nil, [], defaults) + route = Route.build('name', nil, path, {}, [], defaults) assert_equal(/love/, route.requirements[:name]) end -- cgit v1.2.3 From 23cfdd4b71e4284e3efb29a37b2260e2ec77ddc9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 17 Aug 2015 16:36:31 -0700 Subject: test the verb method on the route, specifically --- actionpack/test/controller/resources_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 2bdbbad38c..dd7c128566 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -506,7 +506,7 @@ class ResourcesTest < ActionController::TestCase routes.each do |route| routes.each do |r| next if route == r # skip the comparison instance - assert_not_equal [route.conditions, route.path.spec.to_s], [r.conditions, r.path.spec.to_s] + assert_not_equal [route.conditions, route.path.spec.to_s, route.verb], [r.conditions, r.path.spec.to_s, r.verb] end end end -- cgit v1.2.3 From 4d9475bef91d1df675750aabc13de23c6eff9e92 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 18 Aug 2015 15:20:19 -0700 Subject: symbols will always be constructed with strings. :bomb: --- actionpack/test/journey/nodes/symbol_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/journey/nodes/symbol_test.rb b/actionpack/test/journey/nodes/symbol_test.rb index d411a5018a..adf85b860c 100644 --- a/actionpack/test/journey/nodes/symbol_test.rb +++ b/actionpack/test/journey/nodes/symbol_test.rb @@ -5,7 +5,7 @@ module ActionDispatch module Nodes class TestSymbol < ActiveSupport::TestCase def test_default_regexp? - sym = Symbol.new nil + sym = Symbol.new "foo" assert sym.default_regexp? sym.regexp = nil -- cgit v1.2.3 From 7187339854d8454fdb3338b3041f89c6ce7e1e41 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 18 Aug 2015 16:33:18 -0700 Subject: make the routes reader private nobody should be touching the routes hash without going through the NamedRouteCollection object. --- actionpack/test/dispatch/mount_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/mount_test.rb b/actionpack/test/dispatch/mount_test.rb index 6a439be2b5..d027f09762 100644 --- a/actionpack/test/dispatch/mount_test.rb +++ b/actionpack/test/dispatch/mount_test.rb @@ -49,7 +49,7 @@ class TestRoutingMount < ActionDispatch::IntegrationTest def test_app_name_is_properly_generated_when_engine_is_mounted_in_resources assert Router.mounted_helpers.method_defined?(:user_fake_mounted_at_resource), "A mounted helper should be defined with a parent's prefix" - assert Router.named_routes.routes[:user_fake_mounted_at_resource], + assert Router.named_routes.key?(:user_fake_mounted_at_resource), "A named route should be defined with a parent's prefix" end -- cgit v1.2.3 From 51211a94bd7a34d80f2412a7f94fefe7366647a5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 20 Aug 2015 13:43:57 -0700 Subject: point at rack master --- actionpack/test/dispatch/request/session_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request/session_test.rb b/actionpack/test/dispatch/request/session_test.rb index 10fb04e230..8bcc07dd04 100644 --- a/actionpack/test/dispatch/request/session_test.rb +++ b/actionpack/test/dispatch/request/session_test.rb @@ -7,7 +7,7 @@ module ActionDispatch def test_create_adds_itself_to_env env = {} s = Session.create(store, env, {}) - assert_equal s, env[Rack::Session::Abstract::ENV_SESSION_KEY] + assert_equal s, env[Rack::RACK_SESSION] end def test_to_hash -- cgit v1.2.3 From c6cfcc6124fdef4df3a406f389ba32be486cd437 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 20 Aug 2015 15:52:53 -0700 Subject: move header allocation to a helper method I'm going to change the constructor, so it's easier to do it in one place. --- actionpack/test/dispatch/header_test.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb index e2b38c23bc..782c2cb11d 100644 --- a/actionpack/test/dispatch/header_test.rb +++ b/actionpack/test/dispatch/header_test.rb @@ -1,15 +1,19 @@ require "abstract_unit" class HeaderTest < ActiveSupport::TestCase + def make_headers(hash) + ActionDispatch::Http::Headers.new hash + end + setup do - @headers = ActionDispatch::Http::Headers.new( + @headers = make_headers( "CONTENT_TYPE" => "text/plain", "HTTP_REFERER" => "/some/page" ) end test "#new does not normalize the data" do - headers = ActionDispatch::Http::Headers.new( + headers = make_headers( "Content-Type" => "application/json", "HTTP_REFERER" => "/some/page", "Host" => "http://test.com") @@ -108,7 +112,7 @@ class HeaderTest < ActiveSupport::TestCase end test "env variables with . are not modified" do - headers = ActionDispatch::Http::Headers.new + headers = make_headers({}) headers.merge! "rack.input" => "", "rack.request.cookie_hash" => "", "action_dispatch.logger" => "" @@ -119,7 +123,7 @@ class HeaderTest < ActiveSupport::TestCase end test "symbols are treated as strings" do - headers = ActionDispatch::Http::Headers.new + headers = make_headers({}) headers.merge!(:SERVER_NAME => "example.com", "HTTP_REFERER" => "/", :Host => "test.com") @@ -130,7 +134,7 @@ class HeaderTest < ActiveSupport::TestCase test "headers directly modifies the passed environment" do env = {"HTTP_REFERER" => "/"} - headers = ActionDispatch::Http::Headers.new(env) + headers = make_headers(env) headers['Referer'] = "http://example.com/" headers.merge! "CONTENT_TYPE" => "text/plain" assert_equal({"HTTP_REFERER"=>"http://example.com/", -- cgit v1.2.3 From 34fa6658dd1b779b21e586f01ee64c6f59ca1537 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 20 Aug 2015 15:57:15 -0700 Subject: pass a request object to the headers object --- actionpack/test/dispatch/header_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb index 782c2cb11d..79600b654b 100644 --- a/actionpack/test/dispatch/header_test.rb +++ b/actionpack/test/dispatch/header_test.rb @@ -2,7 +2,7 @@ require "abstract_unit" class HeaderTest < ActiveSupport::TestCase def make_headers(hash) - ActionDispatch::Http::Headers.new hash + ActionDispatch::Http::Headers.new ActionDispatch::Request.new hash end setup do -- cgit v1.2.3 From 4276b214f8a13a38ac7dc4911e90d295a8e40d5a Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 22 Aug 2015 09:44:12 -0400 Subject: Refactor to remove controller class from route to request This refactoring moves the controller class name that was on the route set to the request. The purpose of this refactoring is for changes we need to move controller tests to integration tests, mainly being able to access the controller on the request instead of having to go through the router. [Eileen M. Uchitelle & Aaron Patterson] --- actionpack/test/abstract_unit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 60e2cea8a2..fa0b6087ba 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -122,7 +122,7 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase class StubDispatcher < ::ActionDispatch::Routing::RouteSet::Dispatcher protected def controller_reference(controller_param) - controller_param + controller_param.params[:controller] end def dispatch(controller, action, env) -- cgit v1.2.3 From 5fe141638f1243ac6ae187ae14aa398b4c1875a2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 22 Aug 2015 17:57:45 -0700 Subject: use a request object in the session middleware This commit allows us to use one request object rather than allocating multiple request objects to deal with the session. --- actionpack/test/dispatch/request/session_test.rb | 40 ++++++++++++---------- .../test/dispatch/session/abstract_store_test.rb | 6 ++-- 2 files changed, 24 insertions(+), 22 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request/session_test.rb b/actionpack/test/dispatch/request/session_test.rb index 8bcc07dd04..410e3194e2 100644 --- a/actionpack/test/dispatch/request/session_test.rb +++ b/actionpack/test/dispatch/request/session_test.rb @@ -4,40 +4,42 @@ require 'action_dispatch/middleware/session/abstract_store' module ActionDispatch class Request class SessionTest < ActiveSupport::TestCase + attr_reader :req + + def setup + @req = ActionDispatch::Request.new({}) + end + def test_create_adds_itself_to_env - env = {} - s = Session.create(store, env, {}) - assert_equal s, env[Rack::RACK_SESSION] + s = Session.create(store, req, {}) + assert_equal s, req.env[Rack::RACK_SESSION] end def test_to_hash - env = {} - s = Session.create(store, env, {}) + s = Session.create(store, req, {}) s['foo'] = 'bar' assert_equal 'bar', s['foo'] assert_equal({'foo' => 'bar'}, s.to_hash) end def test_create_merges_old - env = {} - s = Session.create(store, env, {}) + s = Session.create(store, req, {}) s['foo'] = 'bar' - s1 = Session.create(store, env, {}) + s1 = Session.create(store, req, {}) assert_not_equal s, s1 assert_equal 'bar', s1['foo'] end def test_find - env = {} - assert_nil Session.find(env) + assert_nil Session.find(req) - s = Session.create(store, env, {}) - assert_equal s, Session.find(env) + s = Session.create(store, req, {}) + assert_equal s, Session.find(req) end def test_destroy - s = Session.create(store, {}, {}) + s = Session.create(store, req, {}) s['rails'] = 'ftw' s.destroy @@ -46,21 +48,21 @@ module ActionDispatch end def test_keys - s = Session.create(store, {}, {}) + s = Session.create(store, req, {}) s['rails'] = 'ftw' s['adequate'] = 'awesome' assert_equal %w[rails adequate], s.keys end def test_values - s = Session.create(store, {}, {}) + s = Session.create(store, req, {}) s['rails'] = 'ftw' s['adequate'] = 'awesome' assert_equal %w[ftw awesome], s.values end def test_clear - s = Session.create(store, {}, {}) + s = Session.create(store, req, {}) s['rails'] = 'ftw' s['adequate'] = 'awesome' @@ -69,7 +71,7 @@ module ActionDispatch end def test_update - s = Session.create(store, {}, {}) + s = Session.create(store, req, {}) s['rails'] = 'ftw' s.update(:rails => 'awesome') @@ -79,7 +81,7 @@ module ActionDispatch end def test_delete - s = Session.create(store, {}, {}) + s = Session.create(store, req, {}) s['rails'] = 'ftw' s.delete('rails') @@ -88,7 +90,7 @@ module ActionDispatch end def test_fetch - session = Session.create(store, {}, {}) + session = Session.create(store, req, {}) session['one'] = '1' assert_equal '1', session.fetch(:one) diff --git a/actionpack/test/dispatch/session/abstract_store_test.rb b/actionpack/test/dispatch/session/abstract_store_test.rb index fe1a7b4f86..1c35144e6f 100644 --- a/actionpack/test/dispatch/session/abstract_store_test.rb +++ b/actionpack/test/dispatch/session/abstract_store_test.rb @@ -27,7 +27,7 @@ module ActionDispatch as.call(env) assert @env - assert Request::Session.find @env + assert Request::Session.find ActionDispatch::Request.new @env end def test_new_session_object_is_merged_with_old @@ -36,11 +36,11 @@ module ActionDispatch as.call(env) assert @env - session = Request::Session.find @env + session = Request::Session.find ActionDispatch::Request.new @env session['foo'] = 'bar' as.call(@env) - session1 = Request::Session.find @env + session1 = Request::Session.find ActionDispatch::Request.new @env assert_not_equal session, session1 assert_equal session.to_hash, session1.to_hash -- cgit v1.2.3