From 4c464ac989c8943f69ec66059693179828f86a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Ml=C4=8Doch?= Date: Thu, 20 Oct 2022 14:07:24 +0200 Subject: [PATCH] update of gem to work with ruby 3 --- Gemfile.lock | 73 ++++++++++--------- czech_post_b2b_client.gemspec | 20 ++--- lib/czech_post_b2b_client/configuration.rb | 2 +- .../services/orchestrator.rb | 3 +- lib/czech_post_b2b_client/version.rb | 2 +- lib/stepped_service/base.rb | 8 +- .../services/address_sheets_generator_test.rb | 2 +- .../parcels_send_process_updater_test.rb | 2 +- test/services/parcels_sync_sender_test.rb | 2 +- .../communicator_service_testing_base.rb | 8 +- 10 files changed, 65 insertions(+), 57 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 56bd170..06b2654 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,61 +2,62 @@ PATH remote: . specs: czech_post_b2b_client (1.3.0) - ox (~> 2.11) + ox GEM remote: https://rubygems.org/ specs: - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) ansi (1.5.0) ast (2.4.2) builder (3.2.4) byebug (11.1.3) - coderay (1.1.2) - crack (0.4.3) - safe_yaml (~> 1.0.0) + coderay (1.1.3) + crack (0.4.5) + rexml hashdiff (1.0.1) + json (2.6.2) method_source (1.0.0) - minitest (5.14.0) - minitest-reporters (1.4.2) + minitest (5.16.3) + minitest-reporters (1.5.0) ansi builder minitest (>= 5.0) ruby-progressbar - ox (2.13.4) - parallel (1.22.0) - parser (3.1.1.0) + ox (2.14.11) + parallel (1.22.1) + parser (3.1.2.1) ast (~> 2.4.1) - pry (0.13.1) + pry (0.14.1) coderay (~> 1.1) method_source (~> 1.0) - pry-byebug (3.9.0) + pry-byebug (3.10.1) byebug (~> 11.0) - pry (~> 0.13.0) - public_suffix (4.0.6) + pry (>= 0.13, < 0.15) + public_suffix (5.0.0) rainbow (3.1.1) - rake (13.0.1) - regexp_parser (2.2.1) + rake (13.0.6) + regexp_parser (2.6.0) rexml (3.2.5) - rubocop (1.26.1) + rubocop (1.37.0) + json (~> 2.3) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.1.2.1) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.16.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.22.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.16.0) + rubocop-ast (1.22.0) parser (>= 3.1.1.0) - rubocop-minitest (0.9.0) - rubocop (>= 0.74) + rubocop-minitest (0.22.2) + rubocop (>= 0.90, < 2.0) ruby-progressbar (1.11.0) - safe_yaml (1.0.5) - unicode-display_width (2.1.0) - webmock (3.8.3) - addressable (>= 2.3.6) + unicode-display_width (2.3.0) + webmock (3.18.1) + addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -64,15 +65,15 @@ PLATFORMS ruby DEPENDENCIES - bundler (~> 2.1) + bundler czech_post_b2b_client! - minitest (~> 5.0) - minitest-reporters (~> 1.0) - pry-byebug (~> 3.0) - rake (~> 13.0) - rubocop (~> 1.26.1) - rubocop-minitest (~> 0.6) - webmock (~> 3.0) + minitest + minitest-reporters + pry-byebug + rake + rubocop + rubocop-minitest + webmock BUNDLED WITH 2.2.28 diff --git a/czech_post_b2b_client.gemspec b/czech_post_b2b_client.gemspec index c30cfda..ba7115b 100644 --- a/czech_post_b2b_client.gemspec +++ b/czech_post_b2b_client.gemspec @@ -47,14 +47,14 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_dependency 'ox', '~> 2.11' - - spec.add_development_dependency 'bundler', '~> 2.1' - spec.add_development_dependency 'minitest', '~> 5.0' - spec.add_development_dependency 'minitest-reporters', '~> 1.0' - spec.add_development_dependency 'pry-byebug', '~> 3.0' - spec.add_development_dependency 'rake', '~> 13.0' - spec.add_development_dependency 'rubocop', '~> 1.26.1' - spec.add_development_dependency 'rubocop-minitest', '~> 0.6' - spec.add_development_dependency 'webmock', '~> 3.0' + spec.add_dependency 'ox' + + spec.add_development_dependency 'bundler' + spec.add_development_dependency 'minitest' + spec.add_development_dependency 'minitest-reporters' + spec.add_development_dependency 'pry-byebug' + spec.add_development_dependency 'rake' + spec.add_development_dependency 'rubocop' + spec.add_development_dependency 'rubocop-minitest' + spec.add_development_dependency 'webmock' end diff --git a/lib/czech_post_b2b_client/configuration.rb b/lib/czech_post_b2b_client/configuration.rb index b39c191..8057aef 100644 --- a/lib/czech_post_b2b_client/configuration.rb +++ b/lib/czech_post_b2b_client/configuration.rb @@ -32,7 +32,7 @@ def initialize } @language = :cs - @logger = defined?(Rails) ? ::Rails.logger : ::Logger.new($stdout) + @logger = defined?(Rails::Logger) ? ::Rails.logger : ::Logger.new($stdout) @b2b_api_base_uri = 'https://b2b.postaonline.cz/services/POLService/v1' @sending_post_office_location_number = 1 diff --git a/lib/czech_post_b2b_client/services/orchestrator.rb b/lib/czech_post_b2b_client/services/orchestrator.rb index d09aebb..c48736a 100644 --- a/lib/czech_post_b2b_client/services/orchestrator.rb +++ b/lib/czech_post_b2b_client/services/orchestrator.rb @@ -8,7 +8,8 @@ class Orchestrator < SteppedService::Base def result_of_subservice(service_hash) service_name = service_hash.keys.first service_class = send("#{service_name}_class") - service = service_class.call(service_hash.values.first) + + service = service_class.call(**service_hash.values.first) if service.failed? errors.add_from_hash({ service_name => service.errors.full_messages }) diff --git a/lib/czech_post_b2b_client/version.rb b/lib/czech_post_b2b_client/version.rb index 0aede0a..3dbbf39 100644 --- a/lib/czech_post_b2b_client/version.rb +++ b/lib/czech_post_b2b_client/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module CzechPostB2bClient - VERSION = '1.3.0' + VERSION = '1.4.0' end diff --git a/lib/stepped_service/base.rb b/lib/stepped_service/base.rb index 73ac9a9..b4fe379 100644 --- a/lib/stepped_service/base.rb +++ b/lib/stepped_service/base.rb @@ -87,7 +87,13 @@ class Base attr_reader :result def self.call(*args, **keyword_args) - new(*args, **keyword_args).call + if args.blank? + new(**keyword_args).call + elsif keyword_args.blank? + new(*args).call + else + new(*args, **keyword_args).call + end end # You can override it, to not use steps diff --git a/test/services/address_sheets_generator_test.rb b/test/services/address_sheets_generator_test.rb index f25671b..bbf8978 100644 --- a/test/services/address_sheets_generator_test.rb +++ b/test/services/address_sheets_generator_test.rb @@ -58,7 +58,7 @@ def test_it_fails_with_errors_in_response_data # rubocop:disable Metrics/AbcSize builder_service_class.stub(:call, builder) do api_caller_service_class.stub(:call, api_caller) do parser_service_class.stub(:call, parser) do - @service = tested_service_class.call(tested_service_args) + @service = tested_service_class.call(**tested_service_args) end end end diff --git a/test/services/parcels_send_process_updater_test.rb b/test/services/parcels_send_process_updater_test.rb index 088a366..6771f60 100644 --- a/test/services/parcels_send_process_updater_test.rb +++ b/test/services/parcels_send_process_updater_test.rb @@ -53,7 +53,7 @@ def test_it_fails_with_errors_in_response_data # rubocop:disable Metrics/AbcSiz builder_service_class.stub(:call, builder) do api_caller_service_class.stub(:call, api_caller) do parser_service_class.stub(:call, parser) do - @service = tested_service_class.call(tested_service_args) + @service = tested_service_class.call(**tested_service_args) end end end diff --git a/test/services/parcels_sync_sender_test.rb b/test/services/parcels_sync_sender_test.rb index 5d60f8b..83f0c3b 100644 --- a/test/services/parcels_sync_sender_test.rb +++ b/test/services/parcels_sync_sender_test.rb @@ -70,7 +70,7 @@ def test_it_fails_with_errors_in_response_data # rubocop:disable Metrics/AbcSize builder_service_class.stub(:call, builder) do api_caller_service_class.stub(:call, api_caller) do parser_service_class.stub(:call, parser) do - @service = tested_service_class.call(tested_service_args) + @service = tested_service_class.call(**tested_service_args) end end end diff --git a/test/support/communicator_service_testing_base.rb b/test/support/communicator_service_testing_base.rb index 0b32512..44f8ea4 100644 --- a/test/support/communicator_service_testing_base.rb +++ b/test/support/communicator_service_testing_base.rb @@ -43,7 +43,7 @@ def test_it_calls_api_when_data_are_ok # rubocop:disable Metrics/AbcSize builder_service_class.stub(:call, builder) do api_caller_service_class.stub(:call, api_caller) do parser_service_class.stub(:call, parser) do - @service = tested_service_class.call(tested_service_args) + @service = tested_service_class.call(**tested_service_args) end end end @@ -61,7 +61,7 @@ def test_it_handle_builder_errors builder_service_class.stub(:call, builder) do api_caller_service_class.stub(:call, not_to_be_called_mock('ApiCaller')) do - @service = tested_service_class.call(tested_service_args) + @service = tested_service_class.call(**tested_service_args) end end @@ -78,7 +78,7 @@ def test_it_handle_api_caller_errors # rubocop:disable Metrics/AbcSize builder_service_class.stub(:call, builder) do api_caller_service_class.stub(:call, api_caller) do parser_service_class.stub(:call, not_to_be_called_mock('ResponseParser')) do - @service = tested_service_class.call(tested_service_args) + @service = tested_service_class.call(**tested_service_args) end end end @@ -99,7 +99,7 @@ def test_it_handle_parser_errors # rubocop:disable Metrics/AbcSize builder_service_class.stub(:call, builder) do api_caller_service_class.stub(:call, api_caller) do parser_service_class.stub(:call, parser) do - @service = tested_service_class.call(tested_service_args) + @service = tested_service_class.call(**tested_service_args) end end end