diff --git a/.circleci/config.yml b/.circleci/config.yml index b58334d..095e7cc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,7 +20,7 @@ commands: sudo apt-get update sudo apt-get install -yq libvips-dev - solidusio_extensions/test-branch: - branch: master + branch: main command: | export FRONTEND=starter sudo gem update --system @@ -33,26 +33,28 @@ jobs: run-specs-with-postgres: executor: name: solidusio_extensions/postgres - ruby_version: '3.1' + ruby_version: '3.2' steps: - test-with-starter-frontend run-specs-with-mysql: executor: name: solidusio_extensions/mysql - ruby_version: '3.0' + ruby_version: '3.1' steps: - test-with-starter-frontend run-specs-with-sqlite: executor: name: solidusio_extensions/sqlite - ruby_version: '2.7' + ruby_version: '3.0' steps: - test-with-starter-frontend lint-code: - executor: solidusio_extensions/sqlite-memory + executor: + name: solidusio_extensions/sqlite-memory + ruby_version: '3.0' steps: - solidusio_extensions/lint-code @@ -64,14 +66,14 @@ workflows: - run-specs-with-sqlite - lint-code - "Weekly run specs against master": + "Weekly run specs against main": triggers: - schedule: cron: "0 0 * * 4" # every Thursday filters: branches: only: - - master + - main jobs: - run-specs-with-postgres - run-specs-with-mysql diff --git a/.rubocop.yml b/.rubocop.yml index 1910451..aed1e4d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,7 +3,7 @@ require: AllCops: NewCops: disable - TargetRubyVersion: '2.7' + TargetRubyVersion: '3.0' Exclude: - sandbox/**/* - dummy-app/**/* diff --git a/app/models/solidus_paypal_commerce_platform/paypal_order.rb b/app/models/solidus_paypal_commerce_platform/paypal_order.rb index 463b52a..58c51d1 100644 --- a/app/models/solidus_paypal_commerce_platform/paypal_order.rb +++ b/app/models/solidus_paypal_commerce_platform/paypal_order.rb @@ -92,7 +92,7 @@ def breakdown item_total: price(@order.item_total), shipping: price(@order.shipment_total), tax_total: price(@order.additional_tax_total), - discount: price(@order.all_adjustments.promotion.sum(&:amount).abs) + discount: price(@order.promo_total.abs) } end diff --git a/bin/dummy-app b/bin/dummy-app index e6c085c..5acbc30 100755 --- a/bin/dummy-app +++ b/bin/dummy-app @@ -28,7 +28,7 @@ if [ ! -d "dummy-app" ]; then fi cd ./dummy-app -unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-master}" --version '> 0.a' +unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-main}" --version '> 0.a' unbundled bundle exec rake db:drop db:create unbundled bundle exec rails generate solidus:install --auto-accept --payment-method=none --no-seed --no-sample "$@" unbundled bundle add $extension_name --path .. diff --git a/bin/sandbox b/bin/sandbox index bd96ffe..3d95d5a 100755 --- a/bin/sandbox +++ b/bin/sandbox @@ -22,7 +22,7 @@ if [ ! -z $SOLIDUS_BRANCH ] then BRANCH=$SOLIDUS_BRANCH else - BRANCH="master" + BRANCH="main" fi extension_name="solidus_paypal_commerce_platform" @@ -47,7 +47,7 @@ if [ ! -d "sandbox" ]; then fi cd ./sandbox -unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-master}" --version '> 0.a' +unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-main}" --version '> 0.a' unbundled bundle exec rake db:drop db:create unbundled bundle exec rails generate solidus:install --payment-method=none --auto-accept "$@" unbundled bundle add ${extension_name} --path '../' diff --git a/solidus_paypal_commerce_platform.gemspec b/solidus_paypal_commerce_platform.gemspec index 05acb24..36cc75f 100644 --- a/solidus_paypal_commerce_platform.gemspec +++ b/solidus_paypal_commerce_platform.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| spec.metadata['changelog_uri'] = 'https://github.com/solidusio/solidus_paypal_commerce_platform/releases' spec.metadata['rubygems_mfa_required'] = 'true' - spec.required_ruby_version = Gem::Requirement.new('>= 2.7') + spec.required_ruby_version = Gem::Requirement.new('>= 3.0') # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. diff --git a/spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb b/spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb index d4bdb3a..3e2a7e1 100644 --- a/spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb +++ b/spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb @@ -70,6 +70,44 @@ ) end end + + context 'when an order has an inapplicable promo adjustment' do + let(:best_promotion) { + create(:promotion, + :with_line_item_adjustment, + :with_item_total_rule, adjustment_rate: 2.5, item_total_threshold_amount: 10, + apply_automatically: true, + promotion_actions: [ + Spree::Promotion::Actions::CreateItemAdjustments.new( + calculator: Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) + ) + ]) + } + + let(:worst_promotion) { + create(:promotion, + :with_line_item_adjustment, + :with_item_total_rule, adjustment_rate: 2.5, item_total_threshold_amount: 10, + apply_automatically: true, + promotion_actions: [ + Spree::Promotion::Actions::CreateItemAdjustments.new( + calculator: Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 5) + ) + ]) + } + + before do + best_promotion.activate(order: order) + worst_promotion.activate(order: order) + order.recalculate + end + + it 'does not include it in the paypal order breakdown' do + expect(to_json.dig(:purchase_units, 0).dig(:amount, :breakdown)).to match hash_including( + discount: { currency_code: "USD", value: "2.50" } + ) + end + end end private