2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2017-09-23 17:18:01 -04:00
|
|
|
require "active_support/messages/rotation_configuration"
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2009-01-07 16:23:10 -05:00
|
|
|
class FlashTest < ActionController::TestCase
|
2004-11-23 20:04:44 -05:00
|
|
|
class TestController < ActionController::Base
|
|
|
|
def set_flash
|
|
|
|
flash["that"] = "hello"
|
2016-08-06 13:35:13 -04:00
|
|
|
render inline: "hello"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2005-03-20 14:12:53 -05:00
|
|
|
def set_flash_now
|
|
|
|
flash.now["that"] = "hello"
|
2005-10-26 09:14:10 -04:00
|
|
|
flash.now["foo"] ||= "bar"
|
|
|
|
flash.now["foo"] ||= "err"
|
|
|
|
@flashy = flash.now["that"]
|
2005-03-20 14:12:53 -05:00
|
|
|
@flash_copy = {}.update flash
|
2016-08-06 13:35:13 -04:00
|
|
|
render inline: "hello"
|
2005-03-20 14:12:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def attempt_to_use_flash_now
|
|
|
|
@flash_copy = {}.update flash
|
|
|
|
@flashy = flash["that"]
|
2016-08-06 13:35:13 -04:00
|
|
|
render inline: "hello"
|
2005-03-20 14:12:53 -05:00
|
|
|
end
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def use_flash
|
2005-03-20 14:12:53 -05:00
|
|
|
@flash_copy = {}.update flash
|
2004-11-23 20:04:44 -05:00
|
|
|
@flashy = flash["that"]
|
2016-08-06 13:35:13 -04:00
|
|
|
render inline: "hello"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def use_flash_and_keep_it
|
2005-03-20 14:12:53 -05:00
|
|
|
@flash_copy = {}.update flash
|
2004-11-23 20:04:44 -05:00
|
|
|
@flashy = flash["that"]
|
2007-09-09 17:54:59 -04:00
|
|
|
flash.keep
|
2016-08-06 13:35:13 -04:00
|
|
|
render inline: "hello"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2009-12-21 18:29:59 -05:00
|
|
|
|
2007-05-06 00:17:01 -04:00
|
|
|
def use_flash_and_update_it
|
|
|
|
flash.update("this" => "hello again")
|
|
|
|
@flash_copy = {}.update flash
|
2016-08-06 13:35:13 -04:00
|
|
|
render inline: "hello"
|
2007-05-06 00:17:01 -04:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2006-07-21 22:31:21 -04:00
|
|
|
def use_flash_after_reset_session
|
|
|
|
flash["that"] = "hello"
|
|
|
|
@flashy_that = flash["that"]
|
|
|
|
reset_session
|
|
|
|
@flashy_that_reset = flash["that"]
|
|
|
|
flash["this"] = "good-bye"
|
|
|
|
@flashy_this = flash["this"]
|
2016-08-06 13:35:13 -04:00
|
|
|
render inline: "hello"
|
2006-07-21 22:31:21 -04:00
|
|
|
end
|
|
|
|
|
2012-12-07 15:24:56 -05:00
|
|
|
# methods for test_sweep_after_halted_action_chain
|
2016-08-06 12:54:50 -04:00
|
|
|
before_action :halt_and_redir, only: "filter_halting_action"
|
2007-05-06 00:17:01 -04:00
|
|
|
|
|
|
|
def std_action
|
|
|
|
@flash_copy = {}.update(flash)
|
2015-05-28 08:13:32 -04:00
|
|
|
head :ok
|
2007-05-06 00:17:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def filter_halting_action
|
|
|
|
@flash_copy = {}.update(flash)
|
|
|
|
end
|
|
|
|
|
|
|
|
def halt_and_redir
|
|
|
|
flash["foo"] = "bar"
|
2016-08-06 13:35:13 -04:00
|
|
|
redirect_to action: "std_action"
|
2007-05-06 00:17:01 -04:00
|
|
|
@flash_copy = {}.update(flash)
|
|
|
|
end
|
2009-12-17 19:37:11 -05:00
|
|
|
|
|
|
|
def redirect_with_alert
|
2016-08-06 13:35:13 -04:00
|
|
|
redirect_to "/nowhere", alert: "Beware the nowheres!"
|
2009-12-17 19:37:11 -05:00
|
|
|
end
|
2009-12-21 18:29:59 -05:00
|
|
|
|
2009-12-17 19:37:11 -05:00
|
|
|
def redirect_with_notice
|
2016-08-06 13:35:13 -04:00
|
|
|
redirect_to "/somewhere", notice: "Good luck in the somewheres!"
|
2009-12-17 19:37:11 -05:00
|
|
|
end
|
2009-12-21 18:29:59 -05:00
|
|
|
|
2010-05-15 10:48:31 -04:00
|
|
|
def render_with_flash_now_alert
|
|
|
|
flash.now.alert = "Beware the nowheres now!"
|
2016-08-06 13:35:13 -04:00
|
|
|
render inline: "hello"
|
2010-05-15 10:48:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_with_flash_now_notice
|
|
|
|
flash.now.notice = "Good luck in the somewheres now!"
|
2016-08-06 13:35:13 -04:00
|
|
|
render inline: "hello"
|
2010-05-15 10:48:31 -04:00
|
|
|
end
|
|
|
|
|
2009-12-17 19:37:11 -05:00
|
|
|
def redirect_with_other_flashes
|
2016-08-06 13:35:13 -04:00
|
|
|
redirect_to "/wonderland", flash: { joyride: "Horses!" }
|
2009-12-17 19:37:11 -05:00
|
|
|
end
|
2012-07-06 14:34:56 -04:00
|
|
|
|
|
|
|
def redirect_with_foo_flash
|
2016-08-06 13:35:13 -04:00
|
|
|
redirect_to "/wonderland", foo: "for great justice"
|
2012-07-06 14:34:56 -04:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2009-01-07 16:23:10 -05:00
|
|
|
tests TestController
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
def test_flash
|
2006-02-12 11:29:21 -05:00
|
|
|
get :set_flash
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2006-02-12 11:29:21 -05:00
|
|
|
get :use_flash
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_equal "hello", @controller.instance_variable_get(:@flash_copy)["that"]
|
|
|
|
assert_equal "hello", @controller.instance_variable_get(:@flashy)
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2006-02-12 11:29:21 -05:00
|
|
|
get :use_flash
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_nil @controller.instance_variable_get(:@flash_copy)["that"], "On second flash"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_keep_flash
|
2006-02-12 11:29:21 -05:00
|
|
|
get :set_flash
|
2009-12-21 18:29:59 -05:00
|
|
|
|
2007-09-09 17:54:59 -04:00
|
|
|
get :use_flash_and_keep_it
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_equal "hello", @controller.instance_variable_get(:@flash_copy)["that"]
|
|
|
|
assert_equal "hello", @controller.instance_variable_get(:@flashy)
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2006-02-12 11:29:21 -05:00
|
|
|
get :use_flash
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_equal "hello", @controller.instance_variable_get(:@flash_copy)["that"], "On second flash"
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2006-02-12 11:29:21 -05:00
|
|
|
get :use_flash
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_nil @controller.instance_variable_get(:@flash_copy)["that"], "On third flash"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2009-12-21 18:29:59 -05:00
|
|
|
|
2005-03-20 14:12:53 -05:00
|
|
|
def test_flash_now
|
2006-02-12 11:29:21 -05:00
|
|
|
get :set_flash_now
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_equal "hello", @controller.instance_variable_get(:@flash_copy)["that"]
|
|
|
|
assert_equal "bar", @controller.instance_variable_get(:@flash_copy)["foo"]
|
|
|
|
assert_equal "hello", @controller.instance_variable_get(:@flashy)
|
2005-03-20 14:12:53 -05:00
|
|
|
|
2006-02-12 11:29:21 -05:00
|
|
|
get :attempt_to_use_flash_now
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_nil @controller.instance_variable_get(:@flash_copy)["that"]
|
|
|
|
assert_nil @controller.instance_variable_get(:@flash_copy)["foo"]
|
|
|
|
assert_nil @controller.instance_variable_get(:@flashy)
|
2009-12-21 18:29:59 -05:00
|
|
|
end
|
|
|
|
|
2007-05-06 00:17:01 -04:00
|
|
|
def test_update_flash
|
|
|
|
get :set_flash
|
|
|
|
get :use_flash_and_update_it
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_equal "hello", @controller.instance_variable_get(:@flash_copy)["that"]
|
|
|
|
assert_equal "hello again", @controller.instance_variable_get(:@flash_copy)["this"]
|
2007-05-06 00:17:01 -04:00
|
|
|
get :use_flash
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_nil @controller.instance_variable_get(:@flash_copy)["that"], "On second flash"
|
|
|
|
assert_equal "hello again",
|
|
|
|
@controller.instance_variable_get(:@flash_copy)["this"], "On second flash"
|
2007-05-06 00:17:01 -04:00
|
|
|
end
|
2009-05-28 10:30:49 -04:00
|
|
|
|
2006-07-21 22:31:21 -04:00
|
|
|
def test_flash_after_reset_session
|
|
|
|
get :use_flash_after_reset_session
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_equal "hello", @controller.instance_variable_get(:@flashy_that)
|
|
|
|
assert_equal "good-bye", @controller.instance_variable_get(:@flashy_this)
|
|
|
|
assert_nil @controller.instance_variable_get(:@flashy_that_reset)
|
2009-12-21 18:29:59 -05:00
|
|
|
end
|
2007-05-06 00:17:01 -04:00
|
|
|
|
2009-05-28 10:30:49 -04:00
|
|
|
def test_does_not_set_the_session_if_the_flash_is_empty
|
|
|
|
get :std_action
|
|
|
|
assert_nil session["flash"]
|
|
|
|
end
|
|
|
|
|
2012-12-07 15:24:56 -05:00
|
|
|
def test_sweep_after_halted_action_chain
|
2007-05-06 00:17:01 -04:00
|
|
|
get :std_action
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_nil @controller.instance_variable_get(:@flash_copy)["foo"]
|
2007-05-06 00:17:01 -04:00
|
|
|
get :filter_halting_action
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_equal "bar", @controller.instance_variable_get(:@flash_copy)["foo"]
|
2007-05-06 00:17:01 -04:00
|
|
|
get :std_action # follow redirection
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_equal "bar", @controller.instance_variable_get(:@flash_copy)["foo"]
|
2007-05-06 00:17:01 -04:00
|
|
|
get :std_action
|
2015-05-13 06:28:33 -04:00
|
|
|
assert_nil @controller.instance_variable_get(:@flash_copy)["foo"]
|
2007-05-06 00:17:01 -04:00
|
|
|
end
|
2009-05-27 15:51:33 -04:00
|
|
|
|
|
|
|
def test_keep_and_discard_return_values
|
2010-01-15 15:44:27 -05:00
|
|
|
flash = ActionDispatch::Flash::FlashHash.new
|
2016-08-06 13:35:13 -04:00
|
|
|
flash.update(foo: :foo_indeed, bar: :bar_indeed)
|
2009-05-27 15:51:33 -04:00
|
|
|
|
|
|
|
assert_equal(:foo_indeed, flash.discard(:foo)) # valid key passed
|
2013-11-30 09:57:01 -05:00
|
|
|
assert_nil flash.discard(:unknown) # non existent key passed
|
2016-08-16 03:30:11 -04:00
|
|
|
assert_equal({ "foo" => :foo_indeed, "bar" => :bar_indeed }, flash.discard().to_hash) # nothing passed
|
|
|
|
assert_equal({ "foo" => :foo_indeed, "bar" => :bar_indeed }, flash.discard(nil).to_hash) # nothing passed
|
2009-05-27 15:51:33 -04:00
|
|
|
|
|
|
|
assert_equal(:foo_indeed, flash.keep(:foo)) # valid key passed
|
2013-11-30 09:57:01 -05:00
|
|
|
assert_nil flash.keep(:unknown) # non existent key passed
|
2016-08-16 03:30:11 -04:00
|
|
|
assert_equal({ "foo" => :foo_indeed, "bar" => :bar_indeed }, flash.keep().to_hash) # nothing passed
|
|
|
|
assert_equal({ "foo" => :foo_indeed, "bar" => :bar_indeed }, flash.keep(nil).to_hash) # nothing passed
|
2009-05-27 15:51:33 -04:00
|
|
|
end
|
2009-12-17 19:37:11 -05:00
|
|
|
|
|
|
|
def test_redirect_to_with_alert
|
|
|
|
get :redirect_with_alert
|
2020-09-15 22:20:43 -04:00
|
|
|
assert_equal "Beware the nowheres!", @controller.flash[:alert]
|
2009-12-17 19:37:11 -05:00
|
|
|
end
|
2009-12-21 18:29:59 -05:00
|
|
|
|
2009-12-17 19:37:11 -05:00
|
|
|
def test_redirect_to_with_notice
|
|
|
|
get :redirect_with_notice
|
2020-09-15 22:20:43 -04:00
|
|
|
assert_equal "Good luck in the somewheres!", @controller.flash[:notice]
|
2009-12-17 19:37:11 -05:00
|
|
|
end
|
2009-12-21 18:29:59 -05:00
|
|
|
|
2010-05-15 10:48:31 -04:00
|
|
|
def test_render_with_flash_now_alert
|
|
|
|
get :render_with_flash_now_alert
|
2020-09-15 22:20:43 -04:00
|
|
|
assert_equal "Beware the nowheres now!", @controller.flash[:alert]
|
2010-05-15 10:48:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_with_flash_now_notice
|
|
|
|
get :render_with_flash_now_notice
|
2020-09-15 22:20:43 -04:00
|
|
|
assert_equal "Good luck in the somewheres now!", @controller.flash[:notice]
|
2010-05-15 10:48:31 -04:00
|
|
|
end
|
|
|
|
|
2009-12-17 19:37:11 -05:00
|
|
|
def test_redirect_to_with_other_flashes
|
|
|
|
get :redirect_with_other_flashes
|
2020-09-15 22:20:43 -04:00
|
|
|
assert_equal "Horses!", @controller.flash[:joyride]
|
2009-12-17 19:37:11 -05:00
|
|
|
end
|
2012-07-06 14:34:56 -04:00
|
|
|
|
|
|
|
def test_redirect_to_with_adding_flash_types
|
2014-04-05 14:02:18 -04:00
|
|
|
original_controller = @controller
|
|
|
|
test_controller_with_flash_type_foo = Class.new(TestController) do
|
|
|
|
add_flash_types :foo
|
|
|
|
end
|
|
|
|
@controller = test_controller_with_flash_type_foo.new
|
2012-07-06 14:34:56 -04:00
|
|
|
get :redirect_with_foo_flash
|
2020-09-15 22:20:43 -04:00
|
|
|
assert_equal "for great justice", @controller.flash[:foo]
|
2014-04-05 14:02:18 -04:00
|
|
|
ensure
|
|
|
|
@controller = original_controller
|
2012-07-06 14:34:56 -04:00
|
|
|
end
|
2013-09-13 09:03:38 -04:00
|
|
|
|
2021-07-13 10:04:15 -04:00
|
|
|
def test_additional_flash_types_are_not_listed_in_actions_set
|
|
|
|
test_controller_with_flash_type_foo = Class.new(TestController) do
|
|
|
|
add_flash_types :foo
|
|
|
|
end
|
|
|
|
assert_not_includes test_controller_with_flash_type_foo.action_methods, "foo"
|
|
|
|
end
|
|
|
|
|
2013-09-13 09:03:38 -04:00
|
|
|
def test_add_flash_type_to_subclasses
|
2014-04-05 14:02:18 -04:00
|
|
|
test_controller_with_flash_type_foo = Class.new(TestController) do
|
|
|
|
add_flash_types :foo
|
|
|
|
end
|
|
|
|
subclass_controller_with_no_flash_type = Class.new(test_controller_with_flash_type_foo)
|
2016-09-16 12:44:05 -04:00
|
|
|
assert_includes subclass_controller_with_no_flash_type._flash_types, :foo
|
2013-09-13 09:03:38 -04:00
|
|
|
end
|
|
|
|
|
2014-04-07 01:04:17 -04:00
|
|
|
def test_does_not_add_flash_type_to_parent_class
|
|
|
|
Class.new(TestController) do
|
2014-04-05 14:02:18 -04:00
|
|
|
add_flash_types :bar
|
|
|
|
end
|
2013-09-13 09:03:38 -04:00
|
|
|
assert_not TestController._flash_types.include?(:bar)
|
|
|
|
end
|
2010-01-15 15:44:27 -05:00
|
|
|
end
|
|
|
|
|
2010-09-24 20:15:52 -04:00
|
|
|
class FlashIntegrationTest < ActionDispatch::IntegrationTest
|
2016-08-06 12:54:50 -04:00
|
|
|
SessionKey = "_myapp_session"
|
2019-01-16 20:12:40 -05:00
|
|
|
Generator = ActiveSupport::CachingKeyGenerator.new(
|
|
|
|
ActiveSupport::KeyGenerator.new("b3c631c314c0bbca50c1b2843150fe33", iterations: 1000)
|
2021-05-18 22:26:24 -04:00
|
|
|
)
|
2019-01-16 20:12:40 -05:00
|
|
|
Rotations = ActiveSupport::Messages::RotationConfiguration.new
|
|
|
|
SIGNED_COOKIE_SALT = "signed cookie"
|
2010-01-15 15:44:27 -05:00
|
|
|
|
|
|
|
class TestController < ActionController::Base
|
2012-07-06 14:34:56 -04:00
|
|
|
add_flash_types :bar
|
|
|
|
|
2010-01-15 15:44:27 -05:00
|
|
|
def set_flash
|
|
|
|
flash["that"] = "hello"
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
2011-04-04 20:52:37 -04:00
|
|
|
def set_flash_now
|
|
|
|
flash.now["that"] = "hello"
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
2010-01-15 15:44:27 -05:00
|
|
|
def use_flash
|
2016-08-06 13:35:13 -04:00
|
|
|
render inline: "flash: #{flash["that"]}"
|
2010-01-15 15:44:27 -05:00
|
|
|
end
|
2012-07-06 14:34:56 -04:00
|
|
|
|
|
|
|
def set_bar
|
|
|
|
flash[:bar] = "for great justice"
|
|
|
|
head :ok
|
|
|
|
end
|
2016-08-22 16:34:35 -04:00
|
|
|
|
|
|
|
def set_flash_optionally
|
|
|
|
flash.now.notice = params[:flash]
|
|
|
|
if stale? etag: "abe"
|
|
|
|
render inline: "maybe flash"
|
|
|
|
end
|
|
|
|
end
|
2010-01-15 15:44:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_flash
|
|
|
|
with_test_route_set do
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/set_flash"
|
2010-01-15 15:44:27 -05:00
|
|
|
assert_response :success
|
|
|
|
assert_equal "hello", @request.flash["that"]
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/use_flash"
|
2010-01-15 15:44:27 -05:00
|
|
|
assert_response :success
|
|
|
|
assert_equal "flash: hello", @response.body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-06-25 03:36:26 -04:00
|
|
|
def test_just_using_flash_does_not_stream_a_cookie_back
|
|
|
|
with_test_route_set do
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/use_flash"
|
2010-06-25 03:36:26 -04:00
|
|
|
assert_response :success
|
|
|
|
assert_nil @response.headers["Set-Cookie"]
|
|
|
|
assert_equal "flash: ", @response.body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-19 04:34:17 -04:00
|
|
|
def test_setting_flash_does_not_raise_in_following_requests
|
|
|
|
with_test_route_set do
|
2016-08-06 12:54:50 -04:00
|
|
|
env = { "action_dispatch.request.flash_hash" => ActionDispatch::Flash::FlashHash.new }
|
|
|
|
get "/set_flash", env: env
|
|
|
|
get "/set_flash", env: env
|
2011-04-19 04:34:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-19 14:10:29 -04:00
|
|
|
def test_setting_flash_now_does_not_raise_in_following_requests
|
|
|
|
with_test_route_set do
|
2016-08-06 12:54:50 -04:00
|
|
|
env = { "action_dispatch.request.flash_hash" => ActionDispatch::Flash::FlashHash.new }
|
|
|
|
get "/set_flash_now", env: env
|
|
|
|
get "/set_flash_now", env: env
|
2011-04-19 14:10:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-06 14:34:56 -04:00
|
|
|
def test_added_flash_types_method
|
|
|
|
with_test_route_set do
|
2016-08-06 12:54:50 -04:00
|
|
|
get "/set_bar"
|
2012-07-06 14:34:56 -04:00
|
|
|
assert_response :success
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_equal "for great justice", @controller.bar
|
2012-07-06 14:34:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-22 16:34:35 -04:00
|
|
|
def test_flash_factored_into_etag
|
|
|
|
with_test_route_set do
|
|
|
|
get "/set_flash_optionally"
|
|
|
|
no_flash_etag = response.etag
|
|
|
|
|
|
|
|
get "/set_flash_optionally", params: { flash: "hello!" }
|
|
|
|
hello_flash_etag = response.etag
|
|
|
|
|
|
|
|
assert_not_equal no_flash_etag, hello_flash_etag
|
|
|
|
|
|
|
|
get "/set_flash_optionally", params: { flash: "hello!" }
|
|
|
|
another_hello_flash_etag = response.etag
|
|
|
|
|
|
|
|
assert_equal another_hello_flash_etag, hello_flash_etag
|
|
|
|
|
|
|
|
get "/set_flash_optionally", params: { flash: "goodbye!" }
|
|
|
|
goodbye_flash_etag = response.etag
|
|
|
|
|
|
|
|
assert_not_equal another_hello_flash_etag, goodbye_flash_etag
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-09 12:00:23 -04:00
|
|
|
def test_flash_usable_in_metal_without_helper
|
2018-09-13 18:23:20 -04:00
|
|
|
controller_class = nil
|
|
|
|
|
2018-08-09 12:00:23 -04:00
|
|
|
assert_nothing_raised do
|
2018-09-13 18:23:20 -04:00
|
|
|
controller_class = Class.new(ActionController::Metal) do
|
2018-08-09 12:00:23 -04:00
|
|
|
include ActionController::Flash
|
|
|
|
end
|
|
|
|
end
|
2018-09-13 18:23:20 -04:00
|
|
|
|
|
|
|
controller = controller_class.new
|
|
|
|
|
|
|
|
assert_respond_to controller, :alert
|
|
|
|
assert_respond_to controller, :notice
|
2018-08-09 12:00:23 -04:00
|
|
|
end
|
|
|
|
|
2010-01-15 15:44:27 -05:00
|
|
|
private
|
2010-05-17 19:43:06 -04:00
|
|
|
# Overwrite get to send SessionSecret in env hash
|
2019-09-13 04:36:11 -04:00
|
|
|
def get(path, **options)
|
|
|
|
options[:env] ||= {}
|
|
|
|
options[:env]["action_dispatch.key_generator"] ||= Generator
|
|
|
|
options[:env]["action_dispatch.cookies_rotations"] = Rotations
|
|
|
|
options[:env]["action_dispatch.signed_cookie_salt"] = SIGNED_COOKIE_SALT
|
|
|
|
super(path, **options)
|
2010-05-17 19:43:06 -04:00
|
|
|
end
|
|
|
|
|
2010-01-15 15:44:27 -05:00
|
|
|
def with_test_route_set
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2016-03-01 03:48:53 -05:00
|
|
|
ActiveSupport::Deprecation.silence do
|
2016-08-06 13:35:13 -04:00
|
|
|
get ":action", to: FlashIntegrationTest::TestController
|
2016-03-01 03:48:53 -05:00
|
|
|
end
|
2010-06-25 03:36:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@app = self.class.build_app(set) do |middleware|
|
2016-08-06 13:35:13 -04:00
|
|
|
middleware.use ActionDispatch::Session::CookieStore, key: SessionKey
|
2010-06-25 03:36:26 -04:00
|
|
|
middleware.use ActionDispatch::Flash
|
2015-08-07 18:35:39 -04:00
|
|
|
middleware.delete ActionDispatch::ShowExceptions
|
2010-01-15 15:44:27 -05:00
|
|
|
end
|
2010-06-25 03:36:26 -04:00
|
|
|
|
2010-01-15 15:44:27 -05:00
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|