Skip to content

Commit

Permalink
Merge pull request #149 from friendlycart/test-multiple-rubies
Browse files Browse the repository at this point in the history
Test multiple rubies
  • Loading branch information
mamhoff authored Dec 14, 2022
2 parents 0181885 + 04ab5f5 commit 86edf5f
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 41 deletions.
23 changes: 18 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2
version: 2.1
jobs:
build:
test:
parameters:
ruby-version:
type: string
docker:
# specify the version you desire here
- image: circleci/ruby:2.5
- image: cimg/ruby:<< parameters.ruby-version >>

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
Expand All @@ -22,7 +25,7 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "friendly_shipping.gemspec" }}
- v1-dependencies-{{ checksum "friendly_shipping.gemspec" }}-<< parameters.ruby-version >>
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

Expand All @@ -35,7 +38,7 @@ jobs:
- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
key: v1-dependencies-{{ checksum "Gemfile.lock" }}-<< parameters.ruby-version >>

- run:
name: run Rubocop
Expand All @@ -60,3 +63,13 @@ jobs:
- store_artifacts:
path: /tmp/test-results
destination: test-results

workflows:
build_and_test:
jobs:
- test:
matrix:
parameters:
# https://github.com/CircleCI-Public/cimg-ruby
# only supports the last three ruby versions
ruby-version: ["3.1", "3.0", "2.7"]
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7

inherit_from:
- .rubocop-relaxed.yml
Expand All @@ -15,3 +15,6 @@ Style/HashTransformKeys:

Style/HashTransformValues:
Enabled: true

Naming/VariableNumber:
Enabled: false
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.0] - 2022-12-14
- Removes dependency on unmaintained data_uri gem
- Bumps required Ruby to 2.7

## [0.6.5] - 2022-04-25

### Added
Expand Down
6 changes: 2 additions & 4 deletions friendly_shipping.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_runtime_dependency "data_uri", ">= 0.0.3", "< 0.2.0"
spec.add_runtime_dependency "dry-monads", "~> 1.0"
spec.add_runtime_dependency "money", "~> 6.0"
spec.add_runtime_dependency "nokogiri", "~> 1.6"
spec.add_runtime_dependency "physical", "~> 0.4", ">= 0.4.5"
spec.add_runtime_dependency "rest-client", "~> 2.0"
spec.add_runtime_dependency "uri", "< 0.13.0"
spec.required_ruby_version = '>= 2.5'
spec.required_ruby_version = '>= 2.7'

spec.add_development_dependency "bundler", ">= 2.1.4", "< 3"
spec.add_development_dependency "dotenv", "~> 2.7"
Expand All @@ -38,7 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", ">= 12.3.3"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rspec_junit_formatter", "~> 0.4"
spec.add_development_dependency "rubocop", ">= 0.80", "< 1"
spec.add_development_dependency "rubocop"
spec.add_development_dependency "simplecov", "~> 0.17"
spec.add_development_dependency "vcr", "~> 6.0"
spec.add_development_dependency "webmock", "~> 3.6"
Expand Down
2 changes: 1 addition & 1 deletion lib/friendly_shipping/api_error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module FriendlyShipping
class ApiErrorHandler
include Dry::Monads::Result::Mixin
include Dry::Monads[:result]

attr_reader :api_error_class

Expand Down
4 changes: 2 additions & 2 deletions lib/friendly_shipping/http_client.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# frozen_string_literal: true

require 'dry/monads/result'
require 'dry/monads'
require 'rest-client'

require 'friendly_shipping/api_failure'
require 'friendly_shipping/api_error_handler'

module FriendlyShipping
class HttpClient
include Dry::Monads::Result::Mixin
include Dry::Monads[:result]

attr_reader :error_handler

Expand Down
4 changes: 2 additions & 2 deletions lib/friendly_shipping/services/ship_engine.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'dry/monads/result'
require 'dry/monads'
require 'friendly_shipping/http_client'
require 'friendly_shipping/services/ship_engine/bad_request_handler'
require 'friendly_shipping/services/ship_engine/parse_carrier_response'
Expand Down Expand Up @@ -54,7 +54,7 @@ def carriers(debug: false)
# can be serialized into an error message using `to_s`.
def rate_estimates(shipment, options: FriendlyShipping::Services::ShipEngine::RateEstimatesOptions.new, debug: false)
request = FriendlyShipping::Request.new(
url: API_BASE + 'rates/estimate',
url: "#{API_BASE}rates/estimate",
http_method: "POST",
body: SerializeRateEstimateRequest.call(shipment: shipment, options: options).to_json,
headers: request_headers,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'json'
require 'data_uri'

module FriendlyShipping
module Services
Expand All @@ -14,7 +13,14 @@ def self.call(request:, response:)
label_data = nil
label_url = nil
if label_uri_string.starts_with?('data')
label_data = URI::Data.new(label_uri_string).data
# This URI has the following form:
# data:application/zpl;base64,XlhBDQpeTEwxMjE4....
# We don't know the content type here, but we can assume Base64
# encoding.
# This next line splits the URI at the first occurrence of ";base64,",
# giving us the desired base64 encoded string.
_, base64_encoded = label_uri_string.split(";base64,", 2)
label_data = Base64.decode64(base64_encoded)
else
label_url = label_uri_string
end
Expand Down
4 changes: 2 additions & 2 deletions lib/friendly_shipping/services/ups.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'dry/monads/result'
require 'dry/monads'
require 'friendly_shipping/http_client'
require 'friendly_shipping/services/ups/serialize_access_request'
require 'friendly_shipping/services/ups/serialize_city_state_lookup_request'
Expand All @@ -26,7 +26,7 @@
module FriendlyShipping
module Services
class Ups
include Dry::Monads::Result::Mixin
include Dry::Monads[:result]

attr_reader :test, :key, :login, :password, :client

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'dry/monads/result'
require 'dry/monads'
require 'friendly_shipping/services/ups/parse_money_element'

module FriendlyShipping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'dry/monads/result'
require 'dry/monads'

module FriendlyShipping
module Services
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'dry/monads/result'
require 'dry/monads'

module FriendlyShipping
module Services
Expand Down
4 changes: 2 additions & 2 deletions lib/friendly_shipping/services/ups_freight.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'dry/monads/result'
require 'dry/monads'
require 'friendly_shipping/http_client'
require 'friendly_shipping/services/ups_freight/shipping_methods'
require 'friendly_shipping/services/ups_freight/rates_options'
Expand All @@ -23,7 +23,7 @@
module FriendlyShipping
module Services
class UpsFreight
include Dry::Monads::Result::Mixin
include Dry::Monads[:result]

attr_reader :test, :key, :login, :password, :client

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def call(request:, response:)
service_code = shipment_results.dig("Service", "Code")
shipping_method = SHIPPING_METHODS.detect { |sm| sm.service_code == service_code }

total_shipment_charge = shipment_results.dig("TotalShipmentCharge")
total_shipment_charge = shipment_results["TotalShipmentCharge"]
if total_shipment_charge
currency = Money::Currency.new(total_shipment_charge['CurrencyCode'])
amount = total_shipment_charge['MonetaryValue'].to_f
Expand All @@ -32,9 +32,9 @@ def call(request:, response:)

images_data = Array.wrap(shipment_results.dig("Documents", "Image"))

bol_id = shipment_results.dig("BOLID")
shipment_number = shipment_results.dig("ShipmentNumber")
pickup_request_number = shipment_results.dig("PickupRequestConfirmationNumber")
bol_id = shipment_results["BOLID"]
shipment_number = shipment_results["ShipmentNumber"]
pickup_request_number = shipment_results["PickupRequestConfirmationNumber"]

documents = images_data.map { |image_data| ParseShipmentDocument.call(image_data: image_data) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ParseShipmentDocument

def self.call(image_data:)
format_code = image_data.dig("Type", "Code")
graphic_image_b64 = image_data.dig("GraphicImage")
graphic_image_b64 = image_data["GraphicImage"]

ShipmentDocument.new(
format: image_data.dig("Format", "Code").downcase.to_sym,
Expand Down
2 changes: 1 addition & 1 deletion lib/friendly_shipping/services/usps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
module FriendlyShipping
module Services
class Usps
include Dry::Monads::Result::Mixin
include Dry::Monads[:result]

attr_reader :test, :login, :client

Expand Down
2 changes: 1 addition & 1 deletion lib/friendly_shipping/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module FriendlyShipping
VERSION = "0.6.5"
VERSION = "0.7.0"
end
12 changes: 6 additions & 6 deletions spec/friendly_shipping/http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
let(:response) { double(code: 200, body: 'so much text', headers: {}) }

it 'forwards the arguments to RestClient and returns a Success' do
expect(::RestClient).to receive(:get).with('https://example.com', "X-Token" => "s3cr3t").and_return(response)
expect(::RestClient).to receive(:get).with('https://example.com', { "X-Token" => "s3cr3t" }).and_return(response)
result = subject.get(request)
expect(result).to be_success
end

it 'wraps exceptions in Failures' do
expect(::RestClient).to receive(:get).with('https://example.com', "X-Token" => "s3cr3t").and_raise(RestClient::ExceptionWithResponse)
expect(::RestClient).to receive(:get).with('https://example.com', { "X-Token" => "s3cr3t" }).and_raise(RestClient::ExceptionWithResponse)
result = subject.get(request)
expect(result).to be_failure
expect(result.failure).to be_a(FriendlyShipping::ApiFailure)
Expand All @@ -36,13 +36,13 @@
let(:response) { double(code: 200, body: 'ok', headers: {}) }

it 'forwards the arguments to RestClient and returns a Success' do
expect(::RestClient).to receive(:post).with('https://example.com', 'body', "X-Token" => "s3cr3t").and_return(response)
expect(::RestClient).to receive(:post).with('https://example.com', 'body', { "X-Token" => "s3cr3t" }).and_return(response)
result = subject.post(request)
expect(result).to be_success
end

it 'wraps exceptions in Failures' do
expect(::RestClient).to receive(:post).with('https://example.com', 'body', "X-Token" => "s3cr3t").and_raise(RestClient::ExceptionWithResponse)
expect(::RestClient).to receive(:post).with('https://example.com', 'body', { "X-Token" => "s3cr3t" }).and_raise(RestClient::ExceptionWithResponse)
result = subject.post(request)
expect(result).to be_failure
expect(result.failure).to be_a(FriendlyShipping::ApiFailure)
Expand All @@ -54,13 +54,13 @@
let(:response) { double(code: 200, body: 'ok', headers: {}) }

it 'forwards the arguments to RestClient and returns a Success' do
expect(::RestClient).to receive(:put).with('https://example.com', 'body', "X-Token" => "s3cr3t").and_return(response)
expect(::RestClient).to receive(:put).with('https://example.com', 'body', { "X-Token" => "s3cr3t" }).and_return(response)
result = subject.put(request)
expect(result).to be_success
end

it 'wraps exceptions in Failures' do
expect(::RestClient).to receive(:put).with('https://example.com', 'body', "X-Token" => "s3cr3t").and_raise(RestClient::ExceptionWithResponse)
expect(::RestClient).to receive(:put).with('https://example.com', 'body', { "X-Token" => "s3cr3t" }).and_raise(RestClient::ExceptionWithResponse)
result = subject.put(request)
expect(result).to be_failure
expect(result.failure).to be_a(FriendlyShipping::ApiFailure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'friendly_shipping/services/ups/parse_shipment_accept_response'

RSpec.describe FriendlyShipping::Services::Ups::ParseShipmentAcceptResponse do
include Dry::Monads::Result::Mixin
include Dry::Monads[:result]
let(:response_body) { File.open(File.join(gem_root, 'spec', 'fixtures', 'ups', 'shipment_accept_response.xml')).read }
let(:response) { double(body: response_body) }
let(:request) { FriendlyShipping::Request.new(url: 'http://www.example.com') }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'friendly_shipping/services/ups/parse_shipment_confirm_response'

RSpec.describe FriendlyShipping::Services::Ups::ParseShipmentConfirmResponse do
include Dry::Monads::Result::Mixin
include Dry::Monads[:result]
let(:response_body) { File.open(File.join(gem_root, 'spec', 'fixtures', 'ups', 'shipment_confirm_response.xml')).read }
let(:response) { double(body: response_body) }
let(:request) { FriendlyShipping::Request.new(url: 'http://www.example.com') }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'friendly_shipping/services/ups/parse_time_in_transit_response'

RSpec.describe FriendlyShipping::Services::Ups::ParseTimeInTransitResponse do
include Dry::Monads::Result::Mixin
include Dry::Monads[:result]
let(:response_body) { File.open(File.join(gem_root, 'spec', 'fixtures', 'ups', 'ups_timing_api_response.xml')).read }
let(:response) { double(body: response_body) }
let(:request) { FriendlyShipping::Request.new(url: 'http://www.example.com') }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'friendly_shipping/services/ups/parse_void_shipment_response'

RSpec.describe FriendlyShipping::Services::Ups::ParseVoidShipmentResponse do
include Dry::Monads::Result::Mixin
include Dry::Monads[:result]
let(:response_body) { File.open(File.join(gem_root, 'spec', 'fixtures', 'ups', 'void_shipment_response.xml')).read }
let(:response) { double(body: response_body) }
let(:request) { FriendlyShipping::Request.new(url: 'http://www.example.com') }
Expand Down

0 comments on commit 86edf5f

Please sign in to comment.