From 270276d26426737b47060324ba6c9eaf03183c88 Mon Sep 17 00:00:00 2001 From: Ihor Dotsenko Date: Mon, 19 Mar 2018 10:24:27 +0200 Subject: [PATCH 1/2] Fix bug with chaining rescues of FastJsonapi::MultiToJson::Result --- lib/fast_jsonapi/multi_to_json.rb | 10 ++++++++-- spec/lib/multi_to_json/result_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 spec/lib/multi_to_json/result_spec.rb diff --git a/lib/fast_jsonapi/multi_to_json.rb b/lib/fast_jsonapi/multi_to_json.rb index 9dd7b5c..108579e 100644 --- a/lib/fast_jsonapi/multi_to_json.rb +++ b/lib/fast_jsonapi/multi_to_json.rb @@ -12,7 +12,12 @@ module FastJsonapi # e.g. https://github.com/github/github-ds/blob/fbda5389711edfb4c10b6c6bad19311dfcb1bac1/lib/github/result.rb class Result def initialize(*rescued_exceptions) - rescued_exceptions = [StandardError] if rescued_exceptions.empty? + @rescued_exceptions = if rescued_exceptions.empty? + [StandardError] + else + rescued_exceptions + end + @value = yield @error = nil rescue *rescued_exceptions => e @@ -33,7 +38,8 @@ module FastJsonapi def rescue return self if ok? - Result.new { yield(@error) } + + Result.new(*@rescued_exceptions) { yield(@error) } end end diff --git a/spec/lib/multi_to_json/result_spec.rb b/spec/lib/multi_to_json/result_spec.rb new file mode 100644 index 0000000..a5ce702 --- /dev/null +++ b/spec/lib/multi_to_json/result_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +module FastJsonapi + module MultiToJson + describe Result do + it 'supports chaining of rescues' do + expect do + Result.new(LoadError) do + require '1' + end.rescue do + require '2' + end.rescue do + require '3' + end.rescue do + '4' + end + end.not_to raise_error + end + end + end +end From 652ad51559f634eceb02cdb1cf713c2919114e2c Mon Sep 17 00:00:00 2001 From: Shishir Kakaraddi Date: Mon, 19 Mar 2018 13:17:30 -0700 Subject: [PATCH 2/2] Bump version number to 1.1.1 --- Gemfile.lock | 2 +- fast_jsonapi.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5a3cb84..790ddf7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - fast_jsonapi (1.1.0) + fast_jsonapi (1.1.1) activesupport (>= 4.2) GEM diff --git a/fast_jsonapi.gemspec b/fast_jsonapi.gemspec index 24edd23..d3f0440 100644 --- a/fast_jsonapi.gemspec +++ b/fast_jsonapi.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |gem| gem.name = "fast_jsonapi" - gem.version = "1.1.0" + gem.version = "1.1.1" gem.required_rubygems_version = Gem::Requirement.new(">= 0") if gem.respond_to? :required_rubygems_version= gem.metadata = { "allowed_push_host" => "https://rubygems.org" } if gem.respond_to? :metadata=