Skip to content

Commit

Permalink
Fixed Spree 4 compatibility (#183)
Browse files Browse the repository at this point in the history
* Fixed Spree 4 compatibility

* fixes

* Update usa_address_factory.rb

* fixes

* fixes

* Fixed #178

* Update vcr.rb

* require spree 4.3+
  • Loading branch information
damianlegawiec authored Apr 25, 2024
1 parent b579675 commit 202c7c8
Show file tree
Hide file tree
Showing 21 changed files with 237 additions and 222 deletions.
173 changes: 102 additions & 71 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,115 @@
version: 2.1

defaults: &defaults
environment: &environment
CIRCLE_TEST_REPORTS: /tmp/test-results
CIRCLE_ARTIFACTS: /tmp/test-artifacts
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
BUNDLE_PATH: ~/spree/vendor/bundle
working_directory: ~/spree
docker:
- image: &ruby_image cimg/ruby:3.3-browsers

run_tests: &run_tests
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- spree-bundle-{{ .Branch }}
- spree-bundle
- run:
name: Add keyserver
command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B
- run:
name: Install libvips
command: sudo apt-get update && sudo apt-get install libvips
- run:
name: Set bundle path
command: bundle config --local path vendor/bundle
- run:
name: Ensure bundle Install
command: |
bundle check || bundle install
- run:
name: Create test app
command: |
bundle exec rake test_app
- run:
name: Run Rspec
command: |
TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
bundle exec rspec --format documentation \
--format RspecJunitFormatter \
-o ~/rspec/rspec.xml \
-- ${TESTFILES}
- store_test_results:
path: ~/rspec
- store_artifacts:
path: tmp/capybara

jobs:
rspec:
parameters:
ruby-version:
type: string
gemfile:
type: string
database:
type: string
docker:
- image: circleci/ruby:<< parameters.ruby-version >>-node-browsers
environment:
DB: << parameters.database >>
- image: circleci/mysql:5.7-ram
environment:
MYSQL_DATABASE: avatax
MYSQL_USER: avatax
MYSQL_PASSWORD: password
- image: circleci/postgres:9.6-alpine
environment:
POSTGRES_USER: 'avatax'
POSTGRES_PASSWORD: 'password'
POSTGRES_DB: 'avatax'
bundle:
<<: *defaults
steps:
- checkout
- when:
condition:
equal: ["mysql", << parameters.database >>]
steps:
- run:
name: Configure MySQL2
# Hack to set environment variable for later steps https://circleci.com/docs/2.0/env-vars/#example-configuration-of-environment-variables
command: echo 'export DATABASE_URL="mysql2://avatax:password@127.0.0.1/avatax"' >> $BASH_ENV
- when:
condition:
equal: ["postgres", << parameters.database >>]
steps:
- run:
name: Configure Postgres
command: echo 'export DATABASE_URL="postgresql://avatax:password@127.0.0.1/avatax"' >> $BASH_ENV
- run:
name: Configure bundler
command: bundle config --local path '~/.bundle'
- run:
name: Select Gemfile
command: cp gemfiles/<< parameters.gemfile >>.gemfile gemfiles/ci.gemfile
- restore_cache:
keys:
- bundler-v10-<< parameters.ruby-version >>-<< parameters.gemfile >>-{{ checksum "gemfiles/ci.gemfile" }}
- bundler-v10-<< parameters.ruby-version >>-<< parameters.gemfile >>
- spree-bundle-{{ .Branch }}
- spree-bundle
- run:
name: Install dependencies
command: bundle install --gemfile=gemfiles/ci.gemfile
- save_cache:
key: bundler-v10-<< parameters.ruby-version >>-<< parameters.gemfile >>-{{ checksum "gemfiles/ci.gemfile" }}
paths:
- "~/.bundle"
name: Add keyserver
command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B
- run:
name: Setup test app
command: bundle exec --gemfile=gemfiles/ci.gemfile rake test_app
name: Install libvips
command: sudo apt-get update && sudo apt-get install libvips
- run:
name: Run RSpec
command: bundle exec --gemfile=gemfiles/ci.gemfile rake spec
workflows:
all-specs:
jobs:
- rspec:
matrix:
parameters:
database:
- mysql
- postgres
gemfile:
- spree_4_2
- spree_4_3
ruby-version:
- "3.0"
- "2.7"

name: Set bundle path
command: bundle config --local path vendor/bundle
- run:
name: Bundle Install
command: |
bundle check || bundle install
- save_cache:
paths:
- vendor/bundle
key: spree-bundle-{{ checksum "Gemfile.lock" }}

tests_postgres: &tests_postgres
<<: *run_tests
environment: &postgres_environment
<<: *environment
DB: postgres
DB_HOST: localhost
DB_USERNAME: postgres
docker:
- image: *ruby_image
- image: &postgres_image cimg/postgres:16.2
environment:
POSTGRES_USER: postgres

tests_mysql: &tests_mysql
<<: *run_tests
environment: &mysql_environment
<<: *environment
DB: mysql
DB_HOST: 127.0.0.1
DB_USERNAME: root
COVERAGE: true
COVERAGE_DIR: /tmp/workspace/simplecov
docker:
- image: *ruby_image
- image: &mysql_image cimg/mysql:8.0

workflows:
version: 2
main:
jobs:
- bundle
- tests_postgres:
requires:
- bundle
- tests_mysql:
requires:
- bundle
78 changes: 0 additions & 78 deletions .travis.yml

This file was deleted.

21 changes: 0 additions & 21 deletions Appraisals

This file was deleted.

21 changes: 15 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ git_source(:github) do |repo_name|
end

gem 'rails-controller-testing'
gem 'rubocop', '~> 0.63.0', require: false
gem 'rubocop-rspec', require: false
gem 'spree_auth_devise'
gem 'spree_backend'
gem 'spree_core'
gem 'sass-rails'
gem 'spree', github: 'spree/spree', branch: 'main'
gem 'spree_backend', github: 'spree/spree_backend', branch: 'main'
gem 'spree_emails', github: 'spree/spree', branch: 'main'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'main'

if ENV['DB'] == 'mysql'
gem 'mysql2'
elsif ENV['DB'] == 'postgres'
gem 'pg'
else
gem 'sqlite3', '~> 1.4'
end

gem 'webdrivers'
gem 'pry'

gemspec
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2019 Spark Solutions
Copyright (c) 2019-2024 Spark Solutions Sp. z o.o.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/admin/avatax_settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class AvataxSettingsController < Spree::Admin::BaseController
def edit
@ship_from_address = SpreeAvataxOfficial::Config.ship_from_address
@country = if @ship_from_address[:country].blank?
Spree::Country.default
current_store.default_country
else
Spree::Country.find_by(iso3: @ship_from_address[:country])
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree_avatax_official/spree/user_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ def self.prepended(base)
end
end

::Spree::User.prepend ::SpreeAvataxOfficial::Spree::UserDecorator
Spree.user_class.prepend ::SpreeAvataxOfficial::Spree::UserDecorator
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def stock_location_cache_key(stock_location)
end

def avatax_preferences_cache_key(order)
ship_from_address_timestamp = ship_from_address_preference.try(:updated_at).try(:utc).try(:to_s, :number)
ship_from_address_timestamp = ship_from_address_preference.try(:updated_at).try(:utc).try(:to_i)

"#{company_code(order)}-#{ship_from_address_timestamp}"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%= Spree.t('avalara_entity_use_codes') %>
<% end %>
<%= render 'spree/shared/error_messages', target: @use_code %>
<%= render 'spree/admin/shared/error_messages', target: @use_code %>
<%= form_for @use_code, url: admin_avalara_entity_use_code_path(@use_code), method: :put do |f| %>
<fieldset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%= Spree.t('avalara_entity_use_codes') %>
<% end %>
<%= render 'spree/shared/error_messages', target: @use_code %>
<%= render 'spree/admin/shared/error_messages', target: @use_code %>
<%= form_for @use_code, url: admin_avalara_entity_use_codes_path, html: { multipart: true } do |f| %>
<fieldset>
Expand Down
4 changes: 2 additions & 2 deletions app/views/spree/admin/users/avalara_information.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<%= Spree.t('avalara_entity_use_codes') %>
<% end %>
<%= render partial: 'spree/admin/users/sidebar', locals: { current: :avalara_informtion } %>
<%#= render partial: 'spree/admin/users/sidebar', locals: { current: :avalara_informtion } %>

<fieldset data-hook="admin_user_edit_general_settings" class="alpha twelve columns">
<div data-hook="admin_user_edit_form_header">
<%= render partial: 'spree/shared/error_messages', locals: { target: @user } %>
<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @user } %>
</div>

<div data-hook="admin_user_edit_form">
Expand Down
14 changes: 0 additions & 14 deletions gemfiles/spree_4_2.gemfile

This file was deleted.

Loading

0 comments on commit 202c7c8

Please sign in to comment.