From 6906901787db7a863ebe01144f6832ba1bbe1a1c Mon Sep 17 00:00:00 2001 From: Dimitris Bachtis Date: Thu, 13 Dec 2018 15:33:14 +0200 Subject: [PATCH] fix: render_batch receives jobs in hash form. All occurrences of RequestService's `render_batch` receive their jobs input in hash form but were expecting it to be an array. This caused the on_error callbacks to always silently get called with a nil job. Since the consistent form of arguments to the RequestService's methods is a hash, the mock jobs in its test are also wrapped in a hash ( instead of an array ). --- lib/hypernova/request_service.rb | 2 +- spec/request_service_spec.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/hypernova/request_service.rb b/lib/hypernova/request_service.rb index cf2f942..a23c86a 100644 --- a/lib/hypernova/request_service.rb +++ b/lib/hypernova/request_service.rb @@ -9,7 +9,7 @@ def render_batch(jobs) return render_batch_blank(jobs) if jobs.empty? response_body = Hypernova::ParsedResponse.new(jobs).body response_body.each do |index_string, resp| - on_error(build_error(resp["error"]), jobs[index_string.to_i]) if resp["error"] + on_error(build_error(resp["error"]), jobs[index_string]) if resp["error"] end build_renderer(jobs).render(response_body) end diff --git a/spec/request_service_spec.rb b/spec/request_service_spec.rb index 1b79f7d..2b0f293 100644 --- a/spec/request_service_spec.rb +++ b/spec/request_service_spec.rb @@ -17,10 +17,10 @@ # Do not override these variables let(:batch_renderer) { double("batch_renderer") } let(:jobs) do - [ - Helpers.args_1, - Helpers.args_2, - ] + { + "0" => Helpers.args_1, + "1" => Helpers.args_2, + } end let(:parsed_response) { double("parsed_response", body: body) } @@ -61,7 +61,7 @@ def on_error(error, job, jobs_hash) allow(batch_renderer).to receive(:render).with(body) - expect(plugin).to receive(:on_error).with(error_from_response, jobs[1], nil) + expect(plugin).to receive(:on_error).with(error_from_response, jobs["1"], nil) request_service.render_batch(jobs) end end