Skip to content

Commit

Permalink
Merge pull request #155 from spree-contrib/fix/specs
Browse files Browse the repository at this point in the history
Fix failing specs in the Ruby >= 2.5 and Spree >= 4.2
  • Loading branch information
damianlegawiec authored Mar 17, 2021
2 parents 4f6c3a8 + 93c70e6 commit c9260c8
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 51 deletions.
26 changes: 15 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ services:
language: ruby

rvm:
- 2.6
- 3.0
- 2.7
- 2.5
- 2.4
- 2.3

env:
Expand All @@ -37,18 +37,22 @@ jobs:
allow_failures:
- gemfile: gemfiles/spree_master.gemfile
exclude:
- rvm: 2.6
- rvm: 3.0
gemfile: gemfiles/spree_3_1.gemfile
- rvm: 2.5
gemfile: gemfiles/spree_3_1.gemfile
- rvm: 2.4
gemfile: gemfiles/spree_3_1.gemfile
- rvm: 2.4
- rvm: 3.0
gemfile: gemfiles/spree_3_7.gemfile
- rvm: 3.0
gemfile: gemfiles/spree_4_0.gemfile
- rvm: 2.4
- rvm: 3.0
gemfile: gemfiles/spree_4_1.gemfile
- rvm: 2.4
gemfile: gemfiles/spree_4_2.gemfile
- rvm: 2.7
gemfile: gemfiles/spree_3_1.gemfile
- rvm: 2.5
gemfile: gemfiles/spree_3_1.gemfile
- rvm: 2.5
gemfile: gemfiles/spree_master.gemfile
- rvm: 2.3
gemfile: gemfiles/spree_3_7.gemfile
- rvm: 2.3
gemfile: gemfiles/spree_4_0.gemfile
- rvm: 2.3
Expand Down
20 changes: 18 additions & 2 deletions app/models/avatax/request_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@ module RequestDecorator
include ::SpreeAvataxOfficial::HttpHelper

def request(method, path, model, options = {})
max_retries ||= ::SpreeAvataxOfficial::Config.max_retries
max_retries ||= ::SpreeAvataxOfficial::Config.max_retries
uri_encoded_path = URI.parse(path).to_s
response = connection.send(method) do |request|
request.options['timeout'] ||= 1_200
case method
when :get, :delete
request.url("#{uri_encoded_path}?#{URI.encode_www_form(options)}")
when :post, :put
request.url("#{uri_encoded_path}?#{URI.encode_www_form(options)}")
request.headers['Content-Type'] = 'application/json'
request.body = model.to_json unless model.empty?
end
end

super
if faraday_response
response
else
response.body
end
rescue *::SpreeAvataxOfficial::HttpHelper::CONNECTION_ERRORS => e
retry unless (max_retries -= 1).zero?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def find_or_create_tax_rate(item, avatax_item)
::Spree::TaxRate.find_or_create_by!(
name: tax_rate_name,
amount: sum_rates_from_details(avatax_item),
zone: item.tax_zone,
zone: item.tax_zone&.reload,
tax_category: item.tax_category,
show_rate_in_label: false,
included_in_price: item.included_in_price
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def inventory_units(refundable)

def create_partial_refund(refundable)
SpreeAvataxOfficial::Transactions::PartialRefundService.call(
refundable_params(refundable).merge(
**refundable_params(refundable).merge(
refund_items: refund_items(refundable)
)
)
Expand Down
12 changes: 3 additions & 9 deletions lib/spree_avatax_official/version.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
module SpreeAvataxOfficial
VERSION = '1.7.0.beta'.freeze

module_function

# Returns the version of the currently loaded SpreeAvataxOfficial as a
# <tt>Gem::Version</tt>.
def version
Gem::Version.new VERSION::STRING
end

module VERSION
MAJOR = 1
MINOR = 6
TINY = 1

STRING = [MAJOR, MINOR, TINY].compact.join('.')
Gem::Version.new VERSION
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@
let!(:stock_location) do
line_item.inventory_units.first.shipment.stock_location.tap do |stock_location|
stock_location.update(
name: 'California Warehouse',
address1: california_address.address1,
address2: california_address.address2,
city: california_address.city,
zipcode: california_address.zipcode,
state_id: california_address.state_id
name: 'California Warehouse',
address1: california_address.address1,
address2: california_address.address2,
city: california_address.city,
zipcode: california_address.zipcode,
state_id: california_address.state_id
)
end
end
Expand Down Expand Up @@ -224,6 +224,7 @@
order.updater.update
end

expect(order.tax_zone.included_in_price).to be true
expect(result.success?).to eq true
expect(order.total).to eq 50.0
expect(order.included_tax_total).to eq 3.7
Expand Down Expand Up @@ -284,6 +285,7 @@
order.updater.update
end

expect(order.tax_zone.included_in_price).to be true
expect(result.success?).to eq true
expect(order.total).to eq 50.0
expect(order.included_tax_total).to eq 3.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
let(:connection_options) { { request: { timeout: 0, open_timeout: 2 } } }

before do
allow_any_instance_of(AvaTax::Client).to receive(:connection_options).and_return(connection_options) # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(AvaTax::Client).to receive(:connection_options).and_return(**connection_options) # rubocop:disable RSpec/AnyInstance
end

it 'returns negative result' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe SpreeAvataxOfficial::Transactions::GetByCodeService do
describe '#call' do
subject { described_class.call(params) }
subject { described_class.call(**params) }

let(:order) { create(:order) }
let!(:return_transaction) { create(:spree_avatax_official_transaction, :return_invoice, order: order, code: 'test321') }
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
SpreeAvataxOfficial::Config.enabled = false
end

config.before do
Rails.cache.clear
end

config.before(type: :feature) do
DatabaseCleaner.start
end
Expand Down
4 changes: 2 additions & 2 deletions spec/support/database_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with :truncation
DatabaseCleaner.clean_with :truncation, except: %w[spree_preferences]
end

config.before do
Expand All @@ -11,7 +11,7 @@

# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
config.before(:each, :js) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.strategy = :truncation, { except: %w[spree_preferences] }
end

config.before do
Expand Down
18 changes: 1 addition & 17 deletions spree_avatax_official.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,8 @@ Gem::Specification.new do |s| # rubocop:disable Metrics/BlockLength
s.add_dependency 'spree_core', spree_version
s.add_dependency 'spree_extension'

s.add_development_dependency 'appraisal'
s.add_development_dependency 'puma'
s.add_development_dependency 'awesome_print'
s.add_development_dependency 'capybara'
s.add_development_dependency 'capybara-screenshot'
s.add_development_dependency 'coffee-rails'
s.add_development_dependency 'database_cleaner'
s.add_development_dependency 'dotenv-rails'
s.add_development_dependency 'factory_bot'
s.add_development_dependency 'ffaker'
s.add_development_dependency 'mysql2'
s.add_development_dependency 'pg'
s.add_development_dependency 'pry'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'sass-rails'
s.add_development_dependency 'selenium-webdriver'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'spree_dev_tools'
s.add_development_dependency 'vcr'
s.add_development_dependency 'webmock'
end

0 comments on commit c9260c8

Please sign in to comment.