aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorJon Moss <me@jonathanmoss.me>2016-03-17 16:19:12 -0400
committerJon Moss <me@jonathanmoss.me>2016-03-19 21:52:45 -0400
commit6c6a22176f01b563a7b731fee9f37c837ba83320 (patch)
tree988c98e2cce707f0b554e8cbce14dfa871e43dae /railties/test
parent47c0a3990a44bbf678e06605eb77f000147dac70 (diff)
downloadrails-6c6a22176f01b563a7b731fee9f37c837ba83320.tar.gz
rails-6c6a22176f01b563a7b731fee9f37c837ba83320.tar.bz2
rails-6c6a22176f01b563a7b731fee9f37c837ba83320.zip
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
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/middleware/flash_test.rb46
1 files changed, 46 insertions, 0 deletions
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