diff options
Diffstat (limited to 'actionpack/test')
6 files changed, 71 insertions, 13 deletions
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 34fb3b1003..3b89531e90 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -1210,6 +1210,20 @@ class IntegrationRequestEncodersTest < ActionDispatch::IntegrationTest end end + def test_get_parameters_with_as_option + with_routing do |routes| + routes.draw do + ActiveSupport::Deprecation.silence do + get ':action' => FooController + end + end + + get '/foos_json?foo=heyo', as: :json + + assert_equal({ 'foo' => 'heyo' }, response.parsed_body) + end + end + private def post_to_foos(as:) with_routing do |routes| diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index b75eb0e3bf..2eed2996f6 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -369,4 +369,10 @@ class ParametersPermitTest < ActiveSupport::TestCase refute params.permit(foo: [:bar]).has_key?(:foo) refute params.permit(foo: :bar).has_key?(:foo) end + + test '#permitted? is false by default' do + params = ActionController::Parameters.new + + assert_equal false, params.permitted? + end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 8d3134630d..652c06af19 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -2,6 +2,9 @@ require 'abstract_unit' require 'controller/fake_models' class TestControllerWithExtraEtags < ActionController::Base + def self.controller_name; 'test'; end + def self.controller_path; 'test'; end + etag { nil } etag { 'ab' } etag { :cde } @@ -17,7 +20,7 @@ class TestControllerWithExtraEtags < ActionController::Base end def strong - render plain: "stale" if stale?(strong_etag: 'strong') + render plain: "stale" if stale?(strong_etag: 'strong', template: false) end def with_template @@ -25,6 +28,10 @@ class TestControllerWithExtraEtags < ActionController::Base render plain: 'stale' end end + + def with_implicit_template + fresh_when(etag: '123') + end end class ImplicitRenderTestController < ActionController::Base @@ -528,20 +535,28 @@ class EtagRenderTest < ActionController::TestCase get :with_template assert_response :not_modified - # Modify the template digest - path = File.expand_path('../../fixtures/test/hello_world.erb', __FILE__) - old = File.read(path) + modify_template(:hello_world) do + request.if_none_match = etag + get :with_template + assert_response :ok + assert_not_equal etag, @response.etag + end + end - begin - File.write path, 'foo' - ActionView::LookupContext::DetailsKey.clear + def test_etag_reflects_implicit_template_digest + get :with_implicit_template + assert_response :ok + assert_not_nil etag = @response.etag + request.if_none_match = etag + get :with_implicit_template + assert_response :not_modified + + modify_template(:with_implicit_template) do request.if_none_match = etag - get :with_template + get :with_implicit_template assert_response :ok assert_not_equal etag, @response.etag - ensure - File.write path, old end end @@ -553,6 +568,16 @@ class EtagRenderTest < ActionController::TestCase def strong_etag(record) %("#{Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key(record))}") end + + def modify_template(name) + path = File.expand_path("../../fixtures/test/#{name}.erb", __FILE__) + original = File.read(path) + File.write(path, "#{original} Modified!") + ActionView::LookupContext::DetailsKey.clear + yield + ensure + File.write(path, original) + end end class MetalRenderTest < ActionController::TestCase diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 69098326b9..f6dd9272a6 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -102,6 +102,18 @@ module ActionDispatch assert_equal("PUT", fakeset.routes.first.verb) end + def test_to_scope + fakeset = FakeSet.new + mapper = Mapper.new fakeset + mapper.scope(to: "posts#index") do + mapper.get :all + mapper.post :most + end + + assert_equal "posts#index", fakeset.routes.to_a[0].defaults[:to] + assert_equal "posts#index", fakeset.routes.to_a[1].defaults[:to] + end + def test_map_slash fakeset = FakeSet.new mapper = Mapper.new fakeset diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index a07138b55e..6ab71ebc81 100644 --- a/actionpack/test/dispatch/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb @@ -155,7 +155,7 @@ class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest test "parses json params after custom json mime type registered" do begin Mime::Type.unregister :json - Mime::Type.register "application/json", :json, %w(application/vnd.api+json) + Mime::Type.register "application/json", :json, %w(application/vnd.rails+json) assert_parses( {"user" => {"username" => "meinac"}, "username" => "meinac"}, "{\"username\": \"meinac\"}", { 'CONTENT_TYPE' => 'application/json' } @@ -169,10 +169,10 @@ class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest test "parses json params after custom json mime type registered with synonym" do begin Mime::Type.unregister :json - Mime::Type.register "application/json", :json, %w(application/vnd.api+json) + Mime::Type.register "application/json", :json, %w(application/vnd.rails+json) assert_parses( {"user" => {"username" => "meinac"}, "username" => "meinac"}, - "{\"username\": \"meinac\"}", { 'CONTENT_TYPE' => 'application/vnd.api+json' } + "{\"username\": \"meinac\"}", { 'CONTENT_TYPE' => 'application/vnd.rails+json' } ) ensure Mime::Type.unregister :json diff --git a/actionpack/test/fixtures/test/with_implicit_template.erb b/actionpack/test/fixtures/test/with_implicit_template.erb new file mode 100644 index 0000000000..474488cd13 --- /dev/null +++ b/actionpack/test/fixtures/test/with_implicit_template.erb @@ -0,0 +1 @@ +Hello explicitly! |