From 61dd4dee0964c244a19ce069c7a7ed954fbd09e2 Mon Sep 17 00:00:00 2001 From: KY Date: Sat, 17 Dec 2016 04:43:31 +0800 Subject: [PATCH 1/3] Add Gemfile --- .gitignore | 1 + Gemfile | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 Gemfile diff --git a/.gitignore b/.gitignore index 9e667f6..1132a14 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ spec/reports test/tmp test/version_tmp tmp +Gemfile.lock #chargebee ignores snippets.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..b4e2a20 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gemspec From 6e6b18f1a7270a2dd55ba4f78de61e7d2252a8e2 Mon Sep 17 00:00:00 2001 From: KY Date: Sat, 17 Dec 2016 04:44:18 +0800 Subject: [PATCH 2/3] Ignore .rspec --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1132a14..35f7844 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ test/tmp test/version_tmp tmp Gemfile.lock +.rspec #chargebee ignores snippets.rb From 9ff96b1668243e2d114dc17f2826251fc24a9877 Mon Sep 17 00:00:00 2001 From: KY Date: Sat, 17 Dec 2016 04:46:16 +0800 Subject: [PATCH 3/3] Allow Error.new with no argument and not blows up --- lib/chargebee/errors.rb | 12 ++++++------ spec/errors_spec.rb | 9 +++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/chargebee/errors.rb b/lib/chargebee/errors.rb index 6371621..9736552 100644 --- a/lib/chargebee/errors.rb +++ b/lib/chargebee/errors.rb @@ -3,9 +3,9 @@ module ChargeBee class Error < StandardError attr_reader :original_error - def initialize(message=nil,original_error = nil) - super message - @original_error = original_error + def initialize(message = nil, original_error = {}) + super message + @original_error = original_error end end @@ -16,8 +16,8 @@ class APIError < Error attr_reader :http_status_code, :type, :api_error_code, :param, :json_obj, #Deprecated attributes :http_code, :http_body, :error_code - - def initialize(http_code=nil, json_obj = nil) + + def initialize(http_code = nil, json_obj = {}) super json_obj[:message] @json_obj = json_obj @http_status_code = http_code @@ -30,7 +30,7 @@ def initialize(http_code=nil, json_obj = nil) @http_code = http_code @http_body = json_obj.to_s end - + end diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index 9638763..33cc9a7 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe 'ChargeBee::InvalidRequestError' do + let(:invalid_request_json) do { message: 'id: The value chargebee_account is already present.', @@ -14,10 +15,14 @@ } end - it "provide message from error api response" do + it 'provide message from error api response' do error = ChargeBee::InvalidRequestError.new(400, invalid_request_json) error.message.should eq 'id: The value chargebee_account is already present.' end -end + it 'allows empty arguments' do + error = ChargeBee::InvalidRequestError.new + error.message.should eq 'ChargeBee::InvalidRequestError' + end +end