mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Call run_afters even if throwing from run_befores
This commit is contained in:
parent
34fe914946
commit
08e8c79347
2 changed files with 30 additions and 10 deletions
|
@ -283,18 +283,14 @@ module Sidekiq
|
||||||
action = self.class.match(env)
|
action = self.class.match(env)
|
||||||
return [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found"]] unless action
|
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)
|
self.class.run_befores(app, action)
|
||||||
begin
|
action.instance_exec env, &action.block
|
||||||
resp = action.instance_exec env, &action.block
|
|
||||||
ensure
|
ensure
|
||||||
self.class.run_afters(app, action)
|
self.class.run_afters(app, action)
|
||||||
end
|
end
|
||||||
|
|
||||||
resp
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = case resp
|
resp = case resp
|
||||||
when Array
|
when Array
|
||||||
resp
|
resp
|
||||||
|
|
|
@ -769,4 +769,28 @@ describe Sidekiq::Web do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue