Skip to content

Commit b95ddd4

Browse files
fatkodimamihaic195
andcommitted
Fix EtagWithFlash when there is no Flash middleware available
Co-authored-by: mihaic195 <[email protected]>
1 parent 46c7420 commit b95ddd4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

actionpack/lib/action_controller/metal/etag_with_flash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module EtagWithFlash
1212
include ActionController::ConditionalGet
1313

1414
included do
15-
etag { flash unless flash.empty? }
15+
etag { flash if request.respond_to?(:flash) && !flash.empty? }
1616
end
1717
end
1818
end

railties/test/application/configuration_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,23 @@ def index
632632
assert last_response.ok?
633633
end
634634

635+
test "EtagWithFlash module doesn't break for API apps" do
636+
make_basic_app do |application|
637+
application.config.api_only = true
638+
end
639+
640+
class ::OmgController < ActionController::Base
641+
def index
642+
stale?(weak_etag: "something")
643+
render plain: "else"
644+
end
645+
end
646+
647+
get "/"
648+
649+
assert last_response.ok?
650+
end
651+
635652
test "Use key_generator when secret_key_base is set" do
636653
make_basic_app do |application|
637654
application.secrets.secret_key_base = "b3c631c314c0bbca50c1b2843150fe33"

0 commit comments

Comments
 (0)