Skip to content

Commit e65ff7c

Browse files
authored
Merge pull request airbnb#18 from gilbox/gil--on_error-args
Pass hash into on_error
2 parents 7614f8f + c5dbe83 commit e65ff7c

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

lib/hypernova/controller_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def hypernova_batch_after
8888
result = @hypernova_batch.submit!
8989
on_success(result, hash)
9090
rescue StandardError => e
91-
on_error(e)
91+
on_error(e, nil, hash)
9292
result = @hypernova_batch.submit_fallback!
9393
end
9494
else

lib/hypernova/plugin_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def after_response(current_response, original_response)
4747
end
4848
end
4949

50-
def on_error(error, job = {})
51-
Hypernova.plugins.each { |plugin| plugin.on_error(error, job) if plugin.respond_to?(:on_error) }
50+
def on_error(error, job = nil, jobs_hash = nil)
51+
Hypernova.plugins.each { |plugin| plugin.on_error(error, job, jobs_hash) if plugin.respond_to?(:on_error) }
5252
end
5353

5454
def on_success(res, jobs_hash)

spec/batch_renderer_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "spec_helper"
22
require "hypernova/batch_renderer"
3+
require "securerandom"
34

45
describe Hypernova::BatchRenderer do
56
# Do not override these variables

spec/controller_helpers_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def initialize
109109
allow(test).to receive(:will_send_request).and_raise(error)
110110
allow(test).to receive(:response).and_return(response)
111111

112-
expect(test).to receive(:on_error).with(error)
112+
expect(test).to receive(:on_error).with(error, nil, hash_including('mordor.js'))
113113
expect(batch).to receive(:submit_fallback!)
114114

115115
test.hypernova_render_support {}

spec/plugin_helper_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_view_data(name, data)
3131
describe "#on_error" do
3232
it "calls on_error for each plugin" do
3333
class Plugin
34-
def on_error(error, job)
34+
def on_error(error, job, jobs_hash)
3535
end
3636
end
3737

@@ -40,9 +40,10 @@ def on_error(error, job)
4040

4141
error = double("error")
4242
job = double("job")
43+
jobs_hash = double("jobs")
4344

44-
expect(plugin).to receive(:on_error).with(error, job)
45-
TestClass.new.on_error(error, job)
45+
expect(plugin).to receive(:on_error).with(error, job, jobs_hash)
46+
TestClass.new.on_error(error, job, jobs_hash)
4647
end
4748
end
4849

spec/request_service_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949

5050
it "calls on_error for each job where the response has an error with a new hash" do
5151
class Plugin
52-
def on_error(error, job)
53-
[error.message, job]
52+
def on_error(error, job, jobs_hash)
53+
[error.message, job, jobs_hash]
5454
end
5555
end
5656

@@ -61,7 +61,7 @@ def on_error(error, job)
6161

6262
allow(batch_renderer).to receive(:render).with(body)
6363

64-
expect(plugin).to receive(:on_error).with(error_from_response, jobs[1])
64+
expect(plugin).to receive(:on_error).with(error_from_response, jobs[1], nil)
6565
request_service.render_batch(jobs)
6666
end
6767
end

0 commit comments

Comments
 (0)