1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #42230 from ricardotk002/correct-null-flash-api

Use a regular flash object if session store is disabled
This commit is contained in:
Jean Boussier 2021-05-19 10:46:40 +02:00 committed by GitHub
commit c047e21940
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 20 deletions

View file

@ -199,6 +199,10 @@ module ActionController #:nodoc:
def exists?
true
end
def enabled?
false
end
end
class NullCookieJar < ActionDispatch::Cookies::CookieJar #:nodoc:

View file

@ -211,6 +211,10 @@ module ActionController
@data.fetch(key.to_s, *args, &block)
end
def enabled?
true
end
private
def load!
@id

View file

@ -45,7 +45,6 @@ module ActionDispatch
# read a notice you put there or <tt>flash["notice"] = "hello"</tt>
# to put a new one.
def flash
return Flash::NullFlash unless session.respond_to?(:loaded?)
flash = flash_hash
return flash if flash
self.flash = Flash::FlashHash.from_session_value(session["flash"])
@ -60,16 +59,14 @@ module ActionDispatch
end
def commit_flash # :nodoc:
session = self.session || {}
flash_hash = self.flash_hash
return unless session.enabled?
if flash_hash && (flash_hash.present? || session.key?("flash"))
session["flash"] = flash_hash.to_session_value
self.flash = flash_hash.dup
end
if (!session.respond_to?(:loaded?) || session.loaded?) && # reset_session uses {}, which doesn't implement #loaded?
session.key?("flash") && session["flash"].nil?
if session.loaded? && session.key?("flash") && session["flash"].nil?
session.delete("flash")
end
end
@ -80,20 +77,6 @@ module ActionDispatch
end
end
module NullFlash #:nodoc:
class << self
def []=(k, v); end
def [](k); end
def alert=(message); end
def notice=(message); end
def empty?; end
end
end
class FlashNow #:nodoc:
attr_accessor :flash

View file

@ -244,7 +244,7 @@ class FlashIntegrationTest < ActionDispatch::IntegrationTest
SessionKey = "_myapp_session"
Generator = ActiveSupport::CachingKeyGenerator.new(
ActiveSupport::KeyGenerator.new("b3c631c314c0bbca50c1b2843150fe33", iterations: 1000)
)
)
Rotations = ActiveSupport::Messages::RotationConfiguration.new
SIGNED_COOKIE_SALT = "signed cookie"