diff --git a/lib/sidekiq/web/application.rb b/lib/sidekiq/web/application.rb index 8326e775..e9f033ba 100644 --- a/lib/sidekiq/web/application.rb +++ b/lib/sidekiq/web/application.rb @@ -283,17 +283,13 @@ module Sidekiq action = self.class.match(env) return [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found"]] unless action - resp = catch(:halt) { - app = @klass + app = @klass + resp = catch(:halt) do self.class.run_befores(app, action) - begin - resp = action.instance_exec env, &action.block - ensure - self.class.run_afters(app, action) - end - - resp - } + action.instance_exec env, &action.block + ensure + self.class.run_afters(app, action) + end resp = case resp when Array diff --git a/test/test_web.rb b/test/test_web.rb index d9316910..c3cca02a 100644 --- a/test/test_web.rb +++ b/test/test_web.rb @@ -769,4 +769,28 @@ describe Sidekiq::Web do end end end + + describe "redirecting in before" do + include Rack::Test::Methods + + before do + Sidekiq::WebApplication.before { Thread.current[:some_setting] = :before } + Sidekiq::WebApplication.before { redirect '/' } + Sidekiq::WebApplication.after { Thread.current[:some_setting] = :after } + end + + after do + Sidekiq::WebApplication.remove_instance_variable(:@befores) + Sidekiq::WebApplication.remove_instance_variable(:@afters) + end + + def app + Sidekiq::Web.new + end + + it "allows afters to run" do + get '/' + assert_equal :after, Thread.current[:some_setting] + end + end end