From 6c6a22176f01b563a7b731fee9f37c837ba83320 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Thu, 17 Mar 2016 16:19:12 -0400 Subject: Fix request.reset_session for API controllers Due to that `ActionDispatch::Flash` (the flash API's middleware) is not included for API controllers, the `request.reset_session` method, which relies on there being a `flash=` method which is in fact defined by the middleware, was previously breaking. Similarly to how add46482a540b33184f3011c5c307f4b8e90c9cc created a method to be overridden by the flash middleware in order to ensure non-breakage, this is how flashes are now reset. Fixes #24222 --- railties/test/application/middleware/flash_test.rb | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 railties/test/application/middleware/flash_test.rb (limited to 'railties/test/application/middleware') diff --git a/railties/test/application/middleware/flash_test.rb b/railties/test/application/middleware/flash_test.rb new file mode 100644 index 0000000000..f5d459c695 --- /dev/null +++ b/railties/test/application/middleware/flash_test.rb @@ -0,0 +1,46 @@ +require 'isolation/abstract_unit' +require 'rack/test' + +module ApplicationTests + class FlashTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + include Rack::Test::Methods + + def setup + build_app + boot_rails + end + + def teardown + teardown_app + end + + test 'calling reset_session on request does not trigger an error for API apps' do + add_to_config 'config.api_only = true' + + controller :test, <<-RUBY + class TestController < ApplicationController + def dump_flash + request.reset_session + render plain: 'It worked!' + end + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + Rails.application.routes.draw do + get '/dump_flash' => "test#dump_flash" + end + RUBY + + app 'development' + + get '/dump_flash' + + assert_equal 200, last_response.status + assert_equal 'It worked!', last_response.body + + refute Rails.application.middleware.include?(ActionDispatch::Flash) + end + end +end -- cgit v1.2.3