From 7921331a66f0125ba2a8167782ac50b46f1dfe63 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Wed, 4 Feb 2026 09:08:02 -0800 Subject: [PATCH 1/8] Remove Solidus < v2.11 compatibility What year is it??? --- .../churn_buster/subscription_customer_serializer.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb b/lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb index cd17af3c..aaeab70c 100644 --- a/lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb +++ b/lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb @@ -5,23 +5,19 @@ module ChurnBuster class SubscriptionCustomerSerializer < Serializer def to_h { - source: 'in_house', + source: "in_house", source_id: object.id, email: object.user.email, properties: { name: name - }, + } } end private def name - if ::Spree.solidus_gem_version < Gem::Version.new('2.11.0') - "#{object.shipping_address_to_use.first_name} #{object.shipping_address_to_use.last_name}" - else - object.shipping_address_to_use.name - end + object.shipping_address_to_use.name end end end From ff395aa16fbe24eeffb285b6e91599847a810950 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Wed, 4 Feb 2026 09:31:04 -0800 Subject: [PATCH 2/8] bundle exec solidus extension . --- .circleci/config.yml | 53 +++++++++++++++ .github/stale.yml | 18 +---- .github/workflows/test.yml | 5 +- .rubocop.yml | 10 --- CHANGELOG.md | 2 +- Gemfile | 32 ++++++--- LICENSE | 2 +- .../spree/frontend/solidus_subscriptions.js | 2 + .../spree/backend/solidus_subscriptions.css | 4 ++ .../spree/frontend/solidus_subscriptions.css | 4 ++ bin/rails-sandbox | 8 +-- bin/sandbox | 68 ++++++++++--------- .../testing_support/factories.rb | 4 ++ spec/spec_helper.rb | 2 + 14 files changed, 139 insertions(+), 75 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 app/assets/javascripts/spree/frontend/solidus_subscriptions.js create mode 100644 app/assets/stylesheets/spree/backend/solidus_subscriptions.css create mode 100644 app/assets/stylesheets/spree/frontend/solidus_subscriptions.css create mode 100644 lib/solidus_subscriptions/testing_support/factories.rb diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..4370b73c --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,53 @@ +version: 2.1 + +orbs: + # Required for feature specs. + browser-tools: circleci/browser-tools@1.1 + + # Always take the latest version of the orb, this allows us to + # run specs against Solidus supported versions only without the need + # to change this configuration every time a Solidus version is released + # or goes EOL. + solidusio_extensions: solidusio/extensions@volatile + +jobs: + run-specs-with-sqlite: + executor: solidusio_extensions/sqlite + steps: + - browser-tools/install-chrome + - solidusio_extensions/run-tests + run-specs-with-postgres: + executor: solidusio_extensions/postgres + steps: + - browser-tools/install-chrome + - solidusio_extensions/run-tests + run-specs-with-mysql: + executor: solidusio_extensions/mysql + steps: + - browser-tools/install-chrome + - solidusio_extensions/run-tests + lint-code: + executor: solidusio_extensions/sqlite-memory + steps: + - solidusio_extensions/lint-code + +workflows: + "Run specs on supported Solidus versions": + jobs: + - run-specs-with-sqlite + - run-specs-with-postgres + - run-specs-with-mysql + - lint-code + + "Weekly run specs against main": + triggers: + - schedule: + cron: "0 0 * * 4" # every Thursday + filters: + branches: + only: + - main + jobs: + - run-specs-with-sqlite + - run-specs-with-postgres + - run-specs-with-mysql diff --git a/.github/stale.yml b/.github/stale.yml index 03407b31..0d0b1c99 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -1,17 +1 @@ -# Number of days of inactivity before an issue becomes stale -daysUntilStale: 60 -# Number of days of inactivity before a stale issue is closed -daysUntilClose: false -# Issues with these labels will never be considered stale -exemptLabels: - - pinned - - security -# Label to use when marking an issue as stale -staleLabel: stale -# Comment to post when marking an issue as stale. Set to `false` to disable -markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. It might be closed if no further activity occurs. Thank you - for your contributions. -# Comment to post when closing a stale issue. Set to `false` to disable -closeComment: false +_extends: .github diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 308f16ef..4579edbb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,6 +34,7 @@ jobs: - "v4.2" - "v4.3" - "v4.4" + - "v4.5" database: - "postgresql" - "mysql" @@ -52,7 +53,7 @@ jobs: - ruby-version: "3.4" rails-version: "7.0" env: - TEST_RESULTS_PATH: coverage/coverage.xml + CODECOV_COVERAGE_PATH: ./coverage/coverage.xml steps: - uses: actions/checkout@v4 - name: Run extension tests @@ -67,4 +68,4 @@ jobs: continue-on-error: true with: token: ${{ secrets.CODECOV_TOKEN }} - files: ${{ env.TEST_RESULTS_PATH }} + files: ${{ env.CODECOV_COVERAGE_PATH }} diff --git a/.rubocop.yml b/.rubocop.yml index aa0d6743..b075a8f6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,15 +1,5 @@ -inherit_from: .rubocop_todo.yml - require: - solidus_dev_support/rubocop -RSpec/DescribeClass: - Exclude: - - spec/requests/**/* - - spec/features/**/* - -Rails/SkipsModelValidations: - Enabled: false - AllCops: NewCops: disable diff --git a/CHANGELOG.md b/CHANGELOG.md index b7c3b9d4..180795a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ # Changelog -See https://github.com/solidusio/solidus_subscriptions/releases or [OLD_CHANGELOG.md](OLD_CHANGELOG.md) for older versions. +See https://github.com/solidusio/solidus_subscriptions/releases or OLD_CHANGELOG.md for older versions. diff --git a/Gemfile b/Gemfile index 30cfa727..c6ece8c9 100644 --- a/Gemfile +++ b/Gemfile @@ -7,24 +7,40 @@ branch = ENV.fetch('SOLIDUS_BRANCH', 'main') gem 'solidus', github: 'solidusio/solidus', branch: branch # The solidus_frontend gem has been pulled out since v3.2 -gem 'solidus_frontend' +if branch >= 'v3.2' + gem 'solidus_frontend' +elsif branch == 'main' + gem 'solidus_frontend', github: 'solidusio/solidus_frontend' +else + gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch +end -rails_version = ENV.fetch('RAILS_VERSION', '7.2') +rails_version = ENV.fetch('RAILS_VERSION', '7.0') gem 'rails', "~> #{rails_version}" -case ENV['DB'] +case ENV.fetch('DB', nil) when 'mysql' gem 'mysql2' when 'postgresql' gem 'pg' else - if rails_version <= "7.2" - gem 'sqlite3', "~> 1.7" - else - gem 'sqlite3', "~> 2.0" - end + gem 'sqlite3', rails_version < '7.2' ? '~> 1.4' : '~> 2.0' +end + +if rails_version == '7.0' + gem 'concurrent-ruby', '< 1.3.5' end +if RUBY_VERSION >= '3.4' + # Solidus Promotions uses CSV but does not have it as dependency yet. + gem 'csv' +end + +# While we still support Ruby < 3 we need to workaround a limitation in +# the 'async' gem that relies on the latest ruby, since RubyGems doesn't +# resolve gems based on the required ruby version. +gem 'async', '< 3' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3') + gemspec # Use a local Gemfile to include development dependencies that might not be diff --git a/LICENSE b/LICENSE index 847fd8f5..9b918e61 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2016 Stembolt +Copyright (c) 2026 Solidus Team All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/app/assets/javascripts/spree/frontend/solidus_subscriptions.js b/app/assets/javascripts/spree/frontend/solidus_subscriptions.js new file mode 100644 index 00000000..a79f2e94 --- /dev/null +++ b/app/assets/javascripts/spree/frontend/solidus_subscriptions.js @@ -0,0 +1,2 @@ +// Placeholder manifest file. +// the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js' \ No newline at end of file diff --git a/app/assets/stylesheets/spree/backend/solidus_subscriptions.css b/app/assets/stylesheets/spree/backend/solidus_subscriptions.css new file mode 100644 index 00000000..e3c23662 --- /dev/null +++ b/app/assets/stylesheets/spree/backend/solidus_subscriptions.css @@ -0,0 +1,4 @@ +/* +Placeholder manifest file. +the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css' +*/ diff --git a/app/assets/stylesheets/spree/frontend/solidus_subscriptions.css b/app/assets/stylesheets/spree/frontend/solidus_subscriptions.css new file mode 100644 index 00000000..da236237 --- /dev/null +++ b/app/assets/stylesheets/spree/frontend/solidus_subscriptions.css @@ -0,0 +1,4 @@ +/* +Placeholder manifest file. +the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css' +*/ diff --git a/bin/rails-sandbox b/bin/rails-sandbox index ad2df04d..8661d4e0 100755 --- a/bin/rails-sandbox +++ b/bin/rails-sandbox @@ -1,16 +1,16 @@ #!/usr/bin/env ruby -app_root = 'sandbox' +app_root = "sandbox" unless File.exist? "#{app_root}/bin/rails" - warn 'Creating the sandbox app...' + warn "Creating the sandbox app..." Dir.chdir "#{__dir__}/.." do system "#{__dir__}/sandbox" or begin - warn 'Automatic creation of the sandbox app failed' + warn "Automatic creation of the sandbox app failed" exit 1 end end end Dir.chdir app_root -exec 'bin/rails', *ARGV +exec "bin/rails", *ARGV diff --git a/bin/sandbox b/bin/sandbox index 8c665ac6..aa4bd817 100755 --- a/bin/sandbox +++ b/bin/sandbox @@ -1,57 +1,56 @@ #!/usr/bin/env bash set -e +test -z "${DEBUG+empty_string}" || set -x -case "$DB" in -postgres|postgresql) - RAILSDB="postgresql" - ;; -mysql) - RAILSDB="mysql" - ;; -sqlite|'') - RAILSDB="sqlite3" - ;; -*) - echo "Invalid DB specified: $DB" - exit 1 - ;; -esac +test "$DB" = "sqlite" && export DB="sqlite3" + +if [ -z "$PAYMENT_METHOD" ] +then + PAYMENT_METHOD="none" +fi -if [ ! -z $SOLIDUS_BRANCH ] +if [ -z "$SOLIDUS_BRANCH" ] then - BRANCH=$SOLIDUS_BRANCH -else - BRANCH="main" + echo "~~> Use 'export SOLIDUS_BRANCH=[main|v4.0|...]' to control the Solidus branch" + SOLIDUS_BRANCH="main" fi +echo "~~> Using branch $SOLIDUS_BRANCH of solidus" extension_name="solidus_subscriptions" # Stay away from the bundler env of the containing extension. function unbundled { - ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@ + ruby -rbundler -e' + Bundler.with_unbundled_env {system *ARGV}' -- \ + env BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES=true $@ } +echo "~~~> Removing the old sandbox" rm -rf ./sandbox -unbundled bundle exec rails new sandbox --database="$RAILSDB" \ - --skip-bundle \ + +echo "~~~> Creating a pristine Rails app" +rails_version=`bundle exec ruby -e'require "rails"; puts Rails.version'` +rails _${rails_version}_ new sandbox \ + --database="${DB:-sqlite3}" \ --skip-git \ --skip-keeps \ --skip-rc \ - --skip-spring \ - --skip-test \ - --skip-javascript + --skip-bootsnap \ + --skip-test if [ ! -d "sandbox" ]; then echo 'sandbox rails application failed' exit 1 fi +echo "~~~> Adding solidus (with i18n) to the Gemfile" cd ./sandbox cat <> Gemfile -gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH' +gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH' gem 'rails-i18n' gem 'solidus_i18n' +gem 'solidus_auth_devise' gem '$extension_name', path: '..' @@ -62,20 +61,25 @@ group :test, :development do end RUBY +echo "Generating manifest file" +mkdir -p app/assets/config +cat < app/assets/config/manifest.js +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css +MANIFESTJS + unbundled bundle install --gemfile Gemfile unbundled bundle exec rake db:drop db:create unbundled bundle exec rails generate solidus:install \ --auto-accept \ - --payment-method=none \ $@ -unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations=true +unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations +unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations echo echo "๐Ÿš€ Sandbox app successfully created for $extension_name!" -echo "๐Ÿš€ Using $RAILSDB and Solidus $BRANCH" -echo "๐Ÿš€ Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter" -echo "๐Ÿš€ Use 'export SOLIDUS_BRANCH=' to control the Solidus version" -echo "๐Ÿš€ This app is intended for test purposes." +echo "๐Ÿงช This app is intended for test purposes." diff --git a/lib/solidus_subscriptions/testing_support/factories.rb b/lib/solidus_subscriptions/testing_support/factories.rb new file mode 100644 index 00000000..745a01e4 --- /dev/null +++ b/lib/solidus_subscriptions/testing_support/factories.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +FactoryBot.define do +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6a5e2daa..9d3e91ee 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,6 +18,8 @@ # in spec/support/ and its subdirectories. Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f } +# Requires factories defined in Solidus core and this extension. +# See: lib/solidus_subscriptions/testing_support/factories.rb SolidusDevSupport::TestingSupport::Factories.load_for(SolidusSubscriptions::Engine) RSpec.configure do |config| From f94afca40a431f63e3534ed1247a36c9f9279660 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Wed, 4 Feb 2026 09:45:31 -0800 Subject: [PATCH 3/8] Reformat project --- Gemfile | 44 +- Rakefile | 6 +- .../api/v1/base_controller.rb | 2 +- .../api/v1/subscriptions_controller.rb | 6 +- .../spree/admin/installments_controller.rb | 10 +- .../admin/subscription_events_controller.rb | 10 +- .../admin/subscription_orders_controller.rb | 10 +- .../spree/admin/subscriptions_controller.rb | 66 +- .../admin/users/subscriptions_controller.rb | 2 +- .../subscription_line_items_association.rb | 2 +- .../order/installment_details_association.rb | 2 +- .../spree/order/subscription_association.rb | 2 +- .../spree/user/have_many_subscriptions.rb | 6 +- .../report_default_change_to_subscriptions.rb | 6 +- .../process_installment_job.rb | 2 +- .../solidus_subscriptions/installment.rb | 18 +- .../installment_detail.rb | 4 +- app/models/solidus_subscriptions/interval.rb | 2 +- app/models/solidus_subscriptions/line_item.rb | 12 +- .../permission_sets/default_customer.rb | 2 +- .../solidus_subscriptions/subscription.rb | 100 +-- .../subscription_event.rb | 2 +- .../admin_subscriptions_menu_link.rb | 4 +- .../admin_users_subscriptions_tab.rb | 6 +- .../event_storage_subscriber.rb | 28 +- config/routes.rb | 6 +- ...49_add_billing_address_to_subscriptions.rb | 4 +- ...951_add_payment_method_to_subscriptions.rb | 4 +- ...lidus_subscriptions_subscription_events.rb | 6 +- ...52_add_subscription_reference_to_orders.rb | 2 +- ...10323165714_update_promotion_rule_names.rb | 4 +- .../create_subscription_line_items.rb | 2 +- .../create_subscription_line_items.rb | 2 +- .../install/install_generator.rb | 30 +- lib/solidus_subscriptions.rb | 48 +- lib/solidus_subscriptions/checkout.rb | 4 +- .../churn_buster/client.rb | 16 +- .../churn_buster/order_serializer.rb | 6 +- .../subscription_payment_method_serializer.rb | 12 +- .../churn_buster/subscription_serializer.rb | 4 +- lib/solidus_subscriptions/configuration.rb | 20 +- .../dispatcher/payment_failed_dispatcher.rb | 4 +- .../dispatcher/success_dispatcher.rb | 4 +- lib/solidus_subscriptions/engine.rb | 38 +- .../permitted_attributes.rb | 2 +- .../subscription_generator.rb | 4 +- .../factories/installment_detail_factory.rb | 2 +- .../factories/installment_factory.rb | 2 +- .../factories/line_item_factory.rb | 2 +- .../factories/subscription_event_factory.rb | 4 +- .../factories/subscription_factory.rb | 12 +- lib/solidus_subscriptions/version.rb | 2 +- lib/tasks/process_subscriptions.rake | 2 +- solidus_subscriptions.gemspec | 55 +- .../concerns/create_subscription_spec.rb | 30 +- .../admin/subscriptions_controller_spec.rb | 99 +-- .../spree/api/line_items_controller_spec.rb | 73 +- .../spree/api/orders_controller_spec.rb | 19 +- .../spree/api/users_controller_spec.rb | 13 +- .../create_subscription_line_items_spec.rb | 42 +- ...ubscription_line_items_association_spec.rb | 2 +- .../installment_details_association_spec.rb | 2 +- ...ubscription_line_items_association_spec.rb | 2 +- .../user/have_many_subscriptions_spec.rb | 8 +- .../auto_delete_from_subscriptions_spec.rb | 10 +- .../admin/subscription_orders_spec.rb | 16 +- spec/features/admin/subscriptions_spec.rb | 66 +- .../admin_users_subscription_tabs_spec.rb | 44 +- .../create_subscription_job_spec.rb | 4 +- .../process_installment_job_spec.rb | 20 +- .../process_subscription_job_spec.rb | 34 +- .../solidus_subscriptions/checkout_spec.rb | 28 +- .../churn_buster/client_spec.rb | 34 +- .../dispatcher/failure_dispatcher_spec.rb | 12 +- .../out_of_stock_dispatcher_spec.rb | 4 +- .../payment_failed_dispatcher_spec.rb | 20 +- .../dispatcher/success_dispatcher_spec.rb | 12 +- .../permission_sets/default_customer_spec.rb | 16 +- .../subscription_management_spec.rb | 2 +- .../solidus_subscriptions/processor_spec.rb | 6 +- .../rules/subscription_creation_order_spec.rb | 20 +- .../subscription_installment_order_spec.rb | 14 +- .../subscription_generator_spec.rb | 24 +- spec/lib/solidus_subscriptions_spec.rb | 18 +- .../installment_detail_spec.rb | 8 +- .../solidus_subscriptions/installment_spec.rb | 76 +- .../solidus_subscriptions/line_item_spec.rb | 2 +- .../subscription_spec.rb | 712 +++++++++--------- spec/models/spree/variant_spec.rb | 4 +- .../spree/wallet_payment_source_spec.rb | 10 +- spec/requests/api/v1/line_items_spec.rb | 54 +- spec/requests/api/v1/subscriptions_spec.rb | 204 ++--- spec/spec_helper.rb | 10 +- .../churn_buster_subscriber_spec.rb | 36 +- .../order_subscriber_spec.rb | 4 +- spec/support/active_model_mocks.rb | 2 +- spec/support/cancancan.rb | 2 +- spec/support/shoulda.rb | 2 +- spec/support/timecop.rb | 2 +- spec/support/vcr.rb | 4 +- spec/support/version_cake.rb | 2 +- 101 files changed, 1243 insertions(+), 1242 deletions(-) diff --git a/Gemfile b/Gemfile index c6ece8c9..c4ea023f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,45 +1,45 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -branch = ENV.fetch('SOLIDUS_BRANCH', 'main') -gem 'solidus', github: 'solidusio/solidus', branch: branch +branch = ENV.fetch("SOLIDUS_BRANCH", "main") +gem "solidus", github: "solidusio/solidus", branch: branch # The solidus_frontend gem has been pulled out since v3.2 -if branch >= 'v3.2' - gem 'solidus_frontend' -elsif branch == 'main' - gem 'solidus_frontend', github: 'solidusio/solidus_frontend' +if branch >= "v3.2" + gem "solidus_frontend" +elsif branch == "main" + gem "solidus_frontend", github: "solidusio/solidus_frontend" else - gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch + gem "solidus_frontend", github: "solidusio/solidus", branch: branch end -rails_version = ENV.fetch('RAILS_VERSION', '7.0') -gem 'rails', "~> #{rails_version}" +rails_version = ENV.fetch("RAILS_VERSION", "7.0") +gem "rails", "~> #{rails_version}" -case ENV.fetch('DB', nil) -when 'mysql' - gem 'mysql2' -when 'postgresql' - gem 'pg' +case ENV.fetch("DB", nil) +when "mysql" + gem "mysql2" +when "postgresql" + gem "pg" else - gem 'sqlite3', rails_version < '7.2' ? '~> 1.4' : '~> 2.0' + gem "sqlite3", (rails_version < "7.2") ? "~> 1.4" : "~> 2.0" end -if rails_version == '7.0' - gem 'concurrent-ruby', '< 1.3.5' +if rails_version == "7.0" + gem "concurrent-ruby", "< 1.3.5" end -if RUBY_VERSION >= '3.4' +if RUBY_VERSION >= "3.4" # Solidus Promotions uses CSV but does not have it as dependency yet. - gem 'csv' + gem "csv" end # While we still support Ruby < 3 we need to workaround a limitation in # the 'async' gem that relies on the latest ruby, since RubyGems doesn't # resolve gems based on the required ruby version. -gem 'async', '< 3' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3') +gem "async", "< 3" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3") gemspec @@ -48,4 +48,4 @@ gemspec # # We use `send` instead of calling `eval_gemfile` to work around an issue with # how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658. -send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local' +send(:eval_gemfile, "Gemfile-local") if File.exist? "Gemfile-local" diff --git a/Rakefile b/Rakefile index 78287596..c88e538f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'bundler/gem_tasks' +require "bundler/gem_tasks" -require 'solidus_dev_support/rake_tasks' +require "solidus_dev_support/rake_tasks" SolidusDevSupport::RakeTasks.install -task default: 'extension:specs' +task default: "extension:specs" diff --git a/app/controllers/solidus_subscriptions/api/v1/base_controller.rb b/app/controllers/solidus_subscriptions/api/v1/base_controller.rb index a1cbb060..596b59fe 100644 --- a/app/controllers/solidus_subscriptions/api/v1/base_controller.rb +++ b/app/controllers/solidus_subscriptions/api/v1/base_controller.rb @@ -5,7 +5,7 @@ module Api module V1 class BaseController < ::Spree::Api::BaseController def subscription_guest_token - request.headers['X-Spree-Subscription-Token'] + request.headers["X-Spree-Subscription-Token"] end end end diff --git a/app/controllers/solidus_subscriptions/api/v1/subscriptions_controller.rb b/app/controllers/solidus_subscriptions/api/v1/subscriptions_controller.rb index 6e79671d..69c8981f 100644 --- a/app/controllers/solidus_subscriptions/api/v1/subscriptions_controller.rb +++ b/app/controllers/solidus_subscriptions/api/v1/subscriptions_controller.rb @@ -20,9 +20,9 @@ def create render json: subscription.errors.to_json, status: :unprocessable_entity end else - error_message = I18n.t('solidus_subscriptions.subscription.invalid_payment_details') + error_message = I18n.t("solidus_subscriptions.subscription.invalid_payment_details") - render json: { payment_source_type: [error_message] }.to_json, status: :unprocessable_entity + render json: {payment_source_type: [error_message]}.to_json, status: :unprocessable_entity end end @@ -93,7 +93,7 @@ def create_subscription_params def subscription_params params.require(:subscription).permit(SolidusSubscriptions.configuration.subscription_attributes | [ - line_items_attributes: line_item_attributes, + line_items_attributes: line_item_attributes ]) end diff --git a/app/controllers/spree/admin/installments_controller.rb b/app/controllers/spree/admin/installments_controller.rb index 97e6f4a8..296f80b2 100644 --- a/app/controllers/spree/admin/installments_controller.rb +++ b/app/controllers/spree/admin/installments_controller.rb @@ -3,16 +3,16 @@ module Spree module Admin class InstallmentsController < ResourceController - belongs_to 'subscription', model_class: SolidusSubscriptions::Subscription + belongs_to "subscription", model_class: SolidusSubscriptions::Subscription skip_before_action :load_resource, only: :index def index - @search = collection.ransack((params[:q] || {}).reverse_merge(s: 'created_at desc')) + @search = collection.ransack((params[:q] || {}).reverse_merge(s: "created_at desc")) - @installments = @search.result(distinct: true). - page(params[:page]). - per(params[:per_page] || Spree::Config[:orders_per_page]) + @installments = @search.result(distinct: true) + .page(params[:page]) + .per(params[:per_page] || Spree::Config[:orders_per_page]) end private diff --git a/app/controllers/spree/admin/subscription_events_controller.rb b/app/controllers/spree/admin/subscription_events_controller.rb index 71fa6f0b..29546a5b 100644 --- a/app/controllers/spree/admin/subscription_events_controller.rb +++ b/app/controllers/spree/admin/subscription_events_controller.rb @@ -3,16 +3,16 @@ module Spree module Admin class SubscriptionEventsController < ResourceController - belongs_to 'subscription', model_class: SolidusSubscriptions::Subscription + belongs_to "subscription", model_class: SolidusSubscriptions::Subscription skip_before_action :load_resource, only: :index def index - @search = collection.ransack((params[:q] || {}).reverse_merge(s: 'created_at desc')) + @search = collection.ransack((params[:q] || {}).reverse_merge(s: "created_at desc")) - @subscription_events = @search.result(distinct: true). - page(params[:page]). - per(params[:per_page] || 20) + @subscription_events = @search.result(distinct: true) + .page(params[:page]) + .per(params[:per_page] || 20) end private diff --git a/app/controllers/spree/admin/subscription_orders_controller.rb b/app/controllers/spree/admin/subscription_orders_controller.rb index dc197b61..c7bd8428 100644 --- a/app/controllers/spree/admin/subscription_orders_controller.rb +++ b/app/controllers/spree/admin/subscription_orders_controller.rb @@ -3,14 +3,14 @@ module Spree module Admin class SubscriptionOrdersController < ResourceController - belongs_to 'subscription', model_class: SolidusSubscriptions::Subscription + belongs_to "subscription", model_class: SolidusSubscriptions::Subscription def index - @search = collection.ransack((params[:q] || {}).reverse_merge(s: 'created_at desc')) + @search = collection.ransack((params[:q] || {}).reverse_merge(s: "created_at desc")) - @subscription_orders = @search.result(distinct: true). - page(params[:page]). - per(params[:per_page] || 20) + @subscription_orders = @search.result(distinct: true) + .page(params[:page]) + .per(params[:per_page] || 20) end private diff --git a/app/controllers/spree/admin/subscriptions_controller.rb b/app/controllers/spree/admin/subscriptions_controller.rb index c3f062a3..74be671d 100644 --- a/app/controllers/spree/admin/subscriptions_controller.rb +++ b/app/controllers/spree/admin/subscriptions_controller.rb @@ -7,10 +7,10 @@ class SubscriptionsController < ResourceController def index @search = SolidusSubscriptions::Subscription.accessible_by(current_ability).ransack(params[:q]) - @subscriptions = @search.result(distinct: true). - includes(:line_items, :user). - page(params[:page]). - per(params[:per_page] || Spree::Config[:orders_per_page]) + @subscriptions = @search.result(distinct: true) + .includes(:line_items, :user) + .page(params[:page]) + .per(params[:per_page] || Spree::Config[:orders_per_page]) end def new @@ -26,13 +26,11 @@ def update load_payment_methods @subscription.payment_method_id = params[:subscription][:payment_method_id] - if @subscription.payment_method&.source_required? - @subscription.payment_source = @subscription - .payment_method - .payment_source_class - .find_by(id: params[:subscription][:payment_source_id]) - else - @subscription.payment_source = nil + @subscription.payment_source = if @subscription.payment_method&.source_required? + @subscription + .payment_method + .payment_source_class + .find_by(id: params[:subscription][:payment_source_id]) end super @@ -45,10 +43,10 @@ def cancel end notice = if @subscription.errors.none? - I18n.t('spree.admin.subscriptions.successfully_canceled') - else - @subscription.errors.full_messages.to_sentence - end + I18n.t("spree.admin.subscriptions.successfully_canceled") + else + @subscription.errors.full_messages.to_sentence + end redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice) end @@ -57,10 +55,10 @@ def activate @subscription.activate notice = if @subscription.errors.none? - I18n.t('spree.admin.subscriptions.successfully_activated') - else - @subscription.errors.full_messages.to_sentence - end + I18n.t("spree.admin.subscriptions.successfully_activated") + else + @subscription.errors.full_messages.to_sentence + end redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice) end @@ -69,13 +67,13 @@ def skip @subscription.skip(check_skip_limits: false) notice = if @subscription.errors.none? - I18n.t( - 'spree.admin.subscriptions.successfully_skipped', - date: @subscription.actionable_date - ) - else - @subscription.errors.full_messages.to_sentence - end + I18n.t( + "spree.admin.subscriptions.successfully_skipped", + date: @subscription.actionable_date + ) + else + @subscription.errors.full_messages.to_sentence + end redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice) end @@ -84,10 +82,10 @@ def pause @subscription.pause(actionable_date: nil) notice = if @subscription.errors.none? - I18n.t('spree.admin.subscriptions.successfully_paused') - else - @subscription.errors.full_messages.to_sentence - end + I18n.t("spree.admin.subscriptions.successfully_paused") + else + @subscription.errors.full_messages.to_sentence + end redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice) end @@ -96,10 +94,10 @@ def resume @subscription.resume(actionable_date: nil) notice = if @subscription.errors.none? - I18n.t('spree.admin.subscriptions.successfully_resumed') - else - @subscription.errors.full_messages.to_sentence - end + I18n.t("spree.admin.subscriptions.successfully_resumed") + else + @subscription.errors.full_messages.to_sentence + end redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice) end diff --git a/app/controllers/spree/admin/users/subscriptions_controller.rb b/app/controllers/spree/admin/users/subscriptions_controller.rb index cb1548c0..ea94e34e 100644 --- a/app/controllers/spree/admin/users/subscriptions_controller.rb +++ b/app/controllers/spree/admin/users/subscriptions_controller.rb @@ -4,7 +4,7 @@ module Spree module Admin module Users class SubscriptionsController < ResourceController - belongs_to 'spree/user', model_class: Spree.user_class + belongs_to "spree/user", model_class: Spree.user_class private diff --git a/app/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association.rb b/app/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association.rb index ccb483f7..d45ea6e6 100644 --- a/app/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association.rb +++ b/app/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association.rb @@ -10,7 +10,7 @@ module SubscriptionLineItemsAssociation def self.prepended(base) base.has_many( :subscription_line_items, - class_name: 'SolidusSubscriptions::LineItem', + class_name: "SolidusSubscriptions::LineItem", foreign_key: :spree_line_item_id, inverse_of: :spree_line_item, dependent: :destroy diff --git a/app/decorators/models/solidus_subscriptions/spree/order/installment_details_association.rb b/app/decorators/models/solidus_subscriptions/spree/order/installment_details_association.rb index a1261d4c..4271da2b 100644 --- a/app/decorators/models/solidus_subscriptions/spree/order/installment_details_association.rb +++ b/app/decorators/models/solidus_subscriptions/spree/order/installment_details_association.rb @@ -5,7 +5,7 @@ module Spree module Order module InstallmentDetailsAssociation def self.prepended(base) - base.has_many :installment_details, class_name: '::SolidusSubscriptions::InstallmentDetail' + base.has_many :installment_details, class_name: "::SolidusSubscriptions::InstallmentDetail" end end end diff --git a/app/decorators/models/solidus_subscriptions/spree/order/subscription_association.rb b/app/decorators/models/solidus_subscriptions/spree/order/subscription_association.rb index 81284a34..682bf287 100644 --- a/app/decorators/models/solidus_subscriptions/spree/order/subscription_association.rb +++ b/app/decorators/models/solidus_subscriptions/spree/order/subscription_association.rb @@ -5,7 +5,7 @@ module Spree module Order module SubscriptionAssociation def self.prepended(base) - base.belongs_to :subscription, class_name: '::SolidusSubscriptions::Subscription', optional: true + base.belongs_to :subscription, class_name: "::SolidusSubscriptions::Subscription", optional: true end end end diff --git a/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb b/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb index 9fee356a..35d24744 100644 --- a/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb +++ b/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb @@ -8,8 +8,8 @@ module HaveManySubscriptions def self.prepended(base) base.has_many( :subscriptions, - class_name: 'SolidusSubscriptions::Subscription', - foreign_key: 'user_id' + class_name: "SolidusSubscriptions::Subscription", + foreign_key: "user_id" ) base.accepts_nested_attributes_for :subscriptions @@ -18,7 +18,7 @@ def self.prepended(base) def subscriptions_attributes=(params) ::Spree.deprecator.warn( "Creating or updating subscriptions through #{::Spree.user_class} nested attributes is deprecated. " \ - 'Please use subscriptions APIs directly.' + "Please use subscriptions APIs directly." ) super end diff --git a/app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb b/app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb index 065b170f..7c086bdc 100644 --- a/app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb +++ b/app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb @@ -11,12 +11,12 @@ def self.prepended(base) private def report_default_change_to_subscriptions - return if !previous_changes.key?('default') || !default? + return if !previous_changes.key?("default") || !default? user.subscriptions.with_default_payment_source.each do |subscription| ::SolidusSupport::LegacyEventCompat::Bus.publish( - :'solidus_subscriptions.subscription_payment_method_changed', - subscription: subscription, + :"solidus_subscriptions.subscription_payment_method_changed", + subscription: subscription ) end end diff --git a/app/jobs/solidus_subscriptions/process_installment_job.rb b/app/jobs/solidus_subscriptions/process_installment_job.rb index 84d077a8..e230b604 100644 --- a/app/jobs/solidus_subscriptions/process_installment_job.rb +++ b/app/jobs/solidus_subscriptions/process_installment_job.rb @@ -6,7 +6,7 @@ class ProcessInstallmentJob < ApplicationJob def perform(installment) Checkout.new(installment).process - rescue StandardError => e + rescue => e SolidusSubscriptions.configuration.processing_error_handler&.call(e, installment) end end diff --git a/app/models/solidus_subscriptions/installment.rb b/app/models/solidus_subscriptions/installment.rb index 14a92e8d..7d282dee 100644 --- a/app/models/solidus_subscriptions/installment.rb +++ b/app/models/solidus_subscriptions/installment.rb @@ -5,17 +5,17 @@ # successful or otherwise at fulfilling this installment module SolidusSubscriptions class Installment < ApplicationRecord - has_many :details, class_name: 'SolidusSubscriptions::InstallmentDetail' + has_many :details, class_name: "SolidusSubscriptions::InstallmentDetail" belongs_to( :subscription, - class_name: 'SolidusSubscriptions::Subscription', - inverse_of: :installments, + class_name: "SolidusSubscriptions::Subscription", + inverse_of: :installments ) validates :subscription, presence: true scope :fulfilled, (lambda do - joins(:details).where(InstallmentDetail.table_name => { success: true }).distinct + joins(:details).where(InstallmentDetail.table_name => {success: true}).distinct end) scope :unfulfilled, (lambda do @@ -23,7 +23,7 @@ class Installment < ApplicationRecord end) scope :with_active_subscription, (lambda do - joins(:subscription).where.not(Subscription.table_name => { state: "canceled" }) + joins(:subscription).where.not(Subscription.table_name => {state: "canceled"}) end) scope :actionable, (lambda do @@ -43,7 +43,7 @@ def out_of_stock details.create!( success: false, - message: I18n.t('solidus_subscriptions.installment_details.out_of_stock') + message: I18n.t("solidus_subscriptions.installment_details.out_of_stock") ) end @@ -60,7 +60,7 @@ def success!(order) details.create!( success: true, order: order, - message: I18n.t('solidus_subscriptions.installment_details.success') + message: I18n.t("solidus_subscriptions.installment_details.success") ) end @@ -77,7 +77,7 @@ def failed!(order) details.create!( success: false, order: order, - message: I18n.t('solidus_subscriptions.installment_details.failed') + message: I18n.t("solidus_subscriptions.installment_details.failed") ) end @@ -113,7 +113,7 @@ def payment_failed!(order) details.create!( success: false, order: order, - message: I18n.t('solidus_subscriptions.installment_details.payment_failed') + message: I18n.t("solidus_subscriptions.installment_details.payment_failed") ) if subscription.maximum_reprocessing_time_reached? && !subscription.canceled? diff --git a/app/models/solidus_subscriptions/installment_detail.rb b/app/models/solidus_subscriptions/installment_detail.rb index 90d5c0f9..ed369334 100644 --- a/app/models/solidus_subscriptions/installment_detail.rb +++ b/app/models/solidus_subscriptions/installment_detail.rb @@ -6,11 +6,11 @@ module SolidusSubscriptions class InstallmentDetail < ApplicationRecord belongs_to( :installment, - class_name: 'SolidusSubscriptions::Installment', + class_name: "SolidusSubscriptions::Installment", inverse_of: :details ) - belongs_to(:order, class_name: '::Spree::Order', optional: true) + belongs_to(:order, class_name: "::Spree::Order", optional: true) validates :installment, presence: true alias_attribute :successful, :success diff --git a/app/models/solidus_subscriptions/interval.rb b/app/models/solidus_subscriptions/interval.rb index 909ee0a9..0be51b9e 100644 --- a/app/models/solidus_subscriptions/interval.rb +++ b/app/models/solidus_subscriptions/interval.rb @@ -20,7 +20,7 @@ def self.included(base) # # @return [Integer] The number of seconds. def interval - ActiveSupport::Duration.new(interval_length, { interval_units.pluralize.to_sym => interval_length }) + ActiveSupport::Duration.new(interval_length, {interval_units.pluralize.to_sym => interval_length}) end end end diff --git a/app/models/solidus_subscriptions/line_item.rb b/app/models/solidus_subscriptions/line_item.rb index efd9d662..674448c1 100644 --- a/app/models/solidus_subscriptions/line_item.rb +++ b/app/models/solidus_subscriptions/line_item.rb @@ -22,22 +22,22 @@ class LineItem < ApplicationRecord belongs_to( :spree_line_item, - class_name: '::Spree::LineItem', + class_name: "::Spree::LineItem", inverse_of: :subscription_line_items, - optional: true, + optional: true ) - has_one :order, through: :spree_line_item, class_name: '::Spree::Order' + has_one :order, through: :spree_line_item, class_name: "::Spree::Order" belongs_to( :subscription, - class_name: 'SolidusSubscriptions::Subscription', + class_name: "SolidusSubscriptions::Subscription", inverse_of: :line_items, optional: true ) belongs_to :subscribable, class_name: "::#{SolidusSubscriptions.configuration.subscribable_class}" validates :subscribable_id, presence: true - validates :quantity, numericality: { greater_than: 0 } - validates :interval_length, numericality: { greater_than: 0 }, unless: -> { subscription } + validates :quantity, numericality: {greater_than: 0} + validates :interval_length, numericality: {greater_than: 0}, unless: -> { subscription } validate :ensure_subscribable_valid def ensure_subscribable_valid diff --git a/app/models/solidus_subscriptions/permission_sets/default_customer.rb b/app/models/solidus_subscriptions/permission_sets/default_customer.rb index 28fcf2c4..d1829214 100644 --- a/app/models/solidus_subscriptions/permission_sets/default_customer.rb +++ b/app/models/solidus_subscriptions/permission_sets/default_customer.rb @@ -14,7 +14,7 @@ def category end def activate! - can [:show, :display, :update, :skip, :cancel, :pause, :resume], Subscription, ['user_id = ?', user.id] do |subscription, guest_token| + can [:show, :display, :update, :skip, :cancel, :pause, :resume], Subscription, ["user_id = ?", user.id] do |subscription, guest_token| (subscription.guest_token.present? && subscription.guest_token == guest_token) || (subscription.user && subscription.user == user) end diff --git a/app/models/solidus_subscriptions/subscription.rb b/app/models/solidus_subscriptions/subscription.rb index 0f9ffcc3..20e46658 100644 --- a/app/models/solidus_subscriptions/subscription.rb +++ b/app/models/solidus_subscriptions/subscription.rb @@ -10,23 +10,23 @@ class Subscription < ApplicationRecord PROCESSING_STATES = [:pending, :failed, :success].freeze belongs_to :user, class_name: "::#{::Spree.user_class}" - has_many :line_items, class_name: 'SolidusSubscriptions::LineItem', inverse_of: :subscription - has_many :installments, class_name: 'SolidusSubscriptions::Installment' - has_many :installment_details, class_name: 'SolidusSubscriptions::InstallmentDetail', through: :installments, source: :details - has_many :events, class_name: 'SolidusSubscriptions::SubscriptionEvent' - has_many :orders, class_name: '::Spree::Order', inverse_of: :subscription - belongs_to :store, class_name: '::Spree::Store' - belongs_to :shipping_address, class_name: '::Spree::Address', optional: true - belongs_to :billing_address, class_name: '::Spree::Address', optional: true - belongs_to :payment_method, class_name: '::Spree::PaymentMethod', optional: true + has_many :line_items, class_name: "SolidusSubscriptions::LineItem", inverse_of: :subscription + has_many :installments, class_name: "SolidusSubscriptions::Installment" + has_many :installment_details, class_name: "SolidusSubscriptions::InstallmentDetail", through: :installments, source: :details + has_many :events, class_name: "SolidusSubscriptions::SubscriptionEvent" + has_many :orders, class_name: "::Spree::Order", inverse_of: :subscription + belongs_to :store, class_name: "::Spree::Store" + belongs_to :shipping_address, class_name: "::Spree::Address", optional: true + belongs_to :billing_address, class_name: "::Spree::Address", optional: true + belongs_to :payment_method, class_name: "::Spree::PaymentMethod", optional: true belongs_to :payment_source, polymorphic: true, optional: true validates :user, presence: true - validates :skip_count, :successive_skip_count, presence: true, numericality: { greater_than_or_equal_to: 0 } - validates :interval_length, numericality: { greater_than: 0 } + validates :skip_count, :successive_skip_count, presence: true, numericality: {greater_than_or_equal_to: 0} + validates :interval_length, numericality: {greater_than: 0} validates :payment_method, presence: true, if: -> { payment_source } validates :payment_source, presence: true, if: -> { payment_method&.source_required? } - validates :currency, inclusion: { in: ::Money::Currency.all.map(&:iso_code) } + validates :currency, inclusion: {in: ::Money::Currency.all.map(&:iso_code)} validate :validate_payment_source_ownership @@ -44,8 +44,8 @@ class Subscription < ApplicationRecord # Find all subscriptions that are "actionable"; that is, ones that have an # actionable_date in the past and are not invalid or canceled. scope :actionable, (lambda do - where("#{table_name}.actionable_date <= ?", Time.zone.today). - where.not(state: ["canceled", "inactive"]) + where("#{table_name}.actionable_date <= ?", Time.zone.today) + .where.not(state: ["canceled", "inactive"]) end) # Find subscriptions based on their processing state. This state is not a @@ -64,7 +64,7 @@ class Subscription < ApplicationRecord fulfilled_ids = fulfilled.pluck(:id) where.not(id: fulfilled_ids) when :pending - includes(:installments).where(solidus_subscriptions_installments: { id: nil }) + includes(:installments).where(solidus_subscriptions_installments: {id: nil}) else raise ArgumentError, "state must be one of: :success, :failed, :pending" end @@ -85,7 +85,7 @@ class Subscription < ApplicationRecord # Scope for finding subscription with a specific item scope :with_subscribable, (lambda do |id| - joins(line_items: :subscribable).where(spree_variants: { id: id }) + joins(line_items: :subscribable).where(spree_variants: {id: id}) end) def self.ransackable_scopes(_auth_object = nil) @@ -120,7 +120,7 @@ def self.processing_states state_machine :state, initial: :active do event :cancel do transition [:active, :pending_cancellation] => :canceled, - if: ->(subscription) { subscription.can_be_canceled? } + :if => ->(subscription) { subscription.can_be_canceled? } transition active: :pending_cancellation end @@ -186,7 +186,7 @@ def skip(check_skip_limits: true) save! advance_actionable_date.tap do - create_and_emit_event(type: 'subscription_skipped') + create_and_emit_event(type: "subscription_skipped") end end @@ -221,7 +221,7 @@ def next_actionable_date # @return [Date] The next date after the current actionable_date this # subscription will be eligible to be processed. def advance_actionable_date - create_and_emit_event(type: 'subscription_resumed') if paused? + create_and_emit_event(type: "subscription_resumed") if paused? update! actionable_date: next_actionable_date, paused: false @@ -234,7 +234,7 @@ def pause(actionable_date: nil) return true if paused? result = update! paused: true, actionable_date: actionable_date && tomorrow_or_after(actionable_date) - create_and_emit_event(type: 'subscription_paused') if result + create_and_emit_event(type: "subscription_paused") if result result end @@ -244,12 +244,12 @@ def resume(actionable_date: nil) return true unless paused? result = update! paused: false, actionable_date: tomorrow_or_after(actionable_date) - create_and_emit_event(type: 'subscription_resumed') if result + create_and_emit_event(type: "subscription_resumed") if result result end def state_with_pause - active? && paused? ? 'paused' : state + (active? && paused?) ? "paused" : state end # The state of the last attempt to process an installment associated to @@ -259,9 +259,9 @@ def state_with_pause # failed if the last installment has not been fulfilled and, success # if the last installment was fulfilled. def processing_state - return 'pending' if installments.empty? + return "pending" if installments.empty? - installments.last.fulfilled? ? 'success' : 'failed' + installments.last.fulfilled? ? "success" : "failed" end def payment_method_to_use @@ -285,16 +285,16 @@ def billing_address_to_use end def failing_since - failing_details = installment_details.failed.order('solidus_subscriptions_installment_details.created_at ASC') + failing_details = installment_details.failed.order("solidus_subscriptions_installment_details.created_at ASC") last_successful_detail = installment_details - .succeeded - .order('solidus_subscriptions_installment_details.created_at DESC') - .first + .succeeded + .order("solidus_subscriptions_installment_details.created_at DESC") + .first if last_successful_detail failing_details = failing_details.where( - 'solidus_subscriptions_installment_details.created_at > ?', - last_successful_detail.created_at, + "solidus_subscriptions_installment_details.created_at > ?", + last_successful_detail.created_at ) end @@ -320,7 +320,7 @@ def validate_payment_source_ownership return if payment_source.blank? if payment_source.respond_to?(:user_id) && - payment_source.user_id != user_id + payment_source.user_id != user_id errors.add(:payment_source, :not_owned_by_user) end end @@ -350,7 +350,7 @@ def check_invalid_pause_states errors.add(:paused, :not_active) unless active? end - alias check_invalid_resume_states check_invalid_pause_states + alias_method :check_invalid_resume_states, :check_invalid_pause_states def tomorrow_or_after(date) [date.try(:to_date), Time.zone.tomorrow].compact.max @@ -361,10 +361,10 @@ def tomorrow_or_after(date) def update_actionable_date_if_interval_changed if persisted? && (interval_length_previously_changed? || interval_units_previously_changed?) base_date = if installments.any? - installments.last.created_at - else - created_at - end + installments.last.created_at + else + created_at + end new_date = interval.since(base_date) @@ -399,7 +399,7 @@ def generate_guest_token def emit_event(type:) ::SolidusSupport::LegacyEventCompat::Bus.publish( :"solidus_subscriptions.#{type}", - subscription: self, + subscription: self ) end @@ -409,35 +409,35 @@ def create_and_emit_event(type:) end def emit_event_for_creation - emit_event(type: 'subscription_created') + emit_event(type: "subscription_created") end def emit_event_for_transition event_type = { - active: 'subscription_activated', - canceled: 'subscription_canceled', - pending_cancellation: 'subscription_canceled', - inactive: 'subscription_ended', + active: "subscription_activated", + canceled: "subscription_canceled", + pending_cancellation: "subscription_canceled", + inactive: "subscription_ended" }[state.to_sym] emit_event(type: event_type) end def emit_events_for_update - if previous_changes.key?('interval_length') || previous_changes.key?('interval_units') - emit_event(type: 'subscription_frequency_changed') + if previous_changes.key?("interval_length") || previous_changes.key?("interval_units") + emit_event(type: "subscription_frequency_changed") end - if previous_changes.key?('shipping_address_id') - emit_event(type: 'subscription_shipping_address_changed') + if previous_changes.key?("shipping_address_id") + emit_event(type: "subscription_shipping_address_changed") end - if previous_changes.key?('billing_address_id') - emit_event(type: 'subscription_billing_address_changed') + if previous_changes.key?("billing_address_id") + emit_event(type: "subscription_billing_address_changed") end - if previous_changes.key?('payment_source_id') || previous_changes.key?('payment_source_type') || previous_changes.key?('payment_method_id') - emit_event(type: 'subscription_payment_method_changed') + if previous_changes.key?("payment_source_id") || previous_changes.key?("payment_source_type") || previous_changes.key?("payment_method_id") + emit_event(type: "subscription_payment_method_changed") end end end diff --git a/app/models/solidus_subscriptions/subscription_event.rb b/app/models/solidus_subscriptions/subscription_event.rb index 9a99d8bb..929a494d 100644 --- a/app/models/solidus_subscriptions/subscription_event.rb +++ b/app/models/solidus_subscriptions/subscription_event.rb @@ -2,7 +2,7 @@ module SolidusSubscriptions class SubscriptionEvent < ApplicationRecord - belongs_to :subscription, class_name: 'SolidusSubscriptions::Subscription', inverse_of: :events + belongs_to :subscription, class_name: "SolidusSubscriptions::Subscription", inverse_of: :events after_initialize do self.details ||= {} diff --git a/app/overrides/solidus_subscriptions/admin_subscriptions_menu_link.rb b/app/overrides/solidus_subscriptions/admin_subscriptions_menu_link.rb index 9294d30d..848b0e88 100644 --- a/app/overrides/solidus_subscriptions/admin_subscriptions_menu_link.rb +++ b/app/overrides/solidus_subscriptions/admin_subscriptions_menu_link.rb @@ -4,10 +4,10 @@ module SolidusSubscriptions module AdminSubscriptionsMenuLink if !::Spree::Backend::Config.respond_to?(:menu_items) Deface::Override.new( - virtual_path: 'spree/admin/shared/_menu', + virtual_path: "spree/admin/shared/_menu", name: :add_subcriptions_admin_link, insert_bottom: "[data-hook='admin_tabs']", - partial: 'spree/admin/shared/subscription_tab' + partial: "spree/admin/shared/subscription_tab" ) end end diff --git a/app/overrides/solidus_subscriptions/admin_users_subscriptions_tab.rb b/app/overrides/solidus_subscriptions/admin_users_subscriptions_tab.rb index fcdac9bc..a3cf64e1 100644 --- a/app/overrides/solidus_subscriptions/admin_users_subscriptions_tab.rb +++ b/app/overrides/solidus_subscriptions/admin_users_subscriptions_tab.rb @@ -3,10 +3,10 @@ module SolidusSubscriptions module AdminUsersSubscriptionsTab Deface::Override.new( - virtual_path: 'spree/admin/users/_tabs', - name: 'solidus_subscriptions_admin_users_subscriptions_tab', + virtual_path: "spree/admin/users/_tabs", + name: "solidus_subscriptions_admin_users_subscriptions_tab", insert_bottom: "[data-hook='admin_user_tab_options']", - partial: 'spree/admin/users/subscription_tab' + partial: "spree/admin/users/subscription_tab" ) end end diff --git a/app/subscribers/solidus_subscriptions/event_storage_subscriber.rb b/app/subscribers/solidus_subscriptions/event_storage_subscriber.rb index a763e094..b56e4c53 100644 --- a/app/subscribers/solidus_subscriptions/event_storage_subscriber.rb +++ b/app/subscribers/solidus_subscriptions/event_storage_subscriber.rb @@ -14,50 +14,50 @@ class EventStorageSubscriber def track_subscription_created(event) event.payload.fetch(:subscription).events.create!( - event_type: 'subscription_created', - details: event.payload.fetch(:subscription).as_json, + event_type: "subscription_created", + details: event.payload.fetch(:subscription).as_json ) end def track_subscription_activated(event) event.payload.fetch(:subscription).events.create!( - event_type: 'subscription_activated', - details: event.payload.fetch(:subscription).as_json, + event_type: "subscription_activated", + details: event.payload.fetch(:subscription).as_json ) end def track_subscription_canceled(event) event.payload.fetch(:subscription).events.create!( - event_type: 'subscription_canceled', - details: event.payload.fetch(:subscription).as_json, + event_type: "subscription_canceled", + details: event.payload.fetch(:subscription).as_json ) end def track_subscription_ended(event) event.payload.fetch(:subscription).events.create!( - event_type: 'subscription_ended', - details: event.payload.fetch(:subscription).as_json, + event_type: "subscription_ended", + details: event.payload.fetch(:subscription).as_json ) end def track_subscription_shipping_address_changed(event) event.payload.fetch(:subscription).events.create!( - event_type: 'subscription_shipping_address_changed', - details: event.payload.fetch(:subscription).as_json, + event_type: "subscription_shipping_address_changed", + details: event.payload.fetch(:subscription).as_json ) end def track_subscription_billing_address_changed(event) event.payload.fetch(:subscription).events.create!( - event_type: 'subscription_billing_address_changed', - details: event.payload.fetch(:subscription).as_json, + event_type: "subscription_billing_address_changed", + details: event.payload.fetch(:subscription).as_json ) end def track_subscription_frequency_changed(event) event.payload.fetch(:subscription).events.create!( - event_type: 'subscription_frequency_changed', - details: event.payload.fetch(:subscription).as_json, + event_type: "subscription_frequency_changed", + details: event.payload.fetch(:subscription).as_json ) end end diff --git a/config/routes.rb b/config/routes.rb index d1273fa2..215d8c36 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true SolidusSubscriptions::Engine.routes.draw do - namespace :api, defaults: { format: :json } do + namespace :api, defaults: {format: :json} do namespace :v1 do resources :line_items, only: [:update, :destroy] resources :subscriptions, only: [:create, :update] do @@ -17,7 +17,7 @@ end Spree::Core::Engine.routes.draw do - mount SolidusSubscriptions::Engine, at: '/subscriptions' + mount SolidusSubscriptions::Engine, at: "/subscriptions" namespace :admin do resources :subscriptions, only: [:index, :new, :create, :edit, :update] do @@ -34,7 +34,7 @@ end resources :users do - resources :subscriptions, only: [:index], controller: 'users/subscriptions' + resources :subscriptions, only: [:index], controller: "users/subscriptions" end end end diff --git a/db/migrate/20200617102749_add_billing_address_to_subscriptions.rb b/db/migrate/20200617102749_add_billing_address_to_subscriptions.rb index e229267f..2de930aa 100644 --- a/db/migrate/20200617102749_add_billing_address_to_subscriptions.rb +++ b/db/migrate/20200617102749_add_billing_address_to_subscriptions.rb @@ -4,8 +4,8 @@ def change :solidus_subscriptions_subscriptions, :billing_address, type: :integer, - index: { name: :index_subscription_billing_address_id }, - foreign_key: { to_table: :spree_addresses } + index: {name: :index_subscription_billing_address_id}, + foreign_key: {to_table: :spree_addresses} ) end end diff --git a/db/migrate/20200618092951_add_payment_method_to_subscriptions.rb b/db/migrate/20200618092951_add_payment_method_to_subscriptions.rb index 4dfdedcd..9ff34cea 100644 --- a/db/migrate/20200618092951_add_payment_method_to_subscriptions.rb +++ b/db/migrate/20200618092951_add_payment_method_to_subscriptions.rb @@ -4,8 +4,8 @@ def change :solidus_subscriptions_subscriptions, :payment_method, type: :integer, - index: { name: :index_subscription_payment_method_id }, - foreign_key: { to_table: :spree_payment_methods } + index: {name: :index_subscription_payment_method_id}, + foreign_key: {to_table: :spree_payment_methods} ) end end diff --git a/db/migrate/20200730101242_create_solidus_subscriptions_subscription_events.rb b/db/migrate/20200730101242_create_solidus_subscriptions_subscription_events.rb index 08b1accc..bc678fa3 100644 --- a/db/migrate/20200730101242_create_solidus_subscriptions_subscription_events.rb +++ b/db/migrate/20200730101242_create_solidus_subscriptions_subscription_events.rb @@ -4,9 +4,9 @@ def change t.belongs_to( :subscription, null: false, - foreign_key: { to_table: :solidus_subscriptions_subscriptions }, - index: { name: :idx_solidus_subscription_events_on_subscription_id }, - type: :integer, + foreign_key: {to_table: :solidus_subscriptions_subscriptions}, + index: {name: :idx_solidus_subscription_events_on_subscription_id}, + type: :integer ) t.string :event_type, null: false diff --git a/db/migrate/20200917072152_add_subscription_reference_to_orders.rb b/db/migrate/20200917072152_add_subscription_reference_to_orders.rb index 6c11b409..d4ae332c 100644 --- a/db/migrate/20200917072152_add_subscription_reference_to_orders.rb +++ b/db/migrate/20200917072152_add_subscription_reference_to_orders.rb @@ -5,7 +5,7 @@ def change :subscription, null: true, type: :integer, - foreign_key: { to_table: :solidus_subscriptions_subscriptions } + foreign_key: {to_table: :solidus_subscriptions_subscriptions} ) end end diff --git a/db/migrate/20210323165714_update_promotion_rule_names.rb b/db/migrate/20210323165714_update_promotion_rule_names.rb index 1adfe1b6..4f0b57f2 100644 --- a/db/migrate/20210323165714_update_promotion_rule_names.rb +++ b/db/migrate/20210323165714_update_promotion_rule_names.rb @@ -1,7 +1,7 @@ class UpdatePromotionRuleNames < ActiveRecord::Migration[5.2] TYPE_RENAMES = { - 'SolidusSubscriptions::SubscriptionPromotionRule' => 'SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder', - 'SolidusSubscriptions::SubscriptionOrderPromotionRule' => 'SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder', + "SolidusSubscriptions::SubscriptionPromotionRule" => "SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder", + "SolidusSubscriptions::SubscriptionOrderPromotionRule" => "SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder" }.freeze def change diff --git a/lib/decorators/api/controllers/solidus_subscriptions/spree/api/line_items_controller/create_subscription_line_items.rb b/lib/decorators/api/controllers/solidus_subscriptions/spree/api/line_items_controller/create_subscription_line_items.rb index a38d3b7b..5535e2f1 100644 --- a/lib/decorators/api/controllers/solidus_subscriptions/spree/api/line_items_controller/create_subscription_line_items.rb +++ b/lib/decorators/api/controllers/solidus_subscriptions/spree/api/line_items_controller/create_subscription_line_items.rb @@ -18,7 +18,7 @@ def self.prepended(base) base.after_action( :handle_subscription_line_items, only: [:create, :update], - if: ->{ params[:subscription_line_item] } + if: -> { params[:subscription_line_item] } ) end diff --git a/lib/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb b/lib/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb index c6cb6ffa..bde5b0de 100644 --- a/lib/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb +++ b/lib/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb @@ -17,7 +17,7 @@ def self.prepended(base) base.after_action( :handle_subscription_line_items, only: :populate, - if: ->{ params[:subscription_line_item] } + if: -> { params[:subscription_line_item] } ) end diff --git a/lib/generators/solidus_subscriptions/install/install_generator.rb b/lib/generators/solidus_subscriptions/install/install_generator.rb index faa11391..1b3a0869 100644 --- a/lib/generators/solidus_subscriptions/install/install_generator.rb +++ b/lib/generators/solidus_subscriptions/install/install_generator.rb @@ -3,50 +3,50 @@ module SolidusSubscriptions module Generators class InstallGenerator < Rails::Generators::Base - source_root File.expand_path('templates', __dir__) + source_root File.expand_path("templates", __dir__) class_option :auto_run_migrations, type: :boolean, default: false # Either 'starter' or 'classic' - class_option :frontend, type: :string, default: 'starter' + class_option :frontend, type: :string, default: "starter" def copy_initializer - template 'initializer.rb', 'config/initializers/solidus_subscriptions.rb' + template "initializer.rb", "config/initializers/solidus_subscriptions.rb" end def add_javascripts - append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_subscriptions\n" + append_file "vendor/assets/javascripts/spree/backend/all.js", "//= require spree/backend/solidus_subscriptions\n" end def copy_starter_frontend_files - return if options[:frontend] != 'starter' - return unless File.exist?(Rails.root.join('app/views/cart_line_items/_product_submit.html.erb')) + return if options[:frontend] != "starter" + return unless File.exist?(Rails.root.join("app/views/cart_line_items/_product_submit.html.erb")) - copy_file 'app/views/cart_line_items/_subscription_fields.html.erb' - prepend_to_file 'app/views/cart_line_items/_product_submit.html.erb', "<%= render 'cart_line_items/subscription_fields' %>\n" + copy_file "app/views/cart_line_items/_subscription_fields.html.erb" + prepend_to_file "app/views/cart_line_items/_product_submit.html.erb", "<%= render 'cart_line_items/subscription_fields' %>\n" - copy_file 'app/controllers/concerns/create_subscription.rb' - insert_into_file 'app/controllers/cart_line_items_controller.rb', after: "class CartLineItemsController < StoreController\n" do + copy_file "app/controllers/concerns/create_subscription.rb" + insert_into_file "app/controllers/cart_line_items_controller.rb", after: "class CartLineItemsController < StoreController\n" do <<~RUBY.indent(2) include CreateSubscription RUBY end - inject_into_file 'app/views/cart_line_items/_product_variants.html.erb', + inject_into_file "app/views/cart_line_items/_product_variants.html.erb", " \"data-subscribable\" => variant.subscribable,\n", before: " \"data-price\" => variant.price_for_options(current_pricing_options)&.money&.to_html\n" end def add_migrations - run 'bin/rails railties:install:migrations FROM=solidus_subscriptions' + run "bin/rails railties:install:migrations FROM=solidus_subscriptions" end def run_migrations - run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) + run_migrations = options[:auto_run_migrations] || ["", "y", "Y"].include?(ask("Would you like to run the migrations now? [Y/n]")) if run_migrations - run 'bin/rails db:migrate' + run "bin/rails db:migrate" else - puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output + puts "Skipping bin/rails db:migrate, don't forget to run it!" # rubocop:disable Rails/Output end end end diff --git a/lib/solidus_subscriptions.rb b/lib/solidus_subscriptions.rb index 0bc25b03..6bbf7715 100644 --- a/lib/solidus_subscriptions.rb +++ b/lib/solidus_subscriptions.rb @@ -1,30 +1,30 @@ # frozen_string_literal: true -require 'solidus_core' -require 'solidus_support' +require "solidus_core" +require "solidus_support" -require 'deface' -require 'httparty' -require 'state_machines' +require "deface" +require "httparty" +require "state_machines" -require 'solidus_subscriptions/configuration' -require 'solidus_subscriptions/version' -require 'solidus_subscriptions/engine' -require 'solidus_subscriptions/churn_buster/client' -require 'solidus_subscriptions/churn_buster/serializer' -require 'solidus_subscriptions/churn_buster/subscription_customer_serializer' -require 'solidus_subscriptions/churn_buster/subscription_payment_method_serializer' -require 'solidus_subscriptions/churn_buster/subscription_serializer' -require 'solidus_subscriptions/churn_buster/order_serializer' -require 'solidus_subscriptions/checkout' -require 'solidus_subscriptions/subscription_generator' -require 'solidus_subscriptions/subscription_line_item_builder' -require 'solidus_subscriptions/dispatcher/base' -require 'solidus_subscriptions/dispatcher/failure_dispatcher' -require 'solidus_subscriptions/dispatcher/out_of_stock_dispatcher' -require 'solidus_subscriptions/dispatcher/payment_failed_dispatcher' -require 'solidus_subscriptions/dispatcher/success_dispatcher' -require 'solidus_subscriptions/order_creator' +require "solidus_subscriptions/configuration" +require "solidus_subscriptions/version" +require "solidus_subscriptions/engine" +require "solidus_subscriptions/churn_buster/client" +require "solidus_subscriptions/churn_buster/serializer" +require "solidus_subscriptions/churn_buster/subscription_customer_serializer" +require "solidus_subscriptions/churn_buster/subscription_payment_method_serializer" +require "solidus_subscriptions/churn_buster/subscription_serializer" +require "solidus_subscriptions/churn_buster/order_serializer" +require "solidus_subscriptions/checkout" +require "solidus_subscriptions/subscription_generator" +require "solidus_subscriptions/subscription_line_item_builder" +require "solidus_subscriptions/dispatcher/base" +require "solidus_subscriptions/dispatcher/failure_dispatcher" +require "solidus_subscriptions/dispatcher/out_of_stock_dispatcher" +require "solidus_subscriptions/dispatcher/payment_failed_dispatcher" +require "solidus_subscriptions/dispatcher/success_dispatcher" +require "solidus_subscriptions/order_creator" module SolidusSubscriptions class << self @@ -41,7 +41,7 @@ def churn_buster @churn_buster ||= ChurnBuster::Client.new( account_id: SolidusSubscriptions.configuration.churn_buster_account_id, - api_key: SolidusSubscriptions.configuration.churn_buster_api_key, + api_key: SolidusSubscriptions.configuration.churn_buster_api_key ) end end diff --git a/lib/solidus_subscriptions/checkout.rb b/lib/solidus_subscriptions/checkout.rb index 9b39f3a1..b2b3ab26 100644 --- a/lib/solidus_subscriptions/checkout.rb +++ b/lib/solidus_subscriptions/checkout.rb @@ -46,10 +46,10 @@ def finalize_order(order) order.checkout_steps[0...-1].each do case order.state - when 'address' + when "address" order.ship_address = installment.subscription.shipping_address_to_use order.bill_address = installment.subscription.billing_address_to_use - when 'payment' + when "payment" order.payments.create( payment_method: installment.subscription.payment_method_to_use, source: installment.subscription.payment_source_to_use, diff --git a/lib/solidus_subscriptions/churn_buster/client.rb b/lib/solidus_subscriptions/churn_buster/client.rb index 915bb409..9b272fb6 100644 --- a/lib/solidus_subscriptions/churn_buster/client.rb +++ b/lib/solidus_subscriptions/churn_buster/client.rb @@ -3,7 +3,7 @@ module SolidusSubscriptions module ChurnBuster class Client - BASE_API_URL = 'https://api.churnbuster.io/v1' + BASE_API_URL = "https://api.churnbuster.io/v1" attr_reader :account_id, :api_key @@ -13,19 +13,19 @@ def initialize(account_id:, api_key:) end def report_failed_payment(order) - post('/failed_payments', OrderSerializer.serialize(order)) + post("/failed_payments", OrderSerializer.serialize(order)) end def report_successful_payment(order) - post('/successful_payments', OrderSerializer.serialize(order)) + post("/successful_payments", OrderSerializer.serialize(order)) end def report_subscription_cancellation(subscription) - post('/cancellations', SubscriptionSerializer.serialize(subscription)) + post("/cancellations", SubscriptionSerializer.serialize(subscription)) end def report_payment_method_change(subscription) - post('/payment_methods', SubscriptionPaymentMethodSerializer.serialize(subscription)) + post("/payment_methods", SubscriptionPaymentMethodSerializer.serialize(subscription)) end private @@ -35,12 +35,12 @@ def post(path, body) "#{BASE_API_URL}#{path}", body: body.to_json, headers: { - 'Content-Type' => 'application/json', + "Content-Type" => "application/json" }, basic_auth: { username: account_id, - password: api_key, - }, + password: api_key + } ) end end diff --git a/lib/solidus_subscriptions/churn_buster/order_serializer.rb b/lib/solidus_subscriptions/churn_buster/order_serializer.rb index 5bc5dee7..81aeeb74 100644 --- a/lib/solidus_subscriptions/churn_buster/order_serializer.rb +++ b/lib/solidus_subscriptions/churn_buster/order_serializer.rb @@ -6,12 +6,12 @@ class OrderSerializer < Serializer def to_h { payment: { - source: 'in_house', + source: "in_house", source_id: object.number, amount_in_cents: object.display_total.cents, - currency: object.currency, + currency: object.currency }, - customer: SubscriptionCustomerSerializer.serialize(object.subscription), + customer: SubscriptionCustomerSerializer.serialize(object.subscription) } end end diff --git a/lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb b/lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb index 984059da..1623382c 100644 --- a/lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb +++ b/lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb @@ -6,15 +6,15 @@ class SubscriptionPaymentMethodSerializer < Serializer def to_h { payment_method: { - source: 'in_house', + source: "in_house", source_id: [ object.payment_method_to_use&.id, object.payment_source_to_use&.id - ].compact.join('-'), - type: 'card', - properties: payment_source_properties, + ].compact.join("-"), + type: "card", + properties: payment_source_properties }, - customer: SubscriptionCustomerSerializer.serialize(object), + customer: SubscriptionCustomerSerializer.serialize(object) } end @@ -26,7 +26,7 @@ def payment_source_properties brand: object.payment_source.cc_type, last4: object.payment_source.last_digits, exp_month: object.payment_source.month, - exp_year: object.payment_source.year, + exp_year: object.payment_source.year } else {} diff --git a/lib/solidus_subscriptions/churn_buster/subscription_serializer.rb b/lib/solidus_subscriptions/churn_buster/subscription_serializer.rb index 06c08d16..b8b8a809 100644 --- a/lib/solidus_subscriptions/churn_buster/subscription_serializer.rb +++ b/lib/solidus_subscriptions/churn_buster/subscription_serializer.rb @@ -6,10 +6,10 @@ class SubscriptionSerializer < Serializer def to_h { subscription: { - source: 'in_house', + source: "in_house", source_id: object.id }, - customer: SubscriptionCustomerSerializer.serialize(object), + customer: SubscriptionCustomerSerializer.serialize(object) } end end diff --git a/lib/solidus_subscriptions/configuration.rb b/lib/solidus_subscriptions/configuration.rb index cca422f2..98630a62 100644 --- a/lib/solidus_subscriptions/configuration.rb +++ b/lib/solidus_subscriptions/configuration.rb @@ -7,7 +7,7 @@ class Configuration :churn_buster_api_key, :clear_past_installments, :maximum_reprocessing_time, - :maximum_total_skips, + :maximum_total_skips ) attr_writer( @@ -24,36 +24,36 @@ class Configuration :subscription_attributes, :subscription_generator_class, :subscription_line_item_attributes, - :success_dispatcher_class, + :success_dispatcher_class ) def subscription_generator_class - @subscription_generator_class ||= 'SolidusSubscriptions::SubscriptionGenerator' + @subscription_generator_class ||= "SolidusSubscriptions::SubscriptionGenerator" @subscription_generator_class.constantize end def success_dispatcher_class - @success_dispatcher_class ||= 'SolidusSubscriptions::Dispatcher::SuccessDispatcher' + @success_dispatcher_class ||= "SolidusSubscriptions::Dispatcher::SuccessDispatcher" @success_dispatcher_class.constantize end def failure_dispatcher_class - @failure_dispatcher_class ||= 'SolidusSubscriptions::Dispatcher::FailureDispatcher' + @failure_dispatcher_class ||= "SolidusSubscriptions::Dispatcher::FailureDispatcher" @failure_dispatcher_class.constantize end def payment_failed_dispatcher_class - @payment_failed_dispatcher_class ||= 'SolidusSubscriptions::Dispatcher::PaymentFailedDispatcher' + @payment_failed_dispatcher_class ||= "SolidusSubscriptions::Dispatcher::PaymentFailedDispatcher" @payment_failed_dispatcher_class.constantize end def out_of_stock_dispatcher_class - @out_of_stock_dispatcher_class ||= 'SolidusSubscriptions::Dispatcher::OutOfStockDispatcher' + @out_of_stock_dispatcher_class ||= "SolidusSubscriptions::Dispatcher::OutOfStockDispatcher" @out_of_stock_dispatcher_class.constantize end def processing_error_handler - @processing_error_handler ||= 'SolidusSubscriptions::ProcessingErrorHandlers::RailsLogger' + @processing_error_handler ||= "SolidusSubscriptions::ProcessingErrorHandlers::RailsLogger" @processing_error_handler.constantize end @@ -97,7 +97,7 @@ def subscription_attributes end def subscribable_class - @subscribable_class ||= 'Spree::Variant' + @subscribable_class ||= "Spree::Variant" @subscribable_class.constantize end @@ -106,7 +106,7 @@ def churn_buster? end def order_creator_class - @order_creator_class ||= 'SolidusSubscriptions::OrderCreator' + @order_creator_class ||= "SolidusSubscriptions::OrderCreator" @order_creator_class.constantize end end diff --git a/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb b/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb index 69d92ad4..46027927 100644 --- a/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb +++ b/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb @@ -9,9 +9,9 @@ def dispatch installment.payment_failed!(order) ::SolidusSupport::LegacyEventCompat::Bus.publish( - :'solidus_subscriptions.installment_failed_payment', + :"solidus_subscriptions.installment_failed_payment", installment: installment, - order: order, + order: order ) end end diff --git a/lib/solidus_subscriptions/dispatcher/success_dispatcher.rb b/lib/solidus_subscriptions/dispatcher/success_dispatcher.rb index e9d8ce1b..512219d8 100644 --- a/lib/solidus_subscriptions/dispatcher/success_dispatcher.rb +++ b/lib/solidus_subscriptions/dispatcher/success_dispatcher.rb @@ -7,9 +7,9 @@ def dispatch installment.success!(order) ::SolidusSupport::LegacyEventCompat::Bus.publish( - :'solidus_subscriptions.installment_succeeded', + :"solidus_subscriptions.installment_succeeded", installment: installment, - order: order, + order: order ) end end diff --git a/lib/solidus_subscriptions/engine.rb b/lib/solidus_subscriptions/engine.rb index f8fd7c29..9f7c0990 100644 --- a/lib/solidus_subscriptions/engine.rb +++ b/lib/solidus_subscriptions/engine.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'spree/core' +require "spree/core" -require 'solidus_subscriptions' -require 'solidus_subscriptions/permitted_attributes' -require 'solidus_subscriptions/configuration' -require 'solidus_subscriptions/processor' -require 'solidus_subscriptions/processing_error_handlers/rails_logger' +require "solidus_subscriptions" +require "solidus_subscriptions/permitted_attributes" +require "solidus_subscriptions/configuration" +require "solidus_subscriptions/processor" +require "solidus_subscriptions/processing_error_handlers/rails_logger" module SolidusSubscriptions class Engine < Rails::Engine @@ -14,45 +14,45 @@ class Engine < Rails::Engine isolate_namespace SolidusSubscriptions - engine_name 'solidus_subscriptions' + engine_name "solidus_subscriptions" # use rspec for tests config.generators do |g| g.test_framework :rspec end - initializer 'solidus_subscriptions.update_permitted_attributes' do + initializer "solidus_subscriptions.update_permitted_attributes" do ::Spree::PermittedAttributes.line_item_attributes << { - subscription_line_items_attributes: PermittedAttributes.subscription_line_item_attributes | [:id], + subscription_line_items_attributes: PermittedAttributes.subscription_line_item_attributes | [:id] } ::Spree::PermittedAttributes.user_attributes << { - subscriptions_attributes: PermittedAttributes.subscription_attributes | [:id], + subscriptions_attributes: PermittedAttributes.subscription_attributes | [:id] } end if Object.const_defined?("Spree::Promotion") - initializer 'solidus_subscriptions.register_promotion_rules', after: 'spree.promo.register.promotion.rules' do |app| - app.config.spree.promotions.rules << 'SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder' - app.config.spree.promotions.rules << 'SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder' + initializer "solidus_subscriptions.register_promotion_rules", after: "spree.promo.register.promotion.rules" do |app| + app.config.spree.promotions.rules << "SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder" + app.config.spree.promotions.rules << "SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder" end end - initializer 'solidus_subscriptions.configure_backend' do + initializer "solidus_subscriptions.configure_backend" do next unless ::Spree::Backend::Config.respond_to?(:menu_items) ::Spree::Backend::Config.configure do |config| config.menu_items << config.class::MenuItem.new( [:subscriptions], - 'repeat', + "repeat", url: :admin_subscriptions_path, - condition: ->{ can?(:admin, SolidusSubscriptions::Subscription) }, - match_path: '/subscriptions' + condition: -> { can?(:admin, SolidusSubscriptions::Subscription) }, + match_path: "/subscriptions" ) end end - initializer 'solidus_subscriptions.pub_sub' do |app| + initializer "solidus_subscriptions.pub_sub" do |app| app.reloader.to_prepare do %i[ subscription_created @@ -79,6 +79,6 @@ class Engine < Rails::Engine end def self.table_name_prefix - 'solidus_subscriptions_' + "solidus_subscriptions_" end end diff --git a/lib/solidus_subscriptions/permitted_attributes.rb b/lib/solidus_subscriptions/permitted_attributes.rb index d9ec072f..2f4115e4 100644 --- a/lib/solidus_subscriptions/permitted_attributes.rb +++ b/lib/solidus_subscriptions/permitted_attributes.rb @@ -12,7 +12,7 @@ def subscription_line_item_attributes def subscription_attributes SolidusSubscriptions.configuration.subscription_attributes | [ - line_items_attributes: (subscription_line_item_attributes | [:id] - [:subscribable_id]), + line_items_attributes: (subscription_line_item_attributes | [:id] - [:subscribable_id]) ] end end diff --git a/lib/solidus_subscriptions/subscription_generator.rb b/lib/solidus_subscriptions/subscription_generator.rb index 44b0b122..f233b8c9 100644 --- a/lib/solidus_subscriptions/subscription_generator.rb +++ b/lib/solidus_subscriptions/subscription_generator.rb @@ -57,8 +57,8 @@ def activate(subscription_line_items) def group(subscription_line_items) subscription_line_items.group_by do |li| subscription_configuration(li) - end. - values + end + .values end private diff --git a/lib/solidus_subscriptions/testing_support/factories/installment_detail_factory.rb b/lib/solidus_subscriptions/testing_support/factories/installment_detail_factory.rb index 6910c0ff..51e39d85 100644 --- a/lib/solidus_subscriptions/testing_support/factories/installment_detail_factory.rb +++ b/lib/solidus_subscriptions/testing_support/factories/installment_detail_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :installment_detail, class: 'SolidusSubscriptions::InstallmentDetail' do + factory :installment_detail, class: "SolidusSubscriptions::InstallmentDetail" do installment trait(:success) { diff --git a/lib/solidus_subscriptions/testing_support/factories/installment_factory.rb b/lib/solidus_subscriptions/testing_support/factories/installment_factory.rb index 20dcc041..ec1e5cca 100644 --- a/lib/solidus_subscriptions/testing_support/factories/installment_factory.rb +++ b/lib/solidus_subscriptions/testing_support/factories/installment_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :installment, class: 'SolidusSubscriptions::Installment' do + factory :installment, class: "SolidusSubscriptions::Installment" do transient { subscription_traits { [] } } diff --git a/lib/solidus_subscriptions/testing_support/factories/line_item_factory.rb b/lib/solidus_subscriptions/testing_support/factories/line_item_factory.rb index 8d454d6d..41936efc 100644 --- a/lib/solidus_subscriptions/testing_support/factories/line_item_factory.rb +++ b/lib/solidus_subscriptions/testing_support/factories/line_item_factory.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :subscription_line_item, class: 'SolidusSubscriptions::LineItem' do + factory :subscription_line_item, class: "SolidusSubscriptions::LineItem" do subscribable_id { create(:variant, subscribable: true).id } quantity { 1 } interval_length { 1 } diff --git a/lib/solidus_subscriptions/testing_support/factories/subscription_event_factory.rb b/lib/solidus_subscriptions/testing_support/factories/subscription_event_factory.rb index 85040375..3a03e5d1 100644 --- a/lib/solidus_subscriptions/testing_support/factories/subscription_event_factory.rb +++ b/lib/solidus_subscriptions/testing_support/factories/subscription_event_factory.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true FactoryBot.define do - factory :subscription_event, class: 'SolidusSubscriptions::SubscriptionEvent' do + factory :subscription_event, class: "SolidusSubscriptions::SubscriptionEvent" do subscription - event_type { 'test_event' } + event_type { "test_event" } end end diff --git a/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb b/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb index 4cd3a1c4..e34266f8 100644 --- a/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb +++ b/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true FactoryBot.define do - factory :subscription, class: 'SolidusSubscriptions::Subscription' do + factory :subscription, class: "SolidusSubscriptions::Subscription" do store interval_length { 1 } interval_units { :month } - currency { 'USD' } + currency { "USD" } user do new_user = create(:user, :subscription_user) - card = create(:credit_card, gateway_customer_profile_id: 'BGS-123', user: new_user) + card = create(:credit_card, gateway_customer_profile_id: "BGS-123", user: new_user) wallet_payment_source = new_user.wallet.add(card) new_user.wallet.default_wallet_payment_source = wallet_payment_source new_user @@ -43,14 +43,14 @@ trait(:pending_cancellation) do actionable - state { 'pending_cancellation' } + state { "pending_cancellation" } end trait(:canceled) { - state { 'canceled' } + state { "canceled" } } trait(:inactive) { - state { 'inactive' } + state { "inactive" } } end end diff --git a/lib/solidus_subscriptions/version.rb b/lib/solidus_subscriptions/version.rb index 38a2e3e6..e40937da 100644 --- a/lib/solidus_subscriptions/version.rb +++ b/lib/solidus_subscriptions/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module SolidusSubscriptions - VERSION = '2.0.2' + VERSION = "2.0.2" end diff --git a/lib/tasks/process_subscriptions.rake b/lib/tasks/process_subscriptions.rake index 1da05ec9..99a76abb 100644 --- a/lib/tasks/process_subscriptions.rake +++ b/lib/tasks/process_subscriptions.rake @@ -1,7 +1,7 @@ # frozen_string_literal: true namespace :solidus_subscriptions do - desc 'Create orders for actionable subscriptions' + desc "Create orders for actionable subscriptions" task process: :environment do SolidusSubscriptions::Processor.run end diff --git a/solidus_subscriptions.gemspec b/solidus_subscriptions.gemspec index 2b5a8978..bc5a0b6b 100644 --- a/solidus_subscriptions.gemspec +++ b/solidus_subscriptions.gemspec @@ -1,47 +1,46 @@ # frozen_string_literal: true -require_relative 'lib/solidus_subscriptions/version' +require_relative "lib/solidus_subscriptions/version" Gem::Specification.new do |spec| - spec.name = 'solidus_subscriptions' + spec.name = "solidus_subscriptions" spec.version = SolidusSubscriptions::VERSION - spec.authors = ['Solidus Team'] - spec.email = 'contact@solidus.io' + spec.authors = ["Solidus Team"] + spec.email = "contact@solidus.io" - spec.summary = 'Add subscription support to Solidus' - spec.description = 'Add subscription support to Solidus' - spec.homepage = 'https://github.com/solidusio/solidus_subscriptions' - spec.license = 'BSD-3-Clause' + spec.summary = "Add subscription support to Solidus" + spec.description = "Add subscription support to Solidus" + spec.homepage = "https://github.com/solidusio/solidus_subscriptions" + spec.license = "BSD-3-Clause" - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = 'https://github.com/solidusio/solidus_subscriptions' - spec.metadata['changelog_uri'] = 'https://github.com/solidusio/solidus_subscriptions/releases' + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/solidusio/solidus_subscriptions" + spec.metadata["changelog_uri"] = "https://github.com/solidusio/solidus_subscriptions/releases" - spec.required_ruby_version = Gem::Requirement.new('>= 2.5') + spec.required_ruby_version = Gem::Requirement.new(">= 2.5") # 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. files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") } spec.files = files.grep_v(%r{^(test|spec|features)/}) - spec.test_files = files.grep(%r{^(test|spec|features)/}) spec.bindir = "exe" spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency 'deface' - spec.add_dependency 'httparty', '~> 0.18' - spec.add_dependency 'i18n' - spec.add_dependency 'solidus_core', '>= 2.11', '< 5' - spec.add_dependency 'solidus_support', '~> 0.11' - spec.add_dependency 'state_machines' - - spec.add_development_dependency 'rspec-activemodel-mocks' - spec.add_development_dependency 'shoulda-matchers', '~> 6.4' - spec.add_development_dependency 'solidus_dev_support', '~> 2.0' - spec.add_development_dependency 'timecop' - spec.add_development_dependency 'vcr' - spec.add_development_dependency 'versioncake' - spec.add_development_dependency 'webmock' - spec.add_development_dependency 'yard' + spec.add_dependency "deface" + spec.add_dependency "httparty", "~> 0.18" + spec.add_dependency "i18n" + spec.add_dependency "solidus_core", ">= 2.11", "< 5" + spec.add_dependency "solidus_support", "~> 0.11" + spec.add_dependency "state_machines" + + spec.add_development_dependency "rspec-activemodel-mocks" + spec.add_development_dependency "shoulda-matchers", "~> 6.4" + spec.add_development_dependency "solidus_dev_support", "~> 2.0" + spec.add_development_dependency "timecop" + spec.add_development_dependency "vcr" + spec.add_development_dependency "versioncake" + spec.add_development_dependency "webmock" + spec.add_development_dependency "yard" end diff --git a/spec/controllers/concerns/create_subscription_spec.rb b/spec/controllers/concerns/create_subscription_spec.rb index cfe1136d..87c3547d 100644 --- a/spec/controllers/concerns/create_subscription_spec.rb +++ b/spec/controllers/concerns/create_subscription_spec.rb @@ -1,5 +1,5 @@ -require 'spec_helper' -require_relative '../../../lib/generators/solidus_subscriptions/install/templates/app/controllers/concerns/create_subscription' +require "spec_helper" +require_relative "../../../lib/generators/solidus_subscriptions/install/templates/app/controllers/concerns/create_subscription" RSpec.describe CreateSubscription, type: :controller do subject(:controller_instance) do @@ -15,9 +15,9 @@ allow(controller_instance).to receive(:current_order).and_return(order) end - describe '#subscription_line_item_params_present?' do - context 'when all required params are present' do - it 'returns true' do + describe "#subscription_line_item_params_present?" do + context "when all required params are present" do + it "returns true" do controller_instance.params = { subscription_line_item: { subscribable_id: 1, @@ -29,13 +29,13 @@ end end - context 'when required params are missing' do - it 'returns false' do + context "when required params are missing" do + it "returns false" do controller_instance.params = { subscription_line_item: { - subscribable_id: '', - quantity: '', - interval_length: '' + subscribable_id: "", + quantity: "", + interval_length: "" } } expect(controller_instance.send(:valid_subscription_line_item_params?)).to be false @@ -43,12 +43,12 @@ end end - describe '#handle_subscription_line_items' do + describe "#handle_subscription_line_items" do before do allow(controller_instance).to receive(:params).and_return(params) end - context 'when subscription params are missing' do + context "when subscription params are missing" do let(:params) do { variant_id: variant.id, @@ -56,7 +56,7 @@ } end - it 'does not invoke handle_subscription_line_items and does not create a subscription line item' do + it "does not invoke handle_subscription_line_items and does not create a subscription line item" do expect(controller_instance.send(:valid_subscription_line_item_params?)).to be false expect(controller_instance).not_to receive(:handle_subscription_line_items) @@ -65,7 +65,7 @@ end end - context 'when subscription params are present' do + context "when subscription params are present" do let(:params) do { variant_id: variant.id, @@ -77,7 +77,7 @@ } end - it 'calls create_subscription_line_item with the correct line item' do + it "calls create_subscription_line_item with the correct line item" do line_item = create(:line_item, order: order, variant: variant) allow(order.line_items).to receive(:find_by).with(variant_id: variant.id).and_return(line_item) diff --git a/spec/controllers/spree/admin/subscriptions_controller_spec.rb b/spec/controllers/spree/admin/subscriptions_controller_spec.rb index 6b2b3ebc..a997bc09 100644 --- a/spec/controllers/spree/admin/subscriptions_controller_spec.rb +++ b/spec/controllers/spree/admin/subscriptions_controller_spec.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe Spree::Admin::SubscriptionsController, type: :request do extend Spree::TestingSupport::AuthorizationHelpers::Request + stub_authorization! before do @@ -14,7 +15,7 @@ ActionController::Base.allow_forgery_protection = true end - describe 'get /admin/subscriptions' do + describe "get /admin/subscriptions" do subject do get spree.admin_subscriptions_path response @@ -23,7 +24,7 @@ it { is_expected.to be_successful } end - describe 'GET :new' do + describe "GET :new" do subject do get spree.new_admin_subscription_path response @@ -32,7 +33,7 @@ it { is_expected.to be_successful } end - describe 'GET :edit' do + describe "GET :edit" do subject do get spree.edit_admin_subscription_path(subscription) response @@ -43,56 +44,56 @@ it { is_expected.to be_successful } end - describe 'PUT :update' do - it 'redirects to edit subscription page' do + describe "PUT :update" do + it "redirects to edit subscription page" do subscription = create :subscription - subscription_params = { subscription: { interval_length: 1 } } + subscription_params = {subscription: {interval_length: 1}} - expect(put(spree.admin_subscription_path(subscription), params: subscription_params)). - to redirect_to spree.edit_admin_subscription_path(subscription) + expect(put(spree.admin_subscription_path(subscription), params: subscription_params)) + .to redirect_to spree.edit_admin_subscription_path(subscription) end - it 'updates the subscription attributes', :aggregate_failures do - expected_date = DateTime.parse('2001/11/12') + it "updates the subscription attributes", :aggregate_failures do + expected_date = DateTime.parse("2001/11/12") subscription = create :subscription, :actionable - subscription_params = { subscription: { actionable_date: expected_date } } + subscription_params = {subscription: {actionable_date: expected_date}} - expect { put spree.admin_subscription_path(subscription), params: subscription_params }. - to change { subscription.reload.actionable_date }. - to expected_date + expect { put spree.admin_subscription_path(subscription), params: subscription_params } + .to change { subscription.reload.actionable_date } + .to expected_date end - it 'does not duplicate line items' do + it "does not duplicate line items" do variant = create :variant, subscribable: true subscription = create :subscription subscription_params = { subscription: { line_items_attributes: [ - { subscribable_id: variant.id, quantity: 1 } + {subscribable_id: variant.id, quantity: 1} ] } } - expect { put spree.admin_subscription_path(subscription), params: subscription_params }. - to change { subscription.reload.line_items.count }. - by 1 + expect { put spree.admin_subscription_path(subscription), params: subscription_params } + .to change { subscription.reload.line_items.count } + .by 1 end - context 'when updating the payment method' do - it 'updates the subscription payment method' do + context "when updating the payment method" do + it "updates the subscription payment method" do check_payment_method = create :check_payment_method subscription = create :subscription - subscription_params = { subscription: { payment_method_id: check_payment_method.id } } + subscription_params = {subscription: {payment_method_id: check_payment_method.id}} put spree.admin_subscription_path(subscription), params: subscription_params expect(subscription.reload).to have_attributes( payment_method: check_payment_method, - payment_source: nil, + payment_source: nil ) end - it 'updates the subscription payment source if payment method requires source' do + it "updates the subscription payment source if payment method requires source" do payment = create :credit_card_payment payment_source = payment.source payment_method = payment.payment_method @@ -101,7 +102,7 @@ subscription_params = { subscription: { payment_method_id: payment_method.id, - payment_source_id: payment_source.id, + payment_source_id: payment_source.id } } @@ -112,75 +113,75 @@ end end - describe 'POST cancel' do + describe "POST cancel" do subject(:delete_subscription) { delete spree.cancel_admin_subscription_path(subscription) } - context 'when the subscription can be canceled' do + context "when the subscription can be canceled" do let(:subscription) { create :subscription, :actionable } it { is_expected.to redirect_to spree.admin_subscriptions_path } - it 'has a message' do + it "has a message" do delete_subscription expect(flash[:notice]).to be_present end - it 'cancels the subscription' do - expect { delete_subscription }.to change { subscription.reload.state }.from('active').to('canceled') + it "cancels the subscription" do + expect { delete_subscription }.to change { subscription.reload.state }.from("active").to("canceled") end end - context 'when the subscription cannot be canceled' do + context "when the subscription cannot be canceled" do let(:subscription) { create :subscription, :canceled } it { is_expected.to redirect_to spree.admin_subscriptions_path } - it 'has a message' do + it "has a message" do delete_subscription expect(flash[:notice]).to be_present end - it 'cancels the subscription' do + it "cancels the subscription" do expect { delete_subscription }.not_to(change { subscription.reload.state }) end end end - describe 'POST activate' do + describe "POST activate" do subject(:activate) { post spree.activate_admin_subscription_path(subscription) } - context 'when the subscription can be activated' do + context "when the subscription can be activated" do let(:subscription) { create :subscription, :canceled, :with_line_item } it { is_expected.to redirect_to spree.admin_subscriptions_path } - it 'has a message' do + it "has a message" do activate expect(flash[:notice]).to be_present end - it 'cancels the subscription' do - expect { activate }.to change { subscription.reload.state }.from('canceled').to('active') + it "cancels the subscription" do + expect { activate }.to change { subscription.reload.state }.from("canceled").to("active") end end - context 'when the subscription cannot be activated' do + context "when the subscription cannot be activated" do let(:subscription) { create :subscription, :actionable, :with_line_item } it { is_expected.to redirect_to spree.admin_subscriptions_path } - it 'has a message' do + it "has a message" do activate expect(flash[:notice]).to be_present end - it 'cancels the subscription' do - expect { activate }.not_to(change{ subscription.reload.state }) + it "cancels the subscription" do + expect { activate }.not_to(change { subscription.reload.state }) end end end - describe 'POST skip' do + describe "POST skip" do subject(:skip) { post spree.skip_admin_subscription_path(subscription) } let(:subscription) { create :subscription, :actionable, :with_line_item } @@ -188,15 +189,15 @@ it { is_expected.to redirect_to spree.admin_subscriptions_path } - it 'has a message' do + it "has a message" do skip expect(flash[:notice]).to be_present end - it 'advances the actionable_date' do - expect { skip }. - to change { subscription.reload.actionable_date }. - from(subscription.actionable_date).to(expected_date) + it "advances the actionable_date" do + expect { skip } + .to change { subscription.reload.actionable_date } + .from(subscription.actionable_date).to(expected_date) end end end diff --git a/spec/controllers/spree/api/line_items_controller_spec.rb b/spec/controllers/spree/api/line_items_controller_spec.rb index 3293fc9a..8c8ac15e 100644 --- a/spec/controllers/spree/api/line_items_controller_spec.rb +++ b/spec/controllers/spree/api/line_items_controller_spec.rb @@ -1,13 +1,14 @@ # frozen_string_literal: true -require 'spec_helper' -require 'spree/api/testing_support/helpers' +require "spec_helper" +require "spree/api/testing_support/helpers" RSpec.describe Spree::Api::LineItemsController, type: :controller do include Spree::Api::TestingSupport::Helpers + routes { Spree::Core::Engine.routes } - describe 'POST :create' do + describe "POST :create" do subject(:post_create) { post :create, params: params } let(:params) { line_item_params } @@ -18,7 +19,7 @@ { order_id: order.number, order_token: order.guest_token, - format: 'json', + format: "json", line_item: { quantity: 1, variant_id: variant.id @@ -26,23 +27,23 @@ } end - shared_examples 'a new line item' do + shared_examples "a new line item" do it { is_expected.to be_created } - it 'creates a line item' do - expect { post_create }. - to change(Spree::LineItem, :count). - from(0).to(1) + it "creates a line item" do + expect { post_create } + .to change(Spree::LineItem, :count) + .from(0).to(1) end end - context 'with subscription_line_item params' do + context "with subscription_line_item params" do let(:params) { line_item_params.merge(subscription_line_item_params) } let(:subscription_line_item_params) do { subscription_line_item: { quantity: 2, - end_date: '1990/10/12', + end_date: "1990/10/12", subscribable_id: variant.id, interval_length: 30, interval_units: "day" @@ -50,26 +51,26 @@ } end - it_behaves_like 'a new line item' + it_behaves_like "a new line item" - it 'creates a new subscription line item' do - expect { post_create }. - to change(SolidusSubscriptions::LineItem, :count). - from(0).to(1) + it "creates a new subscription line item" do + expect { post_create } + .to change(SolidusSubscriptions::LineItem, :count) + .from(0).to(1) end end - context 'without subscription_line_item params' do - it_behaves_like 'a new line item' + context "without subscription_line_item params" do + it_behaves_like "a new line item" end end - describe 'patch :update' do + describe "patch :update" do subject(:patch_update) { patch :update, params: params } let(:params) { line_item_params } - context 'when adding subscription information' do + context "when adding subscription information" do let(:variant) { create :variant, subscribable: true } let(:order) { create :order } let(:line_item) { create :line_item, order: order, variant: variant } @@ -78,14 +79,14 @@ id: line_item.id, order_id: order.number, order_token: order.guest_token, - format: 'json', + format: "json", line_item: { quantity: 1, variant_id: variant.id }, subscription_line_item: { quantity: 2, - end_date: '1990/10/12', + end_date: "1990/10/12", subscribable_id: variant.id, interval_length: 30, interval_units: "day" @@ -95,14 +96,14 @@ it { is_expected.to be_successful } - it 'creates a new subscription line item' do - expect { patch_update }. - to change(SolidusSubscriptions::LineItem, :count). - from(0).to(1) + it "creates a new subscription line item" do + expect { patch_update } + .to change(SolidusSubscriptions::LineItem, :count) + .from(0).to(1) end end - context 'when updating subscription information' do + context "when updating subscription information" do let!(:line_item) { create :subscription_line_item, interval_length: 30 } let(:variant) { line_item.spree_line_item.variant } let(:order) { line_item.spree_line_item.order } @@ -111,27 +112,27 @@ id: line_item.spree_line_item.id, order_id: order.number, order_token: order.guest_token, - format: 'json', + format: "json", line_item: { - quantity: 1, + quantity: 1 }, subscription_line_items_attributes: { id: line_item.id, - interval_length: 15, + interval_length: 15 } } end it { is_expected.to be_successful } - it 'does not create a new subscription line item' do - expect { patch_update }. - not_to change(SolidusSubscriptions::LineItem, :count) + it "does not create a new subscription line item" do + expect { patch_update } + .not_to change(SolidusSubscriptions::LineItem, :count) end - it 'updates a new subscription line item' do - expect { patch_update }. - to change { line_item.reload.interval_length }.from(30).to(15) + it "updates a new subscription line item" do + expect { patch_update } + .to change { line_item.reload.interval_length }.from(30).to(15) end end end diff --git a/spec/controllers/spree/api/orders_controller_spec.rb b/spec/controllers/spree/api/orders_controller_spec.rb index 81a0f234..bb6cf147 100644 --- a/spec/controllers/spree/api/orders_controller_spec.rb +++ b/spec/controllers/spree/api/orders_controller_spec.rb @@ -1,16 +1,17 @@ # frozen_string_literal: true -require 'spec_helper' -require 'spree/api/testing_support/helpers' +require "spec_helper" +require "spree/api/testing_support/helpers" RSpec.describe Spree::Api::OrdersController, type: :controller do include Spree::Api::TestingSupport::Helpers + routes { Spree::Core::Engine.routes } let(:order) { create :order } let(:variant) { create :variant, subscribable: true } - describe 'patch /update' do + describe "patch /update" do subject(:subscription_line_items) do patch :update, params: params order.subscription_line_items.reload @@ -20,9 +21,9 @@ let(:params) do { - order: { line_items_attributes: [line_items_params] }, + order: {line_items_attributes: [line_items_params]}, id: order.to_param, - format: 'json', + format: "json", order_token: order.guest_token } end @@ -44,14 +45,14 @@ } end - it 'is a successful response' do + it "is a successful response" do subscription_line_items expect(response).to be_successful end - it 'create the correct number of subscription line items' do - expect(subscription_line_items.length). - to eq line_items_params[:subscription_line_items_attributes].length + it "create the correct number of subscription line items" do + expect(subscription_line_items.length) + .to eq line_items_params[:subscription_line_items_attributes].length end end end diff --git a/spec/controllers/spree/api/users_controller_spec.rb b/spec/controllers/spree/api/users_controller_spec.rb index f4bf4844..026990dd 100644 --- a/spec/controllers/spree/api/users_controller_spec.rb +++ b/spec/controllers/spree/api/users_controller_spec.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true -require 'spec_helper' -require 'spree/api/testing_support/helpers' +require "spec_helper" +require "spree/api/testing_support/helpers" RSpec.describe Spree::Api::UsersController, type: :controller do include Spree::Api::TestingSupport::Helpers + routes { Spree::Core::Engine.routes } let!(:user) do @@ -12,14 +13,14 @@ end let!(:subscription) { create :subscription, :with_line_item, user: user } - describe 'patch /update' do + describe "patch /update" do subject(:update_user) { patch :update, params: params } let(:params) do { id: user.id, token: user.spree_api_key, - format: 'json', + format: "json", user: { subscriptions_attributes: [{ id: subscription.id, @@ -34,11 +35,11 @@ id: subscription.line_item_ids.first, quantity: 6, interval_length: 1, - interval_units: 'month' + interval_units: "month" } end - it 'updates the subscription line items' do + it "updates the subscription line items" do allow(::Spree::Deprecation).to receive(:warn).with(a_string_matching( "Creating or updating subscriptions through #{Spree.user_class} nested attributes is deprecated" )) diff --git a/spec/decorators/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items_spec.rb b/spec/decorators/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items_spec.rb index 67543923..09a3fd21 100644 --- a/spec/decorators/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items_spec.rb +++ b/spec/decorators/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::Spree::OrdersController::CreateSubscriptionLineItems, type: :controller do controller(Spree::OrdersController) {} @@ -13,7 +13,7 @@ create :store end - describe 'POST /orders/populate' do + describe "POST /orders/populate" do subject(:populate) { post :populate, params: params } let!(:variant) { create :variant, subscribable: true } @@ -25,29 +25,29 @@ } end - shared_examples 'a new order line item' do + shared_examples "a new order line item" do it { is_expected.to redirect_to cart_path } - it 'creates an order' do - expect { populate }. - to change(Spree::Order, :count). - from(0).to(1) + it "creates an order" do + expect { populate } + .to change(Spree::Order, :count) + .from(0).to(1) end - it 'creates a line item' do - expect { populate }. - to change(Spree::LineItem, :count). - from(0).to(1) + it "creates a line item" do + expect { populate } + .to change(Spree::LineItem, :count) + .from(0).to(1) end end - context 'with subscription_line_item params' do + context "with subscription_line_item params" do let(:params) { line_item_params.merge(subscription_line_item_params) } let(:subscription_line_item_params) do { subscription_line_item: { quantity: 2, - end_date: Date.parse('2000/10/11'), + end_date: Date.parse("2000/10/11"), subscribable_id: variant.id, interval_length: 30, interval_units: "day" @@ -55,15 +55,15 @@ } end - it_behaves_like 'a new order line item' + it_behaves_like "a new order line item" - it 'creates a new subscription line item' do - expect { populate }. - to change(SolidusSubscriptions::LineItem, :count). - from(0).to(1) + it "creates a new subscription line item" do + expect { populate } + .to change(SolidusSubscriptions::LineItem, :count) + .from(0).to(1) end - it 'creates a subscription line item with the correct values' do + it "creates a subscription line item with the correct values" do populate subscription_line_item = SolidusSubscriptions::LineItem.last @@ -73,8 +73,8 @@ end end - context 'without subscription_line_item params' do - it_behaves_like 'a new order line item' + context "without subscription_line_item params" do + it_behaves_like "a new order line item" end end end diff --git a/spec/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association_spec.rb b/spec/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association_spec.rb index 0b43ad8c..403bafa9 100644 --- a/spec/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association_spec.rb +++ b/spec/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::Spree::LineItem::SubscriptionLineItemsAssociation, type: :model do subject { Spree::LineItem.new } diff --git a/spec/decorators/models/solidus_subscriptions/spree/order/installment_details_association_spec.rb b/spec/decorators/models/solidus_subscriptions/spree/order/installment_details_association_spec.rb index 98597a0b..73a1f9fb 100644 --- a/spec/decorators/models/solidus_subscriptions/spree/order/installment_details_association_spec.rb +++ b/spec/decorators/models/solidus_subscriptions/spree/order/installment_details_association_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::Spree::Order::InstallmentDetailsAssociation, type: :model do subject { Spree::Order.new } diff --git a/spec/decorators/models/solidus_subscriptions/spree/order/subscription_line_items_association_spec.rb b/spec/decorators/models/solidus_subscriptions/spree/order/subscription_line_items_association_spec.rb index 21e74c54..57a2309f 100644 --- a/spec/decorators/models/solidus_subscriptions/spree/order/subscription_line_items_association_spec.rb +++ b/spec/decorators/models/solidus_subscriptions/spree/order/subscription_line_items_association_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::Spree::Order::SubscriptionLineItemsAssociation, type: :model do subject { Spree::Order.new } diff --git a/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb b/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb index ed8aea0f..9cbd3b06 100644 --- a/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb +++ b/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::Spree::User::HaveManySubscriptions, type: :model do subject(:user) { Spree.user_class.new } @@ -8,11 +8,11 @@ it { is_expected.to have_many :subscriptions } it { is_expected.to accept_nested_attributes_for :subscriptions } - describe '#subscriptions_attributes=' do - it 'throws a deprecation warning' do + describe "#subscriptions_attributes=" do + it "throws a deprecation warning" do allow(::Spree::Deprecation).to receive(:warn) - user.subscriptions_attributes = [{ interval_length: 2 }] + user.subscriptions_attributes = [{interval_length: 2}] expect(::Spree::Deprecation) .to have_received(:warn) diff --git a/spec/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions_spec.rb b/spec/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions_spec.rb index 2276e9ec..a2a322b0 100644 --- a/spec/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions_spec.rb +++ b/spec/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions_spec.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::Spree::Variant::AutoDeleteFromSubscriptions, type: :model do subject { create(:variant, subscribable: true) } - describe '.discard' do - it 'deletes itself from subscriptions' do + describe ".discard" do + it "deletes itself from subscriptions" do subscription = create(:subscription) create(:subscription_line_item, subscription: subscription, subscribable: subject) @@ -14,8 +14,8 @@ end end - describe '.destroy' do - it 'deletes itself from subscriptions' do + describe ".destroy" do + it "deletes itself from subscriptions" do subscription = create(:subscription) create(:subscription_line_item, subscription: subscription, subscribable: subject) diff --git a/spec/features/admin/subscription_orders_spec.rb b/spec/features/admin/subscription_orders_spec.rb index 0fb0f5d2..89a7c237 100644 --- a/spec/features/admin/subscription_orders_spec.rb +++ b/spec/features/admin/subscription_orders_spec.rb @@ -1,21 +1,21 @@ # frozen_string_literal: true -RSpec.describe 'Subscription orders admin' do +RSpec.describe "Subscription orders admin" do stub_authorization! let(:subscription) { create(:subscription, :with_shipping_address, :with_billing_address) } before do visit spree.edit_admin_subscription_path(subscription) - within('.tabs') { click_link 'Orders' } + within(".tabs") { click_link "Orders" } end - it 'shows a No orders messages' do - expect(page).to have_css('legend', text: 'Orders') + it "shows a No orders messages" do + expect(page).to have_css("legend", text: "Orders") expect(page).to have_content(/No orders found/i) end - context 'with some orders' do + context "with some orders" do let(:orders) { build_list(:order, 3, subscription_order: true) } let(:subscription) do create(:subscription, :with_shipping_address, :with_billing_address).tap do |subscription| @@ -23,9 +23,9 @@ end end - it 'lists the orders of a subscription' do - expect(page).to have_css('.admin_subscription_order', count: orders.size) - within('#listing_subscription_orders') do + it "lists the orders of a subscription" do + expect(page).to have_css(".admin_subscription_order", count: orders.size) + within("#listing_subscription_orders") do orders.each do |order| expect(page).to have_content(order.number) end diff --git a/spec/features/admin/subscriptions_spec.rb b/spec/features/admin/subscriptions_spec.rb index 32f36ead..26e48033 100644 --- a/spec/features/admin/subscriptions_spec.rb +++ b/spec/features/admin/subscriptions_spec.rb @@ -1,73 +1,73 @@ # frozen_string_literal: true -RSpec.describe 'Subscriptions admin' do +RSpec.describe "Subscriptions admin" do stub_authorization! - let(:shipping_address_fieldset) { 'Shipping Address' } - let(:billing_address_fieldset) { 'Billing Address' } + let(:shipping_address_fieldset) { "Shipping Address" } + let(:billing_address_fieldset) { "Billing Address" } - it 'Updating a subscription' do + it "Updating a subscription" do subscription = create(:subscription, :with_shipping_address, :with_billing_address) visit spree.admin_path - click_link 'Subscriptions' - find('.fa-edit').click + click_link "Subscriptions" + find(".fa-edit").click within_fieldset(shipping_address_fieldset) do - fill_in 'Zip Code', with: '33166' + fill_in "Zip Code", with: "33166" end within_fieldset(billing_address_fieldset) do - fill_in 'Zip Code', with: '33167' + fill_in "Zip Code", with: "33167" end - click_button 'Update' + click_button "Update" subscription.reload - expect(subscription.shipping_address.zipcode).to eq('33166') - expect(subscription.billing_address.zipcode).to eq('33167') + expect(subscription.shipping_address.zipcode).to eq("33166") + expect(subscription.billing_address.zipcode).to eq("33167") end - it 'Creates a subscription' do + it "Creates a subscription" do variant = create(:variant, subscribable: true) create(:user) create(:store) visit spree.admin_path - click_link 'Subscriptions' - click_link 'New Subscription' - fill_in 'Actionable date', with: '01/01/2020' - fill_in 'Interval length', with: 2 - fill_in 'End date', with: '01/03/2020' + click_link "Subscriptions" + click_link "New Subscription" + fill_in "Actionable date", with: "01/01/2020" + fill_in "Interval length", with: 2 + fill_in "End date", with: "01/03/2020" [shipping_address_fieldset, billing_address_fieldset].each do |fieldset| within_fieldset(fieldset) do - name_input_label = if Spree.solidus_gem_version >= Gem::Version.new('2.11.0') - 'Name' - else - 'First Name' - end + name_input_label = if Spree.solidus_gem_version >= Gem::Version.new("2.11.0") + "Name" + else + "First Name" + end - fill_in name_input_label, with: 'John Doe' - fill_in 'Street Address', with: 'Street Address' - fill_in 'City', with: 'City' - fill_in 'Zip Code', with: '33166' - fill_in 'Phone', with: '1234567890' + fill_in name_input_label, with: "John Doe" + fill_in "Street Address", with: "Street Address" + fill_in "City", with: "City" + fill_in "Zip Code", with: "33166" + fill_in "Phone", with: "1234567890" end end - select variant.pretty_name, from: 'Subscribable' - fill_in 'Quantity', with: 1 + select variant.pretty_name, from: "Subscribable" + fill_in "Quantity", with: 1 expect(SolidusSubscriptions::Subscription.count).to eq(0) # The State field is controlled by JS, so we need to set it at the last moment # available. state_id = Spree::State.last.id.to_s - find('input#subscription_shipping_address_attributes_state_id', visible: :all).set(state_id) - find('input#subscription_billing_address_attributes_state_id', visible: :all).set(state_id) + find("input#subscription_shipping_address_attributes_state_id", visible: :all).set(state_id) + find("input#subscription_billing_address_attributes_state_id", visible: :all).set(state_id) - click_on 'Create' + click_on "Create" expect(SolidusSubscriptions::Subscription.count).to eq(1) - expect(page).to have_text('Subscription has been successfully created!') + expect(page).to have_text("Subscription has been successfully created!") end end diff --git a/spec/features/admin_users_subscription_tabs_spec.rb b/spec/features/admin_users_subscription_tabs_spec.rb index 50bd93f0..504b89de 100644 --- a/spec/features/admin_users_subscription_tabs_spec.rb +++ b/spec/features/admin_users_subscription_tabs_spec.rb @@ -1,61 +1,61 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" -RSpec.describe 'User subscriptions tab', type: :feature do +RSpec.describe "User subscriptions tab", type: :feature do stub_authorization! let(:user) { create(:user) } before do - allow(Spree.user_class).to receive(:find_by). - with(hash_including(:id)). - and_return(user) + allow(Spree.user_class).to receive(:find_by) + .with(hash_including(:id)) + .and_return(user) end - context 'when user has subscriptions' do + context "when user has subscriptions" do let!(:subscription) { create(:subscription, - actionable_date: '2020-10-21', + actionable_date: "2020-10-21", interval_length: 10, interval_units: :day, user: user) } before do - visit '/admin/' - click_link 'Users' + visit "/admin/" + click_link "Users" click_link subscription.user.email - within('.tabs') { click_link 'Subscriptions' } + within(".tabs") { click_link "Subscriptions" } end - it 'lists user subscriptions date' do - subscriptions_table = page.find('#subscriptions-table') + it "lists user subscriptions date" do + subscriptions_table = page.find("#subscriptions-table") - expect(subscriptions_table).to have_content('2020-10-21') + expect(subscriptions_table).to have_content("2020-10-21") end - it 'lists user subscriptions days' do - subscriptions_table = page.find('#subscriptions-table') + it "lists user subscriptions days" do + subscriptions_table = page.find("#subscriptions-table") - expect(subscriptions_table).to have_content('10 days') + expect(subscriptions_table).to have_content("10 days") end - it 'shows edit link to subscriptions' do + it "shows edit link to subscriptions" do page.find("#subscriptions-table td.actions a.fa-edit").click expect(page).to have_current_path spree.edit_admin_subscription_path(subscription), ignore_query: true end end - context 'when user does not have subscriptions' do - it 'displays no found message when user has no subscriptions' do + context "when user does not have subscriptions" do + it "displays no found message when user has no subscriptions" do visit spree.admin_path - click_link 'Users' + click_link "Users" click_link user.email - within('.tabs') { click_link 'Subscriptions' } + within(".tabs") { click_link "Subscriptions" } - expect(page).to have_content('No Subscriptions found.') + expect(page).to have_content("No Subscriptions found.") end end end diff --git a/spec/jobs/solidus_subscriptions/create_subscription_job_spec.rb b/spec/jobs/solidus_subscriptions/create_subscription_job_spec.rb index a705fe30..b71b9cfe 100644 --- a/spec/jobs/solidus_subscriptions/create_subscription_job_spec.rb +++ b/spec/jobs/solidus_subscriptions/create_subscription_job_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::CreateSubscriptionJob do - describe '#perform' do - it 'creates new subscriptions for an order' do + describe "#perform" do + it "creates new subscriptions for an order" do order = create(:order, :with_subscription_line_items) subscription_line_item = order.subscription_line_items.last diff --git a/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb index b0a1460c..6955922d 100644 --- a/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb +++ b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::ProcessInstallmentJob do - it 'processes checkout for the installment' do + it "processes checkout for the installment" do installment = build_stubbed(:installment) checkout = instance_spy(SolidusSubscriptions::Checkout) allow(SolidusSubscriptions::Checkout).to receive(:new).with(installment).and_return(checkout) @@ -11,11 +11,11 @@ expect(checkout).to have_received(:process) end - context 'when handling #perform errors' do - it 'by default logs exception data without raising exceptions' do + context "when handling #perform errors" do + it "by default logs exception data without raising exceptions" do installment = build_stubbed(:installment) checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c| - allow(c).to receive(:process).and_raise('test error') + allow(c).to receive(:process).and_raise("test error") end allow(SolidusSubscriptions::Checkout).to receive(:new).and_return(checkout) allow(Rails.logger).to receive(:error) @@ -28,10 +28,10 @@ expect(Rails.logger).to have_received(:error).with("test error").ordered end - it 'swallows error when a proc is not configured' do - stub_config(processing_error_handler: nil ) + it "swallows error when a proc is not configured" do + stub_config(processing_error_handler: nil) checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c| - allow(c).to receive(:process).and_raise('test error') + allow(c).to receive(:process).and_raise("test error") end allow(SolidusSubscriptions::Checkout).to receive(:new).and_return(checkout) @@ -40,10 +40,10 @@ }.not_to raise_error end - it 'runs proc when a proc is configured' do - stub_config(processing_error_handler: proc { |e| raise e } ) + it "runs proc when a proc is configured" do + stub_config(processing_error_handler: proc { |e| raise e }) checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c| - allow(c).to receive(:process).and_raise('test error') + allow(c).to receive(:process).and_raise("test error") end allow(SolidusSubscriptions::Checkout).to receive(:new).and_return(checkout) diff --git a/spec/jobs/solidus_subscriptions/process_subscription_job_spec.rb b/spec/jobs/solidus_subscriptions/process_subscription_job_spec.rb index 511c34af..976d0b8b 100644 --- a/spec/jobs/solidus_subscriptions/process_subscription_job_spec.rb +++ b/spec/jobs/solidus_subscriptions/process_subscription_job_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::ProcessSubscriptionJob do - context 'when clear_past_installments is enabled' do - it 'voids the actionable date of the unfulfilled installments' do + context "when clear_past_installments is enabled" do + it "voids the actionable date of the unfulfilled installments" do stub_config(clear_past_installments: true) subscription = create(:subscription) unfulfilled_installment = create(:installment, :failed, subscription: subscription) @@ -13,8 +13,8 @@ end end - context 'when the subscription is actionable' do - it 'resets the successive_skip_count' do + context "when the subscription is actionable" do + it "resets the successive_skip_count" do subscription = create(:subscription, :actionable, successive_skip_count: 3) described_class.perform_now(subscription) @@ -22,7 +22,7 @@ expect(subscription.reload.successive_skip_count).to eq(0) end - it 'creates a new installment' do + it "creates a new installment" do subscription = create(:subscription, :actionable) described_class.perform_now(subscription) @@ -30,9 +30,9 @@ expect(subscription.installments.count).to eq(1) end - it 'advances the actionable date' do + it "advances the actionable date" do subscription = create(:subscription, :actionable) - subscription.update_columns(interval_length: 1, interval_units: 'week') + subscription.update_columns(interval_length: 1, interval_units: "week") old_actionable_date = subscription.reload.actionable_date described_class.perform_now(subscription) @@ -41,35 +41,35 @@ end end - context 'when the subscription is pending cancellation' do - it 'cancels the subscription' do + context "when the subscription is pending cancellation" do + it "cancels the subscription" do subscription = create( :subscription, :actionable, - :pending_cancellation, + :pending_cancellation ) described_class.perform_now(subscription) - expect(subscription.reload.state).to eq('canceled') + expect(subscription.reload.state).to eq("canceled") end end - context 'when the subscription is pending of deactivation' do - it 'deactivates the subscription' do + context "when the subscription is pending of deactivation" do + it "deactivates the subscription" do subscription = create( :subscription, :actionable, - interval_units: 'week', + interval_units: "week", interval_length: 2, - end_date: 3.days.from_now, + end_date: 3.days.from_now ) described_class.perform_now(subscription) - expect(subscription.reload.state).to eq('inactive') + expect(subscription.reload.state).to eq("inactive") end end - it 'schedules all the subscription actionable installments for processing' do + it "schedules all the subscription actionable installments for processing" do subscription = create(:subscription, :actionable) unfulfilled_installment = create(:installment, :failed, subscription: subscription) diff --git a/spec/lib/solidus_subscriptions/checkout_spec.rb b/spec/lib/solidus_subscriptions/checkout_spec.rb index d15a99de..41c9a07b 100644 --- a/spec/lib/solidus_subscriptions/checkout_spec.rb +++ b/spec/lib/solidus_subscriptions/checkout_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::Checkout, :checkout do - context 'when the order can be created and paid' do - it 'creates and finalizes a new order for the installment' do + context "when the order can be created and paid" do + it "creates and finalizes a new order for the installment" do stub_spree_preferences(auto_capture: true) installment = create(:installment, :actionable) @@ -12,7 +12,7 @@ expect(order).to be_paid end - it 'copies basic information from the subscription' do + it "copies basic information from the subscription" do stub_spree_preferences(auto_capture: true) installment = create(:installment, :actionable) subscription = installment.subscription @@ -28,7 +28,7 @@ expect(order.email).to eq(subscription.user.email) end - it 'marks the order as a subscription order' do + it "marks the order as a subscription order" do stub_spree_preferences(auto_capture: true) installment = create(:installment, :actionable) subscription = installment.subscription @@ -39,7 +39,7 @@ expect(order.subscription_order).to eq(true) end - it 'matches the total on the subscription' do + it "matches the total on the subscription" do stub_spree_preferences(auto_capture: true) installment = create(:installment, :actionable) subscription = installment.subscription @@ -49,7 +49,7 @@ expect(order.item_total).to eq(subscription.line_items.first.subscribable.price) end - it 'calls the success dispatcher' do + it "calls the success dispatcher" do stub_spree_preferences(auto_capture: true) installment = create(:installment, :actionable) success_dispatcher = stub_dispatcher(SolidusSubscriptions::Dispatcher::SuccessDispatcher, installment) @@ -60,11 +60,11 @@ end end - context 'when payment of the order fails' do - it 'calls the payment failed dispatcher' do + context "when payment of the order fails" do + it "calls the payment failed dispatcher" do stub_spree_preferences(auto_capture: true) installment = create(:installment, :actionable).tap do |i| - i.subscription.update!(payment_source: create(:credit_card, number: '4111123412341234', user: i.subscription.user)) + i.subscription.update!(payment_source: create(:credit_card, number: "4111123412341234", user: i.subscription.user)) end payment_failed_dispatcher = stub_dispatcher(SolidusSubscriptions::Dispatcher::PaymentFailedDispatcher, installment) @@ -74,8 +74,8 @@ end end - context 'when an item is out of stock' do - it 'calls the out of stock dispatcher' do + context "when an item is out of stock" do + it "calls the out of stock dispatcher" do stub_spree_preferences(auto_capture: true) installment = create(:installment, :actionable).tap do |i| i.subscription.line_items.first.subscribable.stock_items.each do |stock_item| @@ -90,8 +90,8 @@ end end - context 'when a generic transition error happens during checkout' do - it 'calls the failure dispatcher' do + context "when a generic transition error happens during checkout" do + it "calls the failure dispatcher" do stub_spree_preferences(auto_capture: true) installment = create(:installment, :actionable) failure_dispatcher = stub_dispatcher(SolidusSubscriptions::Dispatcher::FailureDispatcher, installment) @@ -100,7 +100,7 @@ .and_raise(StateMachines::InvalidTransition.new( Spree::Order.new, Spree::Order.state_machines[:state], - :next, + :next )) # rubocop:enable RSpec/AnyInstance diff --git a/spec/lib/solidus_subscriptions/churn_buster/client_spec.rb b/spec/lib/solidus_subscriptions/churn_buster/client_spec.rb index 9efb2e64..42d29642 100644 --- a/spec/lib/solidus_subscriptions/churn_buster/client_spec.rb +++ b/spec/lib/solidus_subscriptions/churn_buster/client_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -RSpec.describe SolidusSubscriptions::ChurnBuster::Client, vcr: { cassette_name: 'churn_buster', record: :new_episodes } do - describe '#report_failed_payment' do - it 'reports the failed payment to Churn Buster' do +RSpec.describe SolidusSubscriptions::ChurnBuster::Client, vcr: {cassette_name: "churn_buster", record: :new_episodes} do + describe "#report_failed_payment" do + it "reports the failed payment to Churn Buster" do client = described_class.new( - account_id: 'test_account_id', - api_key: 'test_api_key', + account_id: "test_account_id", + api_key: "test_api_key" ) order = create(:order, subscription: create(:subscription)) @@ -15,11 +15,11 @@ end end - describe '#report_successful_payment' do - it 'reports the successful payment to Churn Buster' do + describe "#report_successful_payment" do + it "reports the successful payment to Churn Buster" do client = described_class.new( - account_id: 'test_account_id', - api_key: 'test_api_key', + account_id: "test_account_id", + api_key: "test_api_key" ) order = create(:order, subscription: create(:subscription)) @@ -29,11 +29,11 @@ end end - describe '#report_subscription_cancellation' do - it 'reports the failed payment to Churn Buster' do + describe "#report_subscription_cancellation" do + it "reports the failed payment to Churn Buster" do client = described_class.new( - account_id: 'test_account_id', - api_key: 'test_api_key', + account_id: "test_account_id", + api_key: "test_api_key" ) subscription = create(:subscription) @@ -43,11 +43,11 @@ end end - describe '#report_payment_method_change' do - it 'reports the payment method change to Churn Buster' do + describe "#report_payment_method_change" do + it "reports the payment method change to Churn Buster" do client = described_class.new( - account_id: 'test_account_id', - api_key: 'test_api_key', + account_id: "test_account_id", + api_key: "test_api_key" ) subscription = create(:subscription) diff --git a/spec/lib/solidus_subscriptions/dispatcher/failure_dispatcher_spec.rb b/spec/lib/solidus_subscriptions/dispatcher/failure_dispatcher_spec.rb index 0d7db952..c676d27b 100644 --- a/spec/lib/solidus_subscriptions/dispatcher/failure_dispatcher_spec.rb +++ b/spec/lib/solidus_subscriptions/dispatcher/failure_dispatcher_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::Dispatcher::FailureDispatcher do - describe '#dispatch' do - it 'marks the installment as failed' do + describe "#dispatch" do + it "marks the installment as failed" do installment = instance_spy(SolidusSubscriptions::Installment) order = create(:order_with_line_items) @@ -12,9 +12,9 @@ expect(installment).to have_received(:failed!).with(order) end - it 'cancels the order' do - if Spree.solidus_gem_version > Gem::Version.new('2.10') - skip 'Orders in `cart` state cannot be canceled starting from Solidus 2.11.' + it "cancels the order" do + if Spree.solidus_gem_version > Gem::Version.new("2.10") + skip "Orders in `cart` state cannot be canceled starting from Solidus 2.11." end installment = instance_spy(SolidusSubscriptions::Installment) @@ -23,7 +23,7 @@ dispatcher = described_class.new(installment, order) dispatcher.dispatch - expect(order.state).to eq('canceled') + expect(order.state).to eq("canceled") end end end diff --git a/spec/lib/solidus_subscriptions/dispatcher/out_of_stock_dispatcher_spec.rb b/spec/lib/solidus_subscriptions/dispatcher/out_of_stock_dispatcher_spec.rb index 4ad110fc..65c0abaa 100644 --- a/spec/lib/solidus_subscriptions/dispatcher/out_of_stock_dispatcher_spec.rb +++ b/spec/lib/solidus_subscriptions/dispatcher/out_of_stock_dispatcher_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::Dispatcher::OutOfStockDispatcher do - describe '#dispatch' do - it 'marks the installment as out of stock' do + describe "#dispatch" do + it "marks the installment as out of stock" do installment = instance_spy(SolidusSubscriptions::Installment) order = build_stubbed(:order) diff --git a/spec/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher_spec.rb b/spec/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher_spec.rb index f0945cb7..3ed181c9 100644 --- a/spec/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher_spec.rb +++ b/spec/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::Dispatcher::PaymentFailedDispatcher do - describe '#dispatch' do - it 'marks the installment as payment_failed' do + describe "#dispatch" do + it "marks the installment as payment_failed" do installment = instance_spy(SolidusSubscriptions::Installment) order = create(:order_with_line_items) @@ -12,9 +12,9 @@ expect(installment).to have_received(:payment_failed!).with(order) end - it 'cancels the order' do - if Spree.solidus_gem_version > Gem::Version.new('2.10') - skip 'Orders in `cart` state cannot be canceled starting from Solidus 2.11.' + it "cancels the order" do + if Spree.solidus_gem_version > Gem::Version.new("2.10") + skip "Orders in `cart` state cannot be canceled starting from Solidus 2.11." end installment = instance_spy(SolidusSubscriptions::Installment) @@ -23,11 +23,11 @@ dispatcher = described_class.new(installment, order) dispatcher.dispatch - expect(order.state).to eq('canceled') + expect(order.state).to eq("canceled") end - it 'fires an installments_failed_payment event' do - stub_const('SolidusSupport::LegacyEventCompat::Bus', class_spy(SolidusSupport::LegacyEventCompat::Bus)) + it "fires an installments_failed_payment event" do + stub_const("SolidusSupport::LegacyEventCompat::Bus", class_spy(SolidusSupport::LegacyEventCompat::Bus)) installment = instance_spy(SolidusSubscriptions::Installment) order = create(:order_with_line_items) @@ -35,9 +35,9 @@ dispatcher.dispatch expect(SolidusSupport::LegacyEventCompat::Bus).to have_received(:publish).with( - :'solidus_subscriptions.installment_failed_payment', + :"solidus_subscriptions.installment_failed_payment", installment: installment, - order: order, + order: order ) end end diff --git a/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb b/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb index 33b59087..eaf9e1ba 100644 --- a/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb +++ b/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::Dispatcher::SuccessDispatcher do - describe '#dispatch' do - it 'marks the installment as success' do + describe "#dispatch" do + it "marks the installment as success" do installment = instance_spy(SolidusSubscriptions::Installment) order = create(:order_with_line_items) @@ -12,8 +12,8 @@ expect(installment).to have_received(:success!).with(order) end - it 'fires an installments_succeeded event' do - stub_const('SolidusSupport::LegacyEventCompat::Bus', class_spy(SolidusSupport::LegacyEventCompat::Bus)) + it "fires an installments_succeeded event" do + stub_const("SolidusSupport::LegacyEventCompat::Bus", class_spy(SolidusSupport::LegacyEventCompat::Bus)) installment = instance_spy(SolidusSubscriptions::Installment) order = create(:order_with_line_items) @@ -21,9 +21,9 @@ dispatcher.dispatch expect(SolidusSupport::LegacyEventCompat::Bus).to have_received(:publish).with( - :'solidus_subscriptions.installment_succeeded', + :"solidus_subscriptions.installment_succeeded", installment: installment, - order: order, + order: order ) end end diff --git a/spec/lib/solidus_subscriptions/permission_sets/default_customer_spec.rb b/spec/lib/solidus_subscriptions/permission_sets/default_customer_spec.rb index febe2688..0a75f9ed 100644 --- a/spec/lib/solidus_subscriptions/permission_sets/default_customer_spec.rb +++ b/spec/lib/solidus_subscriptions/permission_sets/default_customer_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::PermissionSets::DefaultCustomer do - context 'when the user is authenticated' do - it 'is allowed to display and update their subscriptions' do + context "when the user is authenticated" do + it "is allowed to display and update their subscriptions" do user = create(:user) subscription = create(:subscription, user: user) @@ -24,7 +24,7 @@ expect(ability).not_to be_able_to([:show, :display, :update], subscription) end - it 'is allowed to display and update line items on their subscriptions' do + it "is allowed to display and update line items on their subscriptions" do user = create(:user) subscription = create(:subscription, user: user) line_item = create(:subscription_line_item, subscription: subscription) @@ -49,8 +49,8 @@ end end - context 'when the user provides a guest token' do - it 'is allowed to display and update their subscriptions' do + context "when the user provides a guest token" do + it "is allowed to display and update their subscriptions" do subscription = create(:subscription) ability = Spree::Ability.new(nil) @@ -67,10 +67,10 @@ permission_set = described_class.new(ability) permission_set.activate! - expect(ability).not_to be_able_to([:show, :display, :update], subscription, 'invalid') + expect(ability).not_to be_able_to([:show, :display, :update], subscription, "invalid") end - it 'is allowed to display and update line items on their subscriptions' do + it "is allowed to display and update line items on their subscriptions" do subscription = create(:subscription) line_item = create(:subscription_line_item, subscription: subscription) @@ -89,7 +89,7 @@ permission_set = described_class.new(ability) permission_set.activate! - expect(ability).not_to be_able_to([:show, :display, :update], line_item, 'invalid') + expect(ability).not_to be_able_to([:show, :display, :update], line_item, "invalid") end end end diff --git a/spec/lib/solidus_subscriptions/permission_sets/subscription_management_spec.rb b/spec/lib/solidus_subscriptions/permission_sets/subscription_management_spec.rb index 816f83e0..2836d076 100644 --- a/spec/lib/solidus_subscriptions/permission_sets/subscription_management_spec.rb +++ b/spec/lib/solidus_subscriptions/permission_sets/subscription_management_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::PermissionSets::SubscriptionManagement do - it 'is allowed to manage all subscriptions' do + it "is allowed to manage all subscriptions" do user = create(:user) subscription = create(:subscription) diff --git a/spec/lib/solidus_subscriptions/processor_spec.rb b/spec/lib/solidus_subscriptions/processor_spec.rb index 18811a7b..86c92af5 100644 --- a/spec/lib/solidus_subscriptions/processor_spec.rb +++ b/spec/lib/solidus_subscriptions/processor_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::Processor do - it 'schedules the processing of actionable subscriptions' do + it "schedules the processing of actionable subscriptions" do actionable_subscription = create(:subscription, :actionable) described_class.run @@ -10,7 +10,7 @@ .with(actionable_subscription) end - it 'schedules the processing of non actionable subscriptions with actionable installments' do + it "schedules the processing of non actionable subscriptions with actionable installments" do subscription_with_actionable_installment = create( :subscription, actionable_date: Time.zone.today + 7.days, @@ -23,7 +23,7 @@ .with(subscription_with_actionable_installment) end - it 'does not schedule the processing of non actionable subscriptions' do + it "does not schedule the processing of non actionable subscriptions" do non_actionable_subscription = create(:subscription, actionable_date: Time.zone.today + 14.days) described_class.run diff --git a/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb b/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb index e39e5b5a..5f067c2a 100644 --- a/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb +++ b/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb @@ -1,54 +1,54 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder do let(:rule) { described_class.new } - describe '#applicable' do + describe "#applicable" do subject { rule.applicable? promotable } - context 'when the promotable is a Spree::Order' do + context "when the promotable is a Spree::Order" do let(:promotable) { build_stubbed :order } it { is_expected.to be_truthy } end - context 'when the promotable is not a Spree::Order' do + context "when the promotable is not a Spree::Order" do let(:promotable) { build_stubbed :line_item } it { is_expected.to be_falsy } end end - describe '#eligible?' do + describe "#eligible?" do subject { rule.eligible? order } let(:order) { create(:order, line_items: line_items) } - context 'when the order contains a line item with a subscription' do + context "when the order contains a line item with a subscription" do let(:line_items) { build_list(:line_item, 1, :with_subscription_line_items) } it { is_expected.to be_truthy } end - context 'when the order does not contain a line item with a subscription' do + context "when the order does not contain a line item with a subscription" do let(:line_items) { build_list(:line_item, 1) } it { is_expected.to be_falsy } end end - describe '#actionable?' do + describe "#actionable?" do subject { rule.actionable? line_item } - context 'when the line item has a subscription' do + context "when the line item has a subscription" do let(:line_item) { build_stubbed(:line_item, :with_subscription_line_items) } it { is_expected.to be_truthy } end - context 'when the line item has no subscription' do + context "when the line item has no subscription" do let(:line_item) { build_stubbed :line_item } it { is_expected.to be_falsy } diff --git a/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb b/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb index 81e133d5..8e6de1cd 100644 --- a/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb +++ b/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb @@ -1,36 +1,36 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder do let(:rule) { described_class.new } - describe '#applicable' do + describe "#applicable" do subject { rule.applicable? promotable } - context 'when the promotable is a Spree::Order' do + context "when the promotable is a Spree::Order" do let(:promotable) { build_stubbed :order } it { is_expected.to be_truthy } end - context 'when the promotable is not a Spree::Order' do + context "when the promotable is not a Spree::Order" do let(:promotable) { build_stubbed :line_item } it { is_expected.to be_falsy } end end - describe '#eligible?' do + describe "#eligible?" do subject { rule.eligible? order } - context 'when the order fulfills a subscription installment' do + context "when the order fulfills a subscription installment" do let(:order) { create(:order, subscription_order: true) } it { is_expected.to be_truthy } end - context 'when the order contains does not fulfill a subscription installment' do + context "when the order contains does not fulfill a subscription installment" do let(:order) { create(:order) } it { is_expected.to be_falsy } diff --git a/spec/lib/solidus_subscriptions/subscription_generator_spec.rb b/spec/lib/solidus_subscriptions/subscription_generator_spec.rb index 02ed05e2..9d144e6e 100644 --- a/spec/lib/solidus_subscriptions/subscription_generator_spec.rb +++ b/spec/lib/solidus_subscriptions/subscription_generator_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::SubscriptionGenerator do - describe '.activate' do - it 'creates the correct number of subscriptions' do + describe ".activate" do + it "creates the correct number of subscriptions" do subscription_line_items = build_list(:subscription_line_item, 2) expect { @@ -12,7 +12,7 @@ }.to change(SolidusSubscriptions::Subscription, :count).by(1) end - it 'creates subscriptions with the correct attributes', :aggregate_failures do + it "creates subscriptions with the correct attributes", :aggregate_failures do subscription_line_items = build_list(:subscription_line_item, 2) subscription_line_item = subscription_line_items.first @@ -31,25 +31,25 @@ ) end - it 'copies the payment method from the order' do + it "copies the payment method from the order" do subscription_line_item = build(:subscription_line_item) payment_method = create(:credit_card_payment_method) payment_source = create(:credit_card, payment_method: payment_method, user: subscription_line_item.order.user) create(:payment, order: subscription_line_item.spree_line_item.order, source: payment_source, - payment_method: payment_method,) + payment_method: payment_method) subscription = described_class.activate([subscription_line_item]) expect(subscription).to have_attributes( payment_method: payment_method, - payment_source: payment_source, + payment_source: payment_source ) end - it 'cleanups the subscription line items fields duplicated on the subscription' do - attrs = { interval_length: 2, interval_units: :week, end_date: Time.zone.tomorrow } + it "cleanups the subscription line items fields duplicated on the subscription" do + attrs = {interval_length: 2, interval_units: :week, end_date: Time.zone.tomorrow} subscription_line_item = create(:subscription_line_item, attrs) described_class.activate([subscription_line_item]) @@ -62,8 +62,8 @@ end end - describe '.group' do - it 'groups subscriptions by interval and end date' do + describe ".group" do + it "groups subscriptions by interval and end date" do monthly_subscriptions = build_stubbed_list(:subscription_line_item, 2) bimonthly_subscriptions = build_stubbed_list(:subscription_line_item, 2, interval_length: 2) weekly_subscriptions = build_stubbed_list(:subscription_line_item, 2, interval_units: :week) @@ -73,7 +73,7 @@ monthly_subscriptions, bimonthly_subscriptions, weekly_subscriptions, - expiring_subscriptions, + expiring_subscriptions ] grouping_result = described_class.group(subscriptions.flatten) diff --git a/spec/lib/solidus_subscriptions_spec.rb b/spec/lib/solidus_subscriptions_spec.rb index f99119f5..95dd72f2 100644 --- a/spec/lib/solidus_subscriptions_spec.rb +++ b/spec/lib/solidus_subscriptions_spec.rb @@ -1,26 +1,26 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions do - describe '.churn_buster' do - context 'when Churn Buster was configured' do - it 'returns a Churn Buster client instance' do + describe ".churn_buster" do + context "when Churn Buster was configured" do + it "returns a Churn Buster client instance" do allow(described_class.configuration).to receive_messages( churn_buster?: true, - churn_buster_account_id: 'account_id', - churn_buster_api_key: 'api_key', + churn_buster_account_id: "account_id", + churn_buster_api_key: "api_key" ) churn_buster = instance_double(SolidusSubscriptions::ChurnBuster::Client) allow(SolidusSubscriptions::ChurnBuster::Client).to receive(:new).with( - account_id: 'account_id', - api_key: 'api_key', + account_id: "account_id", + api_key: "api_key" ).and_return(churn_buster) expect(described_class.churn_buster).to eq(churn_buster) end end - context 'when Churn Buster was not configured' do - it 'returns nil' do + context "when Churn Buster was not configured" do + it "returns nil" do allow(described_class.configuration).to receive_messages(churn_buster?: false) expect(described_class.churn_buster).to be_nil diff --git a/spec/models/solidus_subscriptions/installment_detail_spec.rb b/spec/models/solidus_subscriptions/installment_detail_spec.rb index 8c03f4d6..94d9f4fe 100644 --- a/spec/models/solidus_subscriptions/installment_detail_spec.rb +++ b/spec/models/solidus_subscriptions/installment_detail_spec.rb @@ -1,20 +1,20 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::InstallmentDetail, type: :model do it { is_expected.to validate_presence_of :installment } - describe '#failed?' do + describe "#failed?" do subject { build(:installment_detail, success: success).failed? } - context 'when the detail was successful' do + context "when the detail was successful" do let(:success) { true } it { is_expected.to be_falsy } end - context 'when the detail was not successfuly' do + context "when the detail was not successfuly" do let(:success) { false } it { is_expected.to be_truthy } diff --git a/spec/models/solidus_subscriptions/installment_spec.rb b/spec/models/solidus_subscriptions/installment_spec.rb index 2d36ce06..e11efef8 100644 --- a/spec/models/solidus_subscriptions/installment_spec.rb +++ b/spec/models/solidus_subscriptions/installment_spec.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::Installment, type: :model do let(:installment) { create :installment } it { is_expected.to validate_presence_of :subscription } - describe '#out_of_stock' do + describe "#out_of_stock" do subject(:out_of_stock) { installment.out_of_stock } let(:expected_date) do @@ -17,20 +17,20 @@ it { is_expected.to be_a SolidusSubscriptions::InstallmentDetail } it { is_expected.not_to be_successful } - it 'has the correct message' do + it "has the correct message" do expect(out_of_stock).to have_attributes( - message: I18n.t('solidus_subscriptions.installment_details.out_of_stock') + message: I18n.t("solidus_subscriptions.installment_details.out_of_stock") ) end - it 'advances the installment actionable_date' do + it "advances the installment actionable_date" do out_of_stock actionable_date = installment.reload.actionable_date expect(actionable_date).to eq expected_date end end - describe '#success!' do + describe "#success!" do subject(:success) { installment.success!(order) } let(:order) { create :order } @@ -38,28 +38,28 @@ let(:installment) { create :installment, actionable_date: actionable_date } let(:actionable_date) { 1.month.from_now.to_date } - it 'removes any actionable date if any' do - expect { success }. - to change(installment, :actionable_date). - from(actionable_date).to(nil) + it "removes any actionable date if any" do + expect { success } + .to change(installment, :actionable_date) + .from(actionable_date).to(nil) end - it 'creates a new installment detail' do - expect { success }. - to change(SolidusSubscriptions::InstallmentDetail, :count). - by(1) + it "creates a new installment detail" do + expect { success } + .to change(SolidusSubscriptions::InstallmentDetail, :count) + .by(1) end - it 'creates a successful installment detail' do + it "creates a successful installment detail" do success expect(installment.details.last).to be_successful && have_attributes( order: order, - message: I18n.t('solidus_subscriptions.installment_details.success') + message: I18n.t("solidus_subscriptions.installment_details.success") ) end end - describe '#failed!' do + describe "#failed!" do subject(:failed) { installment.failed!(order) } let(:order) { create :order } @@ -71,23 +71,23 @@ it { is_expected.to be_a SolidusSubscriptions::InstallmentDetail } it { is_expected.not_to be_successful } - it 'has the correct message' do + it "has the correct message" do expect(failed).to have_attributes( - message: I18n.t('solidus_subscriptions.installment_details.failed'), + message: I18n.t("solidus_subscriptions.installment_details.failed"), order: order ) end - it 'advances the installment actionable_date' do + it "advances the installment actionable_date" do failed actionable_date = installment.reload.actionable_date expect(actionable_date).to eq expected_date end - context 'when the reprocessing interval is set to nil' do + context "when the reprocessing interval is set to nil" do before { stub_config(reprocessing_interval: nil) } - it 'does not advance the installment actionable_date' do + it "does not advance the installment actionable_date" do failed actionable_date = installment.reload.actionable_date expect(actionable_date).to be_nil @@ -95,45 +95,45 @@ end end - describe '#unfulfilled?' do + describe "#unfulfilled?" do subject { installment.unfulfilled? } let(:installment) { create(:installment, details: details) } - context 'when the installment has an associated successful detail' do + context "when the installment has an associated successful detail" do let(:details) { create_list :installment_detail, 1, success: true } it { is_expected.to be_falsy } end - context 'when the installment has no associated successful detail' do + context "when the installment has no associated successful detail" do let(:details) { create_list :installment_detail, 1 } it { is_expected.to be_truthy } end end - describe '#fulfilled' do + describe "#fulfilled" do subject { installment.fulfilled? } let(:installment) { create(:installment, details: details) } - context 'when the installment has an associated completed order' do + context "when the installment has an associated completed order" do let(:details) { create_list :installment_detail, 1, success: true } it { is_expected.to be_truthy } end - context 'when the installment has no associated completed order' do + context "when the installment has no associated completed order" do let(:details) { create_list :installment_detail, 1 } it { is_expected.to be_falsy } end end - describe '#payment_failed!' do - context 'when the maximum reprocessing time has been reached' do - it 'creates a new installment detail' do + describe "#payment_failed!" do + context "when the maximum reprocessing time has been reached" do + it "creates a new installment detail" do subscription = create(:subscription) allow(subscription).to receive(:maximum_reprocessing_time_reached?).and_return(true) @@ -143,7 +143,7 @@ expect(current_installment.details.count).to eq(1) end - it 'sets the actionable_date to nil' do + it "sets the actionable_date to nil" do subscription = create(:subscription) allow(subscription).to receive(:maximum_reprocessing_time_reached?).and_return(true) @@ -153,19 +153,19 @@ expect(current_installment.actionable_date).to eq(nil) end - it 'cancels the subscription' do + it "cancels the subscription" do subscription = create(:subscription) allow(subscription).to receive(:maximum_reprocessing_time_reached?).and_return(true) current_installment = create(:installment, subscription: subscription) current_installment.payment_failed!(create(:order)) - expect(current_installment.subscription.state).to eq('canceled') + expect(current_installment.subscription.state).to eq("canceled") end end - context 'when the maximum reprocessing time has not been reached' do - it 'creates a new installment detail' do + context "when the maximum reprocessing time has not been reached" do + it "creates a new installment detail" do subscription = create(:subscription) allow(subscription).to receive(:maximum_reprocessing_time_reached?).and_return(false) @@ -187,14 +187,14 @@ expect(current_installment.actionable_date).to eq(Time.zone.today + 2.days) end - it 'does not cancel the subscription' do + it "does not cancel the subscription" do subscription = create(:subscription) allow(subscription).to receive(:maximum_reprocessing_time_reached?).and_return(false) current_installment = create(:installment, subscription: subscription) current_installment.payment_failed!(create(:order)) - expect(subscription.state).to eq('active') + expect(subscription.state).to eq("active") end end end diff --git a/spec/models/solidus_subscriptions/line_item_spec.rb b/spec/models/solidus_subscriptions/line_item_spec.rb index de9bc3c2..385998f4 100644 --- a/spec/models/solidus_subscriptions/line_item_spec.rb +++ b/spec/models/solidus_subscriptions/line_item_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::LineItem, type: :model do it { is_expected.to validate_presence_of :subscribable_id } diff --git a/spec/models/solidus_subscriptions/subscription_spec.rb b/spec/models/solidus_subscriptions/subscription_spec.rb index c6e84e2a..598127e3 100644 --- a/spec/models/solidus_subscriptions/subscription_spec.rb +++ b/spec/models/solidus_subscriptions/subscription_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe SolidusSubscriptions::Subscription, type: :model do it { is_expected.to validate_presence_of :user } @@ -10,98 +10,98 @@ it { is_expected.to validate_numericality_of(:successive_skip_count).is_greater_than_or_equal_to(0) } it { is_expected.to accept_nested_attributes_for(:line_items) } - it 'validates currency correctly' do - expect(subject).to validate_inclusion_of(:currency). - in_array(::Money::Currency.all.map(&:iso_code)). - with_message('is not a valid currency code') + it "validates currency correctly" do + expect(subject).to validate_inclusion_of(:currency) + .in_array(::Money::Currency.all.map(&:iso_code)) + .with_message("is not a valid currency code") end - it 'validates payment_source ownership' do + it "validates payment_source ownership" do subscription = create(:subscription) subscription.update(payment_source: create(:credit_card)) - expect(subscription.errors.messages[:payment_source]).to include('does not belong to the user associated with the subscription') + expect(subscription.errors.messages[:payment_source]).to include("does not belong to the user associated with the subscription") subscription.update(payment_source: create(:credit_card, user: subscription.user)) - expect(subscription.errors.messages[:payment_source]).not_to include('does not belong to the user associated with the subscription') + expect(subscription.errors.messages[:payment_source]).not_to include("does not belong to the user associated with the subscription") end - describe 'creating a subscription' do - it 'tracks the creation' do - stub_const('SolidusSupport::LegacyEventCompat::Bus', class_spy(SolidusSupport::LegacyEventCompat::Bus)) + describe "creating a subscription" do + it "tracks the creation" do + stub_const("SolidusSupport::LegacyEventCompat::Bus", class_spy(SolidusSupport::LegacyEventCompat::Bus)) subscription = create(:subscription) expect(SolidusSupport::LegacyEventCompat::Bus).to have_received(:publish).with( - :'solidus_subscriptions.subscription_created', - subscription: subscription, + :"solidus_subscriptions.subscription_created", + subscription: subscription ) end - it 'generates a guest token' do + it "generates a guest token" do subscription = create(:subscription) expect(subscription.guest_token).to be_present end - it 'sets default config currency if not given' do + it "sets default config currency if not given" do subscription = create(:subscription, currency: nil) expect(subscription.currency).to eq(Spree::Config.currency) end end - describe 'updating a subscription' do - it 'tracks interval changes' do - stub_const('SolidusSupport::LegacyEventCompat::Bus', class_spy(SolidusSupport::LegacyEventCompat::Bus)) + describe "updating a subscription" do + it "tracks interval changes" do + stub_const("SolidusSupport::LegacyEventCompat::Bus", class_spy(SolidusSupport::LegacyEventCompat::Bus)) subscription = create(:subscription) subscription.update!(interval_length: subscription.interval_length + 1) expect(SolidusSupport::LegacyEventCompat::Bus).to have_received(:publish).with( - :'solidus_subscriptions.subscription_frequency_changed', - subscription: subscription, + :"solidus_subscriptions.subscription_frequency_changed", + subscription: subscription ) end - it 'tracks shipping address changes' do - stub_const('SolidusSupport::LegacyEventCompat::Bus', class_spy(SolidusSupport::LegacyEventCompat::Bus)) + it "tracks shipping address changes" do + stub_const("SolidusSupport::LegacyEventCompat::Bus", class_spy(SolidusSupport::LegacyEventCompat::Bus)) subscription = create(:subscription) subscription.update!(shipping_address: create(:address)) expect(SolidusSupport::LegacyEventCompat::Bus).to have_received(:publish).with( - :'solidus_subscriptions.subscription_shipping_address_changed', - subscription: subscription, + :"solidus_subscriptions.subscription_shipping_address_changed", + subscription: subscription ) end - it 'tracks billing address changes' do - stub_const('SolidusSupport::LegacyEventCompat::Bus', class_spy(SolidusSupport::LegacyEventCompat::Bus)) + it "tracks billing address changes" do + stub_const("SolidusSupport::LegacyEventCompat::Bus", class_spy(SolidusSupport::LegacyEventCompat::Bus)) subscription = create(:subscription) subscription.update!(billing_address: create(:address)) expect(SolidusSupport::LegacyEventCompat::Bus).to have_received(:publish).with( - :'solidus_subscriptions.subscription_billing_address_changed', - subscription: subscription, + :"solidus_subscriptions.subscription_billing_address_changed", + subscription: subscription ) end - it 'tracks payment method changes' do - stub_const('SolidusSupport::LegacyEventCompat::Bus', class_spy(SolidusSupport::LegacyEventCompat::Bus)) + it "tracks payment method changes" do + stub_const("SolidusSupport::LegacyEventCompat::Bus", class_spy(SolidusSupport::LegacyEventCompat::Bus)) subscription = create(:subscription) subscription.update!(payment_source: create(:credit_card, user: subscription.user)) expect(SolidusSupport::LegacyEventCompat::Bus).to have_received(:publish).with( - :'solidus_subscriptions.subscription_payment_method_changed', - subscription: subscription, + :"solidus_subscriptions.subscription_payment_method_changed", + subscription: subscription ) end end - describe '#cancel' do + describe "#cancel" do subject { subscription.cancel } let(:subscription) do @@ -114,55 +114,55 @@ allow(SolidusSubscriptions.configuration).to receive(:minimum_cancellation_notice) { minimum_cancellation_notice } end - context 'when the subscription can be canceled' do + context "when the subscription can be canceled" do let(:actionable_date) { 1.month.from_now } let(:minimum_cancellation_notice) { 1.day } - it 'is canceled' do + it "is canceled" do subject expect(subscription).to be_canceled end - it 'creates a subscription_canceled event' do + it "creates a subscription_canceled event" do subject - expect(subscription.events.last).to have_attributes(event_type: 'subscription_canceled') + expect(subscription.events.last).to have_attributes(event_type: "subscription_canceled") end end - context 'when the subscription cannot be canceled' do + context "when the subscription cannot be canceled" do let(:actionable_date) { Date.current } let(:minimum_cancellation_notice) { 1.day } - it 'is pending cancelation' do + it "is pending cancelation" do subject expect(subscription).to be_pending_cancellation end - it 'creates a subscription_canceled event' do + it "creates a subscription_canceled event" do subject - expect(subscription.events.last).to have_attributes(event_type: 'subscription_canceled') + expect(subscription.events.last).to have_attributes(event_type: "subscription_canceled") end end - context 'when the minimum cancellation date is 0.days' do + context "when the minimum cancellation date is 0.days" do let(:actionable_date) { Date.current } let(:minimum_cancellation_notice) { 0.days } - it 'is canceled' do + it "is canceled" do subject expect(subscription).to be_canceled end end end - describe '#pause' do - context 'when an active subscription is paused' do - it 'sets the paused column to true' do + describe "#pause" do + context "when an active subscription is paused" do + it "sets the paused column to true" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -171,41 +171,41 @@ expect(subscription.reload.paused).to be_truthy end - it 'does not change the state' do + it "does not change the state" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) subscription.pause - expect(subscription.reload.state).to eq('active') + expect(subscription.reload.state).to eq("active") end - it 'creates a paused event' do + it "creates a paused event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) subscription.pause - expect(subscription.events.last).to have_attributes(event_type: 'subscription_paused') + expect(subscription.events.last).to have_attributes(event_type: "subscription_paused") end - context 'when today is used as the actionable date' do - it 'sets actionable_date to the next day' do + context "when today is used as the actionable date" do + it "sets actionable_date to the next day" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -214,12 +214,12 @@ expect(subscription.reload.actionable_date).to eq(Time.zone.tomorrow) end - it 'is not actionable' do + it "is not actionable" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -228,12 +228,12 @@ expect(described_class.actionable).not_to include subscription end - it 'pauses correctly' do + it "pauses correctly" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -241,32 +241,32 @@ aggregate_failures do expect(subscription.reload.paused).to be_truthy - expect(subscription.state).to eq('active') + expect(subscription.state).to eq("active") end end - it 'creates a paused event' do + it "creates a paused event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) subscription.pause(actionable_date: Time.zone.today) - expect(subscription.events.last).to have_attributes(event_type: 'subscription_paused') + expect(subscription.events.last).to have_attributes(event_type: "subscription_paused") end end - context 'when a past date is used as the actionable date' do - it 'sets actionable_date to the next day' do + context "when a past date is used as the actionable date" do + it "sets actionable_date to the next day" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -275,12 +275,12 @@ expect(subscription.reload.actionable_date).to eq(Time.zone.tomorrow) end - it 'is not actionable' do + it "is not actionable" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -289,12 +289,12 @@ expect(described_class.actionable).not_to include subscription end - it 'pauses correctly' do + it "pauses correctly" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -302,32 +302,32 @@ aggregate_failures do expect(subscription.reload.paused).to be_truthy - expect(subscription.state).to eq('active') + expect(subscription.state).to eq("active") end end - it 'creates a paused event' do + it "creates a paused event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) subscription.pause(actionable_date: Time.zone.yesterday) - expect(subscription.events.last).to have_attributes(event_type: 'subscription_paused') + expect(subscription.events.last).to have_attributes(event_type: "subscription_paused") end end - context 'when nil is used as the actionable date' do - it 'sets actionable_date to nil' do + context "when nil is used as the actionable date" do + it "sets actionable_date to nil" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -336,12 +336,12 @@ expect(subscription.reload.actionable_date).to eq(nil) end - it 'is not actionable' do + it "is not actionable" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -350,12 +350,12 @@ expect(described_class.actionable).not_to include subscription end - it 'pauses correctly' do + it "pauses correctly" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -363,46 +363,46 @@ aggregate_failures do expect(subscription.reload.paused).to be_truthy - expect(subscription.state).to eq('active') + expect(subscription.state).to eq("active") end end - it 'creates a paused event' do + it "creates a paused event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) subscription.pause(actionable_date: nil) - expect(subscription.events.last).to have_attributes(event_type: 'subscription_paused') + expect(subscription.events.last).to have_attributes(event_type: "subscription_paused") end end - context 'when a future date is used as the actionable date' do - it 'sets actionable_date to the specified date' do + context "when a future date is used as the actionable date" do + it "sets actionable_date to the specified date" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) subscription.pause(actionable_date: (Time.zone.tomorrow + 1.day)) - expect(subscription.reload.actionable_date).to eq((Time.zone.tomorrow + 1.day)) + expect(subscription.reload.actionable_date).to eq(Time.zone.tomorrow + 1.day) end - it 'is not actionable' do + it "is not actionable" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -411,12 +411,12 @@ expect(described_class.actionable).not_to include subscription end - it 'pauses correctly' do + it "pauses correctly" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) @@ -424,32 +424,32 @@ aggregate_failures do expect(subscription.reload.paused).to be_truthy - expect(subscription.state).to eq('active') + expect(subscription.state).to eq("active") end end - it 'creates a paused event' do + it "creates a paused event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: false ) subscription.pause(actionable_date: (Time.zone.tomorrow + 1.day)) - expect(subscription.events.last).to have_attributes(event_type: 'subscription_paused') + expect(subscription.events.last).to have_attributes(event_type: "subscription_paused") end end - context 'when the actionable date has been reached' do - it 'is actionable' do + context "when the actionable date has been reached" do + it "is actionable" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -458,12 +458,12 @@ expect(described_class.actionable).to include subscription end - it 'processes and resumes the subscription' do + it "processes and resumes the subscription" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) expected_actionable_date = subscription.actionable_date + subscription.interval @@ -479,39 +479,39 @@ end end - context 'when a canceled subscription is paused' do - it 'adds an error when the method is called on a subscription which is not active' do + context "when a canceled subscription is paused" do + it "adds an error when the method is called on a subscription which is not active" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'canceled', + state: "canceled", paused: false ) subscription.pause - expect(subscription.errors[:paused].first).to include 'not active' + expect(subscription.errors[:paused].first).to include "not active" end - it 'does not alter the subscription' do + it "does not alter the subscription" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'canceled', + state: "canceled", paused: false ) expect { subscription.pause }.not_to(change { subscription.reload }) end - it 'does not create an event' do + it "does not create an event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'canceled', + state: "canceled", paused: false ) @@ -521,39 +521,39 @@ end end - context 'when a `pending_cancellation` subscription is paused' do - it 'adds an error when the method is called on a subscription which is not active' do + context "when a `pending_cancellation` subscription is paused" do + it "adds an error when the method is called on a subscription which is not active" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'pending_cancellation', + state: "pending_cancellation", paused: false ) subscription.pause - expect(subscription.errors[:paused].first).to include 'not active' + expect(subscription.errors[:paused].first).to include "not active" end - it 'does not alter the subscription' do + it "does not alter the subscription" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'pending_cancellation', + state: "pending_cancellation", paused: false ) expect { subscription.pause }.not_to(change { subscription.reload }) end - it 'does not create an event' do + it "does not create an event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'pending_cancellation', + state: "pending_cancellation", paused: true ) @@ -563,39 +563,39 @@ end end - context 'when an `inactive` subscription is paused' do - it 'adds an error when the method is called on a subscription which is not active' do + context "when an `inactive` subscription is paused" do + it "adds an error when the method is called on a subscription which is not active" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'inactive', + state: "inactive", paused: false ) subscription.pause - expect(subscription.errors[:paused].first).to include 'not active' + expect(subscription.errors[:paused].first).to include "not active" end - it 'does not alter the subscription' do + it "does not alter the subscription" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'inactive', + state: "inactive", paused: false ) expect { subscription.pause }.not_to(change { subscription.reload }) end - it 'does not create an event' do + it "does not create an event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'inactive', + state: "inactive", paused: false ) @@ -606,14 +606,14 @@ end end - describe '#resume' do - context 'when an active subscription is resumed' do - it 'sets the paused column to false' do + describe "#resume" do + context "when an active subscription is resumed" do + it "sets the paused column to false" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -622,41 +622,41 @@ expect(subscription.reload.paused).to be_falsy end - it 'does not change the state' do + it "does not change the state" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) subscription.resume - expect(subscription.reload.state).to eq('active') + expect(subscription.reload.state).to eq("active") end - it 'creates a resumed event' do + it "creates a resumed event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) subscription.resume - expect(subscription.events.last).to have_attributes(event_type: 'subscription_resumed') + expect(subscription.events.last).to have_attributes(event_type: "subscription_resumed") end - context 'when a past date is used as the actionable date' do - it 'sets actionable_date to the next day' do + context "when a past date is used as the actionable date" do + it "sets actionable_date to the next day" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -665,12 +665,12 @@ expect(subscription.reload.actionable_date).to eq(Time.zone.tomorrow) end - it 'is not actionable' do + it "is not actionable" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -679,12 +679,12 @@ expect(described_class.actionable).not_to include subscription end - it 'resumes correctly' do + it "resumes correctly" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -692,32 +692,32 @@ aggregate_failures do expect(subscription.reload.paused).to be_falsy - expect(subscription.state).to eq('active') + expect(subscription.state).to eq("active") end end - it 'creates a resumed event' do + it "creates a resumed event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) subscription.resume(actionable_date: Time.zone.yesterday) - expect(subscription.events.last).to have_attributes(event_type: 'subscription_resumed') + expect(subscription.events.last).to have_attributes(event_type: "subscription_resumed") end end - context 'when today is used as the actionable date' do - it 'sets actionable_date to the next day' do + context "when today is used as the actionable date" do + it "sets actionable_date to the next day" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -726,12 +726,12 @@ expect(subscription.reload.actionable_date).to eq(Time.zone.tomorrow) end - it 'is not actionable' do + it "is not actionable" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -740,12 +740,12 @@ expect(described_class.actionable).not_to include subscription end - it 'resumes correctly' do + it "resumes correctly" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -753,32 +753,32 @@ aggregate_failures do expect(subscription.reload.paused).to be_falsy - expect(subscription.state).to eq('active') + expect(subscription.state).to eq("active") end end - it 'creates a resumed event' do + it "creates a resumed event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) subscription.resume(actionable_date: Time.zone.today) - expect(subscription.events.last).to have_attributes(event_type: 'subscription_resumed') + expect(subscription.events.last).to have_attributes(event_type: "subscription_resumed") end end - context 'when nil is used as the actionable date' do - it 'sets actionable_date to the next day' do + context "when nil is used as the actionable date" do + it "sets actionable_date to the next day" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -787,12 +787,12 @@ expect(subscription.reload.actionable_date).to eq(Time.zone.tomorrow) end - it 'is not actionable' do + it "is not actionable" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -801,12 +801,12 @@ expect(described_class.actionable).not_to include subscription end - it 'resumes correctly' do + it "resumes correctly" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -814,46 +814,46 @@ aggregate_failures do expect(subscription.reload.paused).to be_falsy - expect(subscription.state).to eq('active') + expect(subscription.state).to eq("active") end end - it 'creates a resumed event' do + it "creates a resumed event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) subscription.resume(actionable_date: nil) - expect(subscription.events.last).to have_attributes(event_type: 'subscription_resumed') + expect(subscription.events.last).to have_attributes(event_type: "subscription_resumed") end end - context 'when a future date is used as the actionable date' do - it 'sets actionable_date to the specified date' do + context "when a future date is used as the actionable date" do + it "sets actionable_date to the specified date" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) subscription.resume(actionable_date: (Time.zone.tomorrow + 1.day)) - expect(subscription.reload.actionable_date).to eq((Time.zone.tomorrow + 1.day)) + expect(subscription.reload.actionable_date).to eq(Time.zone.tomorrow + 1.day) end - it 'is not actionable' do + it "is not actionable" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -862,12 +862,12 @@ expect(described_class.actionable).not_to include subscription end - it 'resumes correctly' do + it "resumes correctly" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) @@ -875,45 +875,45 @@ aggregate_failures do expect(subscription.reload.paused).to be_falsy - expect(subscription.state).to eq('active') + expect(subscription.state).to eq("active") end end - it 'creates a resumed event' do + it "creates a resumed event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'active', + state: "active", paused: true ) subscription.resume(actionable_date: (Time.zone.tomorrow + 1.day)) - expect(subscription.events.last).to have_attributes(event_type: 'subscription_resumed') + expect(subscription.events.last).to have_attributes(event_type: "subscription_resumed") end end end - context 'when a `canceled` subscription is resumed' do - it 'does not alter the subscription' do + context "when a `canceled` subscription is resumed" do + it "does not alter the subscription" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'canceled', + state: "canceled", paused: true ) expect { subscription.resume }.not_to(change { subscription.reload }) end - it 'does not create an event' do + it "does not create an event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'canceled', + state: "canceled", paused: true ) @@ -923,25 +923,25 @@ end end - context 'when a `pending_cancellation` subscription is resumed' do - it 'does not alter the subscription' do + context "when a `pending_cancellation` subscription is resumed" do + it "does not alter the subscription" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'pending_cancellation', + state: "pending_cancellation", paused: true ) expect { subscription.resume }.not_to(change { subscription.reload }) end - it 'does not create an event' do + it "does not create an event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'pending_cancellation', + state: "pending_cancellation", paused: true ) @@ -951,25 +951,25 @@ end end - context 'when an `inactive` subscription is resumed' do - it 'does not alter the subscription' do + context "when an `inactive` subscription is resumed" do + it "does not alter the subscription" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'inactive', + state: "inactive", paused: true ) expect { subscription.resume }.not_to(change { subscription.reload }) end - it 'does not create an event' do + it "does not create an event" do subscription = create( :subscription, :actionable, :with_shipping_address, - state: 'inactive', + state: "inactive", paused: true ) @@ -980,42 +980,42 @@ end end - describe '#state_with_pause' do - it 'returns `paused` when the subscription is active and paused' do + describe "#state_with_pause" do + it "returns `paused` when the subscription is active and paused" do subscription = create( :subscription, :with_shipping_address, paused: true, - state: 'active' + state: "active" ) - expect(subscription.state_with_pause).to eq('paused') + expect(subscription.state_with_pause).to eq("paused") end - it 'returns `active` when the subscription is active and not paused' do + it "returns `active` when the subscription is active and not paused" do subscription = create( :subscription, :with_shipping_address, paused: false, - state: 'active' + state: "active" ) - expect(subscription.state_with_pause).to eq('active') + expect(subscription.state_with_pause).to eq("active") end - it 'returns `canceled` when the subscription is canceled and not paused' do + it "returns `canceled` when the subscription is canceled and not paused" do subscription = create( :subscription, :with_shipping_address, paused: false, - state: 'canceled' + state: "canceled" ) - expect(subscription.state_with_pause).to eq('canceled') + expect(subscription.state_with_pause).to eq("canceled") end end - describe '#skip' do + describe "#skip" do subject { subscription.skip&.to_date } let(:total_skips) { 0 } @@ -1039,47 +1039,47 @@ end end - context 'when the successive skips have been exceeded' do + context "when the successive skips have been exceeded" do let(:successive_skips) { 1 } it { is_expected.to be_falsy } - it 'adds errors to the subscription' do + it "adds errors to the subscription" do subject expect(subscription.errors[:successive_skip_count]).not_to be_empty end - it 'does not create an event' do + it "does not create an event" do expect { subject }.not_to change(subscription.events, :count) end end - context 'when the total skips have been exceeded' do + context "when the total skips have been exceeded" do let(:total_skips) { 1 } it { is_expected.to be_falsy } - it 'adds errors to the subscription' do + it "adds errors to the subscription" do subject expect(subscription.errors[:skip_count]).not_to be_empty end - it 'does not create an event' do + it "does not create an event" do expect { subject }.not_to change(subscription.events, :count) end end - context 'when the subscription can be skipped' do + context "when the subscription can be skipped" do it { is_expected.to eq expected_date } - it 'creates a subscription_skipped event' do + it "creates a subscription_skipped event" do subject - expect(subscription.events.last).to have_attributes(event_type: 'subscription_skipped') + expect(subscription.events.last).to have_attributes(event_type: "subscription_skipped") end end end - describe '#deactivate' do + describe "#deactivate" do subject { subscription.deactivate } let(:attributes) { {} } @@ -1089,64 +1089,64 @@ end end - context 'when the subscription can be deactivated' do + context "when the subscription can be deactivated" do let(:attributes) do - { end_date: Date.current.ago(2.days) } + {end_date: Date.current.ago(2.days)} end - it 'is inactive' do + it "is inactive" do subject expect(subscription).to be_inactive end - it 'creates a subscription_deactivated event' do + it "creates a subscription_deactivated event" do subject - expect(subscription.events.last).to have_attributes(event_type: 'subscription_ended') + expect(subscription.events.last).to have_attributes(event_type: "subscription_ended") end end - context 'when the subscription cannot be deactivated' do + context "when the subscription cannot be deactivated" do it { is_expected.to be_falsy } - it 'does not create an event' do + it "does not create an event" do expect { subject }.not_to change(subscription.events, :count) end end end - describe '#activate' do - context 'when the subscription can be activated' do - it 'activates the subscription' do + describe "#activate" do + context "when the subscription can be activated" do + it "activates the subscription" do subscription = create(:subscription, actionable_date: Time.zone.today, - end_date: Time.zone.yesterday,) + end_date: Time.zone.yesterday) subscription.deactivate! subscription.activate - expect(subscription.state).to eq('active') + expect(subscription.state).to eq("active") end - it 'creates a subscription_activated event' do + it "creates a subscription_activated event" do subscription = create(:subscription, actionable_date: Time.zone.today, - end_date: Time.zone.yesterday,) + end_date: Time.zone.yesterday) subscription.deactivate! subscription.activate - expect(subscription.events.last).to have_attributes(event_type: 'subscription_activated') + expect(subscription.events.last).to have_attributes(event_type: "subscription_activated") end end - context 'when the subscription cannot be activated' do - it 'returns false' do + context "when the subscription cannot be activated" do + it "returns false" do subscription = create(:subscription, actionable_date: Time.zone.today) expect(subscription.activate).to eq(false) end - it 'does not create an event' do + it "does not create an event" do subscription = create(:subscription, actionable_date: Time.zone.today) expect { @@ -1156,7 +1156,7 @@ end end - describe '#next_actionable_date' do + describe "#next_actionable_date" do subject { subscription.next_actionable_date } context "when the subscription is active" do @@ -1179,7 +1179,7 @@ end end - describe '#advance_actionable_date' do + describe "#advance_actionable_date" do subject { subscription.advance_actionable_date } let(:expected_date) { Date.current + subscription.interval } @@ -1193,7 +1193,7 @@ it { is_expected.to eq expected_date } - it 'updates the subscription with the new actionable date' do + it "updates the subscription with the new actionable date" do subject expect(subscription.reload).to have_attributes( actionable_date: expected_date @@ -1226,16 +1226,16 @@ end end - describe '#processing_state' do + describe "#processing_state" do subject { subscription.processing_state } - context 'when the subscription has never been processed' do + context "when the subscription has never been processed" do let(:subscription) { build_stubbed :subscription } - it { is_expected.to eq 'pending' } + it { is_expected.to eq "pending" } end - context 'when the last processing attempt failed' do + context "when the last processing attempt failed" do let(:subscription) do create( :subscription, @@ -1243,10 +1243,10 @@ ) end - it { is_expected.to eq 'failed' } + it { is_expected.to eq "failed" } end - context 'when the last processing attempt succeeded' do + context "when the last processing attempt succeeded" do let(:order) { create :completed_order_with_totals } let(:subscription) do @@ -1261,17 +1261,17 @@ ) end - it { is_expected.to eq 'success' } + it { is_expected.to eq "success" } end end - describe '.ransackable_scopes' do + describe ".ransackable_scopes" do subject { described_class.ransackable_scopes } it { is_expected.to match_array [:in_processing_state, :with_subscribable] } end - describe '.with_subscribable' do + describe ".with_subscribable" do let(:subscription) do create :subscription, :with_line_item end @@ -1279,7 +1279,7 @@ create :subscription, :with_line_item end - it 'can find subscription with line items of the provided subscribable' do + it "can find subscription with line items of the provided subscribable" do subscribable = subscription.line_items.first.subscribable other_subscribable = other_subscription.line_items.first.subscribable @@ -1288,49 +1288,49 @@ end end - describe '.in_processing_state' do + describe ".in_processing_state" do subject { described_class.in_processing_state(state) } let!(:new_subs) { create_list :subscription, 2 } let!(:failed_subs) { create_list(:installment, 2, :failed).map(&:subscription) } let!(:success_subs) { create_list(:installment, 2, :success).map(&:subscription) } - context 'with successfull subscriptions' do + context "with successfull subscriptions" do let(:state) { :success } it { is_expected.to match_array success_subs } end - context 'with failed subscriptions' do + context "with failed subscriptions" do let(:state) { :failed } it { is_expected.to match_array failed_subs } end - context 'with new subscriptions' do + context "with new subscriptions" do let(:state) { :pending } it { is_expected.to match_array new_subs } end - context 'with unknown state' do + context "with unknown state" do let(:state) { :foo } - it 'raises an error' do + it "raises an error" do expect { subject }.to raise_error ArgumentError, /state must be one of/ end end end - describe '.processing_states' do + describe ".processing_states" do subject { described_class.processing_states } it { is_expected.to match_array [:pending, :success, :failed] } end - describe '#payment_source_to_use' do - context 'when the subscription has a payment method without source' do - it 'returns nil' do + describe "#payment_source_to_use" do + context "when the subscription has a payment method without source" do + it "returns nil" do payment_method = create(:check_payment_method) subscription = create(:subscription, payment_method: payment_method) @@ -1339,28 +1339,28 @@ end end - context 'when the subscription has a payment method with a source' do - it 'returns the source on the subscription' do + context "when the subscription has a payment method with a source" do + it "returns the source on the subscription" do user = create(:user) payment_method = create(:credit_card_payment_method) payment_source = create(:credit_card, payment_method: payment_method, - gateway_customer_profile_id: 'BGS-123', - user: user,) + gateway_customer_profile_id: "BGS-123", + user: user) subscription = create(:subscription, user: user, payment_method: payment_method, - payment_source: payment_source,) + payment_source: payment_source) expect(subscription.payment_source_to_use).to eq(payment_source) end end - context 'when the subscription has no payment method' do + context "when the subscription has no payment method" do it "returns the default source from the user's wallet_payment_source" do user = create(:user) - payment_source = create(:credit_card, gateway_customer_profile_id: 'BGS-123', user: user) + payment_source = create(:credit_card, gateway_customer_profile_id: "BGS-123", user: user) wallet_payment_source = user.wallet.add(payment_source) user.wallet.default_wallet_payment_source = wallet_payment_source @@ -1371,9 +1371,9 @@ end end - describe '#payment_method_to_use' do - context 'when the subscription has a payment method without source' do - it 'returns the payment method on the subscription' do + describe "#payment_method_to_use" do + context "when the subscription has a payment method without source" do + it "returns the payment method on the subscription" do payment_method = create(:check_payment_method) subscription = create(:subscription, payment_method: payment_method) @@ -1381,28 +1381,28 @@ end end - context 'when the subscription has a payment method with a source' do - it 'returns the payment method on the subscription' do + context "when the subscription has a payment method with a source" do + it "returns the payment method on the subscription" do user = create(:user) payment_method = create(:credit_card_payment_method) payment_source = create(:credit_card, payment_method: payment_method, - gateway_customer_profile_id: 'BGS-123', - user: user,) + gateway_customer_profile_id: "BGS-123", + user: user) subscription = create(:subscription, user: user, payment_method: payment_method, - payment_source: payment_source,) + payment_source: payment_source) expect(subscription.payment_method_to_use).to eq(payment_method) end end - context 'when the subscription has no payment method' do + context "when the subscription has no payment method" do it "returns the method from the default source in the user's wallet_payment_source" do user = create(:user) - payment_source = create(:credit_card, gateway_customer_profile_id: 'BGS-123', user: user) + payment_source = create(:credit_card, gateway_customer_profile_id: "BGS-123", user: user) wallet_payment_source = user.wallet.add(payment_source) user.wallet.default_wallet_payment_source = wallet_payment_source @@ -1413,9 +1413,9 @@ end end - describe '#billing_address_to_use' do - context 'when the subscription has a billing address' do - it 'returns the billing address on the subscription' do + describe "#billing_address_to_use" do + context "when the subscription has a billing address" do + it "returns the billing address on the subscription" do billing_address = create(:bill_address) subscription = create(:subscription, billing_address: billing_address) @@ -1424,8 +1424,8 @@ end end - context 'when the subscription has no billing address' do - it 'returns the billing address on the user' do + context "when the subscription has no billing address" do + it "returns the billing address on the user" do user = create(:user) billing_address = create(:bill_address) user.bill_address = billing_address @@ -1437,9 +1437,9 @@ end end - describe '#shipping_address_to_use' do - context 'when the subscription has a shipping address' do - it 'returns the shipping address on the subscription' do + describe "#shipping_address_to_use" do + context "when the subscription has a shipping address" do + it "returns the shipping address on the subscription" do shipping_address = create(:ship_address) subscription = create(:subscription, shipping_address: shipping_address) @@ -1448,8 +1448,8 @@ end end - context 'when the subscription has no shipping address' do - it 'returns the shipping address on the user' do + context "when the subscription has no shipping address" do + it "returns the shipping address on the user" do user = create(:user) shipping_address = create(:ship_address) user.ship_address = shipping_address @@ -1465,10 +1465,10 @@ context "with installments" do context "when the last installment date would cause the interval to be in the past" do it "sets the actionable_date to the current day" do - subscription = create(:subscription, actionable_date: Time.zone.parse('2016-08-22')) - create(:installment, subscription: subscription, created_at: Time.zone.parse('2016-07-22')) + subscription = create(:subscription, actionable_date: Time.zone.parse("2016-08-22")) + create(:installment, subscription: subscription, created_at: Time.zone.parse("2016-07-22")) - subscription.update!(interval_length: 1, interval_units: 'month') + subscription.update!(interval_length: 1, interval_units: "month") expect(subscription.actionable_date).to eq(Time.zone.today) end @@ -1476,10 +1476,10 @@ context "when the last installment date would cause the interval to be in the future" do it "sets the actionable_date to an interval from the last installment" do - subscription = create(:subscription, actionable_date: Time.zone.parse('2016-08-22')) + subscription = create(:subscription, actionable_date: Time.zone.parse("2016-08-22")) create(:installment, subscription: subscription, created_at: 4.days.ago) - subscription.update!(interval_length: 1, interval_units: 'month') + subscription.update!(interval_length: 1, interval_units: "month") expect(subscription.actionable_date).to eq((4.days.ago + 1.month).to_date) end @@ -1489,9 +1489,9 @@ context "when there are no installments" do context "when the subscription creation date would cause the interval to be in the past" do it "sets the actionable_date to the current day" do - subscription = create(:subscription, created_at: Time.zone.parse('2016-08-22')) + subscription = create(:subscription, created_at: Time.zone.parse("2016-08-22")) - subscription.update!(interval_length: 1, interval_units: 'month') + subscription.update!(interval_length: 1, interval_units: "month") expect(subscription.actionable_date).to eq(Time.zone.today) end @@ -1501,7 +1501,7 @@ it "sets the actionable_date to one interval past the subscription creation date" do subscription = create(:subscription, created_at: 4.days.ago) - subscription.update!(interval_length: 1, interval_units: 'month') + subscription.update!(interval_length: 1, interval_units: "month") expect(subscription.actionable_date).to eq((4.days.ago + 1.month).to_date) end @@ -1509,73 +1509,73 @@ end end - describe '#failing_since' do - context 'when the subscription is not failing' do - it 'returns nil' do + describe "#failing_since" do + context "when the subscription is not failing" do + it "returns nil" do subscription = create(:subscription, installments: [ create(:installment, details: [ - create(:installment_detail, success: false, created_at: '2020-11-11'), - create(:installment_detail, success: false, created_at: '2020-11-12'), - create(:installment_detail, success: true, created_at: '2020-11-13'), + create(:installment_detail, success: false, created_at: "2020-11-11"), + create(:installment_detail, success: false, created_at: "2020-11-12"), + create(:installment_detail, success: true, created_at: "2020-11-13") ]), create(:installment, details: [ - create(:installment_detail, success: false, created_at: '2020-11-24'), - create(:installment_detail, success: true, created_at: '2020-11-25'), - ]), + create(:installment_detail, success: false, created_at: "2020-11-24"), + create(:installment_detail, success: true, created_at: "2020-11-25") + ]) ]) expect(subscription.failing_since).to eq(nil) end end - context 'when the subscription is failing with a previous success' do - it 'returns the date of the first failure' do + context "when the subscription is failing with a previous success" do + it "returns the date of the first failure" do subscription = create(:subscription, installments: [ create(:installment, details: [ - create(:installment_detail, success: false, created_at: '2020-11-11'), - create(:installment_detail, success: false, created_at: '2020-11-12'), - create(:installment_detail, success: true, created_at: '2020-11-13'), + create(:installment_detail, success: false, created_at: "2020-11-11"), + create(:installment_detail, success: false, created_at: "2020-11-12"), + create(:installment_detail, success: true, created_at: "2020-11-13") ]), create(:installment, details: [ - create(:installment_detail, success: false, created_at: '2020-11-24'), - create(:installment_detail, success: false, created_at: '2020-11-25'), + create(:installment_detail, success: false, created_at: "2020-11-24"), + create(:installment_detail, success: false, created_at: "2020-11-25") ]), create(:installment, details: [ - create(:installment_detail, success: false, created_at: '2020-11-26'), - create(:installment_detail, success: false, created_at: '2020-11-27'), - ]), + create(:installment_detail, success: false, created_at: "2020-11-26"), + create(:installment_detail, success: false, created_at: "2020-11-27") + ]) ]) - expect(subscription.failing_since).to eq(Time.zone.parse('2020-11-24')) + expect(subscription.failing_since).to eq(Time.zone.parse("2020-11-24")) end end - context 'when the subscription is failing with no previous success' do - it 'returns the date of the first failure' do + context "when the subscription is failing with no previous success" do + it "returns the date of the first failure" do subscription = create(:subscription, installments: [ create(:installment, details: [ - create(:installment_detail, success: false, created_at: '2020-11-11'), - create(:installment_detail, success: false, created_at: '2020-11-12'), - create(:installment_detail, success: false, created_at: '2020-11-13'), + create(:installment_detail, success: false, created_at: "2020-11-11"), + create(:installment_detail, success: false, created_at: "2020-11-12"), + create(:installment_detail, success: false, created_at: "2020-11-13") ]), create(:installment, details: [ - create(:installment_detail, success: false, created_at: '2020-11-24'), - create(:installment_detail, success: false, created_at: '2020-11-25'), + create(:installment_detail, success: false, created_at: "2020-11-24"), + create(:installment_detail, success: false, created_at: "2020-11-25") ]), create(:installment, details: [ - create(:installment_detail, success: false, created_at: '2020-11-26'), - create(:installment_detail, success: false, created_at: '2020-11-27'), - ]), + create(:installment_detail, success: false, created_at: "2020-11-26"), + create(:installment_detail, success: false, created_at: "2020-11-27") + ]) ]) - expect(subscription.failing_since).to eq(Time.zone.parse('2020-11-11')) + expect(subscription.failing_since).to eq(Time.zone.parse("2020-11-11")) end end end - describe '#maximum_reprocessing_time_reached?' do - context 'when maximum_reprocessing_time is not configured' do - it 'returns false' do + describe "#maximum_reprocessing_time_reached?" do + context "when maximum_reprocessing_time is not configured" do + it "returns false" do stub_config(maximum_reprocessing_time: 5.days) subscription = create(:subscription) @@ -1583,73 +1583,73 @@ end end - context 'when maximum_reprocessing_time is configured' do - context 'when the subscription has been failing for too long' do - it 'returns true' do + context "when maximum_reprocessing_time is configured" do + context "when the subscription has been failing for too long" do + it "returns true" do stub_config(maximum_reprocessing_time: 15.days) subscription = create(:subscription, installments: [ create(:installment, details: [ create(:installment_detail, success: false, created_at: 20.days.ago), create(:installment_detail, success: false, created_at: 19.days.ago), - create(:installment_detail, success: true, created_at: 18.days.ago), + create(:installment_detail, success: true, created_at: 18.days.ago) ]), create(:installment, details: [ create(:installment_detail, success: false, created_at: 17.days.ago), - create(:installment_detail, success: false, created_at: 16.days.ago), + create(:installment_detail, success: false, created_at: 16.days.ago) ]), create(:installment, details: [ create(:installment_detail, success: false, created_at: 15.days.ago), - create(:installment_detail, success: false, created_at: 14.days.ago), - ]), + create(:installment_detail, success: false, created_at: 14.days.ago) + ]) ]) expect(subscription.maximum_reprocessing_time_reached?).to eq(true) end end - context 'when the subscription has not been failing for too long' do - it 'returns false' do + context "when the subscription has not been failing for too long" do + it "returns false" do stub_config(maximum_reprocessing_time: 15.days) subscription = create(:subscription, installments: [ create(:installment, details: [ create(:installment_detail, success: false, created_at: 15.days.ago), create(:installment_detail, success: false, created_at: 14.days.ago), - create(:installment_detail, success: true, created_at: 13.days.ago), + create(:installment_detail, success: true, created_at: 13.days.ago) ]), create(:installment, details: [ create(:installment_detail, success: false, created_at: 12.days.ago), - create(:installment_detail, success: false, created_at: 11.days.ago), + create(:installment_detail, success: false, created_at: 11.days.ago) ]), create(:installment, details: [ create(:installment_detail, success: false, created_at: 10.days.ago), - create(:installment_detail, success: false, created_at: 9.days.ago), - ]), + create(:installment_detail, success: false, created_at: 9.days.ago) + ]) ]) expect(subscription.maximum_reprocessing_time_reached?).to eq(false) end end - context 'when the subscription is not failing' do - it 'returns false' do + context "when the subscription is not failing" do + it "returns false" do stub_config(maximum_reprocessing_time: 2.days) subscription = create(:subscription, installments: [ create(:installment, details: [ create(:installment_detail, success: false, created_at: 15.days.ago), create(:installment_detail, success: false, created_at: 14.days.ago), - create(:installment_detail, success: true, created_at: 13.days.ago), + create(:installment_detail, success: true, created_at: 13.days.ago) ]), create(:installment, details: [ create(:installment_detail, success: false, created_at: 12.days.ago), - create(:installment_detail, success: false, created_at: 11.days.ago), + create(:installment_detail, success: false, created_at: 11.days.ago) ]), create(:installment, details: [ create(:installment_detail, success: false, created_at: 10.days.ago), - create(:installment_detail, success: true, created_at: 9.days.ago), - ]), + create(:installment_detail, success: true, created_at: 9.days.ago) + ]) ]) expect(subscription.maximum_reprocessing_time_reached?).to eq(false) @@ -1658,25 +1658,25 @@ end end - describe '#actionable?' do - context 'when the actionable date is nil' do - it 'is not actionable' do + describe "#actionable?" do + context "when the actionable date is nil" do + it "is not actionable" do subscription = build_stubbed(:subscription, actionable_date: nil) expect(subscription).not_to be_actionable end end - context 'when the actionable date is in the future' do - it 'is not actionable' do + context "when the actionable date is in the future" do + it "is not actionable" do subscription = build_stubbed(:subscription, actionable_date: Time.zone.today + 5.days) expect(subscription).not_to be_actionable end end - context 'when the state is either canceled or inactive' do - it 'is not actionable' do + context "when the state is either canceled or inactive" do + it "is not actionable" do canceled_subscription = build_stubbed(:subscription, :canceled) inactive_subscription = build_stubbed(:subscription, :inactive) @@ -1686,8 +1686,8 @@ end end - context 'when the active subscription actionable date is today or in the past' do - it 'is actionable' do + context "when the active subscription actionable date is today or in the past" do + it "is actionable" do subscription = build_stubbed(:subscription, actionable_date: Time.zone.today) expect(subscription).to be_actionable diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index 3627fc7b..c067dfd2 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe Spree::Variant, type: :model do let(:variant) { build_stubbed :variant } @@ -8,7 +8,7 @@ describe "#pretty_name" do subject(:pretty_name) { variant.pretty_name } - it 'includes the product and options', :aggregate_failures do + it "includes the product and options", :aggregate_failures do expect(pretty_name).to match variant.name expect(pretty_name).to match variant.options_text end diff --git a/spec/models/spree/wallet_payment_source_spec.rb b/spec/models/spree/wallet_payment_source_spec.rb index 9f96944a..6b66261e 100644 --- a/spec/models/spree/wallet_payment_source_spec.rb +++ b/spec/models/spree/wallet_payment_source_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true RSpec.describe Spree::WalletPaymentSource do - describe 'setting it as the default' do - it 'reports a payment method changed event for subscriptions that use the default payment source' do - stub_const('SolidusSupport::LegacyEventCompat::Bus', class_spy(SolidusSupport::LegacyEventCompat::Bus)) + describe "setting it as the default" do + it "reports a payment method changed event for subscriptions that use the default payment source" do + stub_const("SolidusSupport::LegacyEventCompat::Bus", class_spy(SolidusSupport::LegacyEventCompat::Bus)) user = create(:user) subscription = create(:subscription, user: user) payment_source = create(:credit_card, user: user) @@ -12,8 +12,8 @@ user.wallet.default_wallet_payment_source = wallet_payment_source expect(SolidusSupport::LegacyEventCompat::Bus).to have_received(:publish).with( - :'solidus_subscriptions.subscription_payment_method_changed', - subscription: subscription, + :"solidus_subscriptions.subscription_payment_method_changed", + subscription: subscription ) end end diff --git a/spec/requests/api/v1/line_items_spec.rb b/spec/requests/api/v1/line_items_spec.rb index d5fa6b4b..02692cb9 100644 --- a/spec/requests/api/v1/line_items_spec.rb +++ b/spec/requests/api/v1/line_items_spec.rb @@ -1,50 +1,50 @@ # frozen_string_literal: true -RSpec.describe '/api/v1/line_items' do +RSpec.describe "/api/v1/line_items" do include SolidusSubscriptions::Engine.routes.url_helpers - describe 'PATCH /:id' do - context 'when the subscription belongs to the user' do - context 'with valid params' do - it 'responds with 200 OK' do + describe "PATCH /:id" do + context "when the subscription belongs to the user" do + context "with valid params" do + it "responds with 200 OK" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription, user: user) line_item = create(:subscription_line_item, subscription: subscription) patch( api_v1_line_item_path(line_item), - params: { subscription_line_item: { quantity: 11 } }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription_line_item: {quantity: 11}}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(200) end - it 'updates the line item' do + it "updates the line item" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription, user: user) line_item = create(:subscription_line_item, subscription: subscription) patch( api_v1_line_item_path(line_item), - params: { subscription_line_item: { quantity: 11 } }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription_line_item: {quantity: 11}}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(line_item.reload.quantity).to eq(11) end end - context 'with invalid params' do - it 'responds with 422 Unprocessable Entity' do + context "with invalid params" do + it "responds with 422 Unprocessable Entity" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription, user: user) line_item = create(:subscription_line_item, subscription: subscription) patch( api_v1_line_item_path(line_item), - params: { subscription_line_item: { quantity: -1 } }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription_line_item: {quantity: -1}}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(422) @@ -52,16 +52,16 @@ end end - context 'when the subscription does not belong to the user' do - it 'responds with 401 Unauthorized' do + context "when the subscription does not belong to the user" do + it "responds with 401 Unauthorized" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription) line_item = create(:subscription_line_item, subscription: subscription) patch( api_v1_line_item_path(line_item), - params: { subscription_line_item: { quantity: 11 } }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription_line_item: {quantity: 11}}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(401) @@ -69,44 +69,44 @@ end end - describe 'DELETE /:id' do - context 'when the subscription belongs to the user' do - it 'responds with 200 OK' do + describe "DELETE /:id" do + context "when the subscription belongs to the user" do + it "responds with 200 OK" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription, user: user) line_item = create(:subscription_line_item, subscription: subscription) delete( api_v1_line_item_path(line_item), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(200) end - it 'deletes the line item' do + it "deletes the line item" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription, user: user) line_item = create(:subscription_line_item, subscription: subscription) delete( api_v1_line_item_path(line_item), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect { line_item.reload }.to raise_error(ActiveRecord::RecordNotFound) end end - context 'when the subscription does not belong to the user' do - it 'responds with 401 Unauthorized' do + context "when the subscription does not belong to the user" do + it "responds with 401 Unauthorized" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription) line_item = create(:subscription_line_item, subscription: subscription) delete( api_v1_line_item_path(line_item), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(401) diff --git a/spec/requests/api/v1/subscriptions_spec.rb b/spec/requests/api/v1/subscriptions_spec.rb index 30b47fb9..20364285 100644 --- a/spec/requests/api/v1/subscriptions_spec.rb +++ b/spec/requests/api/v1/subscriptions_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -RSpec.describe '/api/v1/subscriptions' do +RSpec.describe "/api/v1/subscriptions" do include SolidusSubscriptions::Engine.routes.url_helpers - describe 'POST /' do - context 'with valid params' do - it 'creates the subscription and responds with 200 OK' do + describe "POST /" do + context "with valid params" do + it "creates the subscription and responds with 200 OK" do user = create(:user, &:generate_spree_api_key!) expect do post( api_v1_subscriptions_path, - params: { subscription: { interval_length: 11 } }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription: {interval_length: 11}}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) end.to change(SolidusSubscriptions::Subscription, :count).from(0).to(1) @@ -20,15 +20,15 @@ end end - context 'with invalid params' do + context "with invalid params" do it "doesn't create the subscription and responds with 422 Unprocessable Entity" do user = create(:user, &:generate_spree_api_key!) expect do post( api_v1_subscriptions_path, - params: { subscription: { interval_length: -1 } }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription: {interval_length: -1}}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) end.not_to change(SolidusSubscriptions::Subscription, :count) @@ -36,106 +36,106 @@ end end - context 'when valid payment attributes are provided' do - it 'creates the subscription using the specified payment' do + context "when valid payment attributes are provided" do + it "creates the subscription using the specified payment" do user = create(:user, &:generate_spree_api_key!) payment_source = create(:credit_card, user: user) - payment_params = { payment_method_id: payment_source.payment_method.id, payment_source_id: payment_source.id } + payment_params = {payment_method_id: payment_source.payment_method.id, payment_source_id: payment_source.id} expect(user.wallet.default_wallet_payment_source).to be_nil expect do post( api_v1_subscriptions_path, - params: { subscription: { interval_length: 7 }.merge(payment_params) }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription: {interval_length: 7}.merge(payment_params)}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) end.to change(SolidusSubscriptions::Subscription, :count).from(0).to(1) expect(SolidusSubscriptions::Subscription.last).to have_attributes(payment_params) end end - context 'when an invalid payment method is provided' do + context "when an invalid payment method is provided" do it "doesn't create the subscription and responds with 422 Unprocessable Entity" do user = create(:user, &:generate_spree_api_key!) payment_source = create(:credit_card) - payment_params = { payment_source_id: payment_source.id } + payment_params = {payment_source_id: payment_source.id} expect do post( api_v1_subscriptions_path, - params: { subscription: { interval_length: 7 }.merge(payment_params) }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription: {interval_length: 7}.merge(payment_params)}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) end.not_to change(SolidusSubscriptions::Subscription, :count) - error_message = I18n.t('solidus_subscriptions.subscription.invalid_payment_details') + error_message = I18n.t("solidus_subscriptions.subscription.invalid_payment_details") response_body = JSON.parse(response.body) - expect(response_body).to eq('payment_source_type' => [error_message]) + expect(response_body).to eq("payment_source_type" => [error_message]) expect(response.status).to eq(422) end end - context 'when an invalid payment source is provided' do + context "when an invalid payment source is provided" do it "doesn't create the subscription and responds with 422 Unprocessable Entity" do user = create(:user, &:generate_spree_api_key!) payment_source = create(:credit_card) - payment_params = { payment_method_id: payment_source.payment_method.id } + payment_params = {payment_method_id: payment_source.payment_method.id} expect do post( api_v1_subscriptions_path, - params: { subscription: { interval_length: 7 }.merge(payment_params) }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription: {interval_length: 7}.merge(payment_params)}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) end.not_to change(SolidusSubscriptions::Subscription, :count) - error_message = I18n.t('solidus_subscriptions.subscription.invalid_payment_details') + error_message = I18n.t("solidus_subscriptions.subscription.invalid_payment_details") response_body = JSON.parse(response.body) - expect(response_body).to eq('payment_source_type' => [error_message]) + expect(response_body).to eq("payment_source_type" => [error_message]) expect(response.status).to eq(422) end end end - describe 'PATCH /:id' do - context 'when the subscription belongs to the user' do - context 'with valid params' do - it 'responds with 200 OK' do + describe "PATCH /:id" do + context "when the subscription belongs to the user" do + context "with valid params" do + it "responds with 200 OK" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription, user: user) patch( api_v1_subscription_path(subscription), - params: { subscription: { interval_length: 11 } }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription: {interval_length: 11}}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(200) end - it 'updates the subscription' do + it "updates the subscription" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription, user: user) patch( api_v1_subscription_path(subscription), - params: { subscription: { interval_length: 11 } }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription: {interval_length: 11}}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(subscription.reload.interval_length).to eq(11) end end - context 'with invalid params' do - it 'responds with 422 Unprocessable Entity' do + context "with invalid params" do + it "responds with 422 Unprocessable Entity" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription, user: user) patch( api_v1_subscription_path(subscription), - params: { subscription: { interval_length: -1 } }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription: {interval_length: -1}}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(422) @@ -143,15 +143,15 @@ end end - context 'when the subscription does not belong to the user' do - it 'responds with 401 Unauthorized' do + context "when the subscription does not belong to the user" do + it "responds with 401 Unauthorized" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription) patch( api_v1_subscription_path(subscription), - params: { subscription: { interval_length: 11 } }, - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + params: {subscription: {interval_length: 11}}, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(401) @@ -159,16 +159,16 @@ end end - describe 'POST /:id/pause' do - context 'when the subscription is active and belongs to the user' do - context 'with an actionable_date' do - it 'pauses the subscription and updates the actionable_date' do + describe "POST /:id/pause" do + context "when the subscription is active and belongs to the user" do + context "with an actionable_date" do + it "pauses the subscription and updates the actionable_date" do user = create(:user, &:generate_spree_api_key!) subscription = create( :subscription, user: user, paused: false, - state: 'active' + state: "active" ) date = Time.zone.tomorrow + 1.day params = { @@ -179,7 +179,7 @@ post( pause_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"}, params: params ) @@ -191,21 +191,21 @@ end end - context 'without an actionable_date' do - it 'pauses the subscription indefinitely' do + context "without an actionable_date" do + it "pauses the subscription indefinitely" do user = create(:user, &:generate_spree_api_key!) subscription = create( :subscription, :with_shipping_address, user: user, paused: false, - state: 'active' + state: "active" ) params = nil post( pause_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"}, params: params ) @@ -218,39 +218,39 @@ end end - context 'when the subscription is not active and belongs to the user' do - it 'is an unprocessable entity' do + context "when the subscription is not active and belongs to the user" do + it "is an unprocessable entity" do user = create(:user, &:generate_spree_api_key!) subscription = create( :subscription, :with_shipping_address, user: user, paused: false, - state: 'canceled' + state: "canceled" ) params = nil post( pause_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"}, params: params ) aggregate_failures do expect(response).to have_http_status(:unprocessable_entity) - expect(JSON.parse(response.body)["paused"]).to include('cannot pause/resume a subscription which is not active') + expect(JSON.parse(response.body)["paused"]).to include("cannot pause/resume a subscription which is not active") expect(subscription.reload.paused).to eq(false) end end end - context('when the subscription is active but does not belong to the user') do - it 'responds with 401 Unauthorized' do + context("when the subscription is active but does not belong to the user") do + it "responds with 401 Unauthorized" do user = create(:user, &:generate_spree_api_key!) subscription = create( :subscription, paused: false, - state: 'active' + state: "active" ) date = Time.zone.tomorrow + 1.day params = { @@ -261,7 +261,7 @@ post( pause_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"}, params: params ) @@ -270,16 +270,16 @@ end end - describe '#resume' do - context 'when the subscription is active and belongs to the user' do - context 'with an actionable_date' do - it 'resumes the subscription and updates the actionable_date' do + describe "#resume" do + context "when the subscription is active and belongs to the user" do + context "with an actionable_date" do + it "resumes the subscription and updates the actionable_date" do user = create(:user, &:generate_spree_api_key!) subscription = create( :subscription, user: user, paused: true, - state: 'active' + state: "active" ) date = Time.zone.tomorrow + 1.day params = { @@ -290,7 +290,7 @@ post( resume_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"}, params: params ) @@ -302,14 +302,14 @@ end end - context 'without an actionable_date' do - it 'resumes the subscription on the next day' do + context "without an actionable_date" do + it "resumes the subscription on the next day" do user = create(:user, &:generate_spree_api_key!) subscription = create( :subscription, user: user, paused: true, - state: 'active' + state: "active" ) params = { subscription: { @@ -319,7 +319,7 @@ post( resume_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"}, params: params ) @@ -332,14 +332,14 @@ end end - context 'when the subscription is not active and belongs to the user' do - it 'is an unprocessable entity' do + context "when the subscription is not active and belongs to the user" do + it "is an unprocessable entity" do user = create(:user, &:generate_spree_api_key!) subscription = create( :subscription, user: user, paused: true, - state: 'canceled' + state: "canceled" ) params = { subscription: { @@ -349,24 +349,24 @@ post( resume_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"}, params: params ) aggregate_failures do expect(response.status).to eq(422) - expect(JSON.parse(response.body)["paused"]).to include('cannot pause/resume a subscription which is not active') + expect(JSON.parse(response.body)["paused"]).to include("cannot pause/resume a subscription which is not active") end end end - context 'when the subscription is active but does not belong to the user' do - it 'responds with 401 Unauthorized' do + context "when the subscription is active but does not belong to the user" do + it "responds with 401 Unauthorized" do user = create(:user, &:generate_spree_api_key!) subscription = create( :subscription, paused: true, - state: 'active' + state: "active" ) params = { subscription: { @@ -376,7 +376,7 @@ post( resume_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"}, params: params ) @@ -388,47 +388,47 @@ end end - describe 'POST /:id/skip' do - context 'when the subscription belongs to the user' do - it 'responds with 200 OK' do + describe "POST /:id/skip" do + context "when the subscription belongs to the user" do + it "responds with 200 OK" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription, user: user) post( skip_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(200) end - it 'skips the subscription' do + it "skips the subscription" do user = create(:user, &:generate_spree_api_key!) subscription = create( :subscription, user: user, interval_length: 1, - interval_units: 'week', - actionable_date: Time.zone.today, + interval_units: "week", + actionable_date: Time.zone.today ) post( skip_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(subscription.reload.actionable_date).to eq(Time.zone.today + 1.week) end end - context 'when the subscription does not belong to the user' do - it 'responds with 401 Unauthorized' do + context "when the subscription does not belong to the user" do + it "responds with 401 Unauthorized" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription) post( skip_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(401) @@ -436,41 +436,41 @@ end end - describe 'POST /:id/cancel' do - context 'when the subscription belongs to the user' do - it 'responds with 200 OK' do + describe "POST /:id/cancel" do + context "when the subscription belongs to the user" do + it "responds with 200 OK" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription, user: user) post( cancel_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(200) end - it 'cancels the subscription' do + it "cancels the subscription" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription, user: user) post( cancel_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) - expect(subscription.reload.state).to eq('canceled') + expect(subscription.reload.state).to eq("canceled") end end - context 'when the subscription does not belong to the user' do - it 'responds with 401 Unauthorized' do + context "when the subscription does not belong to the user" do + it "responds with 401 Unauthorized" do user = create(:user, &:generate_spree_api_key!) subscription = create(:subscription) post( cancel_api_v1_subscription_path(subscription), - headers: { 'Authorization' => "Bearer #{user.spree_api_key}" }, + headers: {"Authorization" => "Bearer #{user.spree_api_key}"} ) expect(response.status).to eq(401) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9d3e91ee..58584da5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true # Configure Rails Environment -ENV['RAILS_ENV'] = 'test' +ENV["RAILS_ENV"] = "test" # Run Coverage report -require 'solidus_dev_support/rspec/coverage' +require "solidus_dev_support/rspec/coverage" # Create the dummy app if it's still missing. dummy_env = "#{__dir__}/dummy/config/environment.rb" -system 'bin/rake extension:test_app' unless File.exist? dummy_env +system "bin/rake extension:test_app" unless File.exist? dummy_env require dummy_env # Requires factories and other useful helpers defined in spree_core. -require 'solidus_dev_support/rspec/feature_helper' +require "solidus_dev_support/rspec/feature_helper" # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. @@ -26,7 +26,7 @@ config.infer_spec_type_from_file_location! config.use_transactional_fixtures = false - if Spree.solidus_gem_version < Gem::Version.new('2.11') + if Spree.solidus_gem_version < Gem::Version.new("2.11") config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system end diff --git a/spec/subscribers/solidus_subscriptions/churn_buster_subscriber_spec.rb b/spec/subscribers/solidus_subscriptions/churn_buster_subscriber_spec.rb index f4dbd524..fed518d7 100644 --- a/spec/subscribers/solidus_subscriptions/churn_buster_subscriber_spec.rb +++ b/spec/subscribers/solidus_subscriptions/churn_buster_subscriber_spec.rb @@ -1,73 +1,73 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::ChurnBusterSubscriber do - describe '#report_subscription_cancellation' do - it 'reports the cancellation to Churn Buster' do + describe "#report_subscription_cancellation" do + it "reports the cancellation to Churn Buster" do churn_buster = instance_spy(SolidusSubscriptions::ChurnBuster::Client) allow(SolidusSubscriptions).to receive(:churn_buster).and_return(churn_buster) subscription = create(:subscription) - SolidusSupport::LegacyEventCompat::Bus.publish(:'solidus_subscriptions.subscription_canceled', subscription: subscription) + SolidusSupport::LegacyEventCompat::Bus.publish(:"solidus_subscriptions.subscription_canceled", subscription: subscription) expect(churn_buster).to have_received(:report_subscription_cancellation).with(subscription) end end - describe '#report_subscription_ending' do - it 'reports the cancellation to Churn Buster' do + describe "#report_subscription_ending" do + it "reports the cancellation to Churn Buster" do churn_buster = instance_spy(SolidusSubscriptions::ChurnBuster::Client) allow(SolidusSubscriptions).to receive(:churn_buster).and_return(churn_buster) subscription = create(:subscription) - SolidusSupport::LegacyEventCompat::Bus.publish(:'solidus_subscriptions.subscription_ended', subscription: subscription) + SolidusSupport::LegacyEventCompat::Bus.publish(:"solidus_subscriptions.subscription_ended", subscription: subscription) expect(churn_buster).to have_received(:report_subscription_cancellation).with(subscription) end end - describe '#report_payment_success' do - it 'reports the success to Churn Buster' do + describe "#report_payment_success" do + it "reports the success to Churn Buster" do churn_buster = instance_spy(SolidusSubscriptions::ChurnBuster::Client) allow(SolidusSubscriptions).to receive(:churn_buster).and_return(churn_buster) order = build_stubbed(:order) installment = build_stubbed(:installment) SolidusSupport::LegacyEventCompat::Bus.publish( - :'solidus_subscriptions.installment_succeeded', + :"solidus_subscriptions.installment_succeeded", installment: installment, - order: order, + order: order ) expect(churn_buster).to have_received(:report_successful_payment).with(order) end end - describe '#report_payment_failure' do - it 'reports the failure to Churn Buster' do + describe "#report_payment_failure" do + it "reports the failure to Churn Buster" do churn_buster = instance_spy(SolidusSubscriptions::ChurnBuster::Client) allow(SolidusSubscriptions).to receive(:churn_buster).and_return(churn_buster) order = build_stubbed(:order) installment = build_stubbed(:installment) SolidusSupport::LegacyEventCompat::Bus.publish( - :'solidus_subscriptions.installment_failed_payment', + :"solidus_subscriptions.installment_failed_payment", installment: installment, - order: order, + order: order ) expect(churn_buster).to have_received(:report_failed_payment).with(order) end end - describe '#report_payment_method_change' do - it 'reports the payment method change to Churn Buster' do + describe "#report_payment_method_change" do + it "reports the payment method change to Churn Buster" do churn_buster = instance_spy(SolidusSubscriptions::ChurnBuster::Client) allow(SolidusSubscriptions).to receive(:churn_buster).and_return(churn_buster) subscription = create(:subscription) SolidusSupport::LegacyEventCompat::Bus.publish( - :'solidus_subscriptions.subscription_payment_method_changed', - subscription: subscription, + :"solidus_subscriptions.subscription_payment_method_changed", + subscription: subscription ) expect(churn_buster).to have_received(:report_payment_method_change).with(subscription) diff --git a/spec/subscribers/solidus_subscriptions/order_subscriber_spec.rb b/spec/subscribers/solidus_subscriptions/order_subscriber_spec.rb index c09038f2..4d30a521 100644 --- a/spec/subscribers/solidus_subscriptions/order_subscriber_spec.rb +++ b/spec/subscribers/solidus_subscriptions/order_subscriber_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true RSpec.describe SolidusSubscriptions::OrderSubscriber do - describe 'on order completion' do - it 'enqueues the CreateSubscriptionJob' do + describe "on order completion" do + it "enqueues the CreateSubscriptionJob" do order = create(:order_ready_to_complete, :with_subscription_line_items) order.complete! diff --git a/spec/support/active_model_mocks.rb b/spec/support/active_model_mocks.rb index 8ee2090d..64c1afdc 100644 --- a/spec/support/active_model_mocks.rb +++ b/spec/support/active_model_mocks.rb @@ -1 +1 @@ -require 'rspec/active_model/mocks' +require "rspec/active_model/mocks" diff --git a/spec/support/cancancan.rb b/spec/support/cancancan.rb index 7fdda0c8..8bf4cf7d 100644 --- a/spec/support/cancancan.rb +++ b/spec/support/cancancan.rb @@ -1 +1 @@ -require 'cancan/matchers' +require "cancan/matchers" diff --git a/spec/support/shoulda.rb b/spec/support/shoulda.rb index 2e087cfe..13f0b51b 100644 --- a/spec/support/shoulda.rb +++ b/spec/support/shoulda.rb @@ -1,4 +1,4 @@ -require 'shoulda-matchers' +require "shoulda-matchers" Shoulda::Matchers.configure do |config| config.integrate do |with| with.test_framework :rspec diff --git a/spec/support/timecop.rb b/spec/support/timecop.rb index cb435ae9..79382012 100644 --- a/spec/support/timecop.rb +++ b/spec/support/timecop.rb @@ -1 +1 @@ -require 'timecop' +require "timecop" diff --git a/spec/support/vcr.rb b/spec/support/vcr.rb index ca8a14a4..ba7329de 100644 --- a/spec/support/vcr.rb +++ b/spec/support/vcr.rb @@ -1,5 +1,5 @@ -require 'webmock/rspec' -require 'vcr' +require "webmock/rspec" +require "vcr" WebMock.disable_net_connect! diff --git a/spec/support/version_cake.rb b/spec/support/version_cake.rb index 8bfa6f99..eb233f6a 100644 --- a/spec/support/version_cake.rb +++ b/spec/support/version_cake.rb @@ -2,7 +2,7 @@ if defined?(VersionCake::TestHelpers) config.include VersionCake::TestHelpers, type: :controller config.before(:each, type: :controller) do - set_request_version('', 1) + set_request_version("", 1) end end end From cc6f11d4e5e81472022a5b4ec16f70eed5d057d4 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Wed, 4 Feb 2026 22:00:39 -0800 Subject: [PATCH 4/8] Ignore parent commit in blames It's just formatting. --- .git-blame-ignore-revs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 00000000..f19180ce --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,5 @@ +# See `git help blame` for more information. +# Use `git config blame.ignoreRevsFile .git-blame-ignore-revs` to enable. + +# Reformat project +f94afca4 From a05b706e96b051d9726305e35c80bdf7b3c5174a Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Thu, 5 Feb 2026 13:30:31 -0800 Subject: [PATCH 5/8] Fix GitHub actions test running --- .github/workflows/test.yml | 51 ++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4579edbb..038e553c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,6 +7,7 @@ on: pull_request: schedule: - cron: "0 0 * * 4" # every Thursday + workflow_call: concurrency: group: test-${{ github.ref_name }} @@ -23,37 +24,55 @@ jobs: fail-fast: true matrix: rails-version: - - "7.0" - "7.1" - "7.2" + - "8.0" ruby-version: - "3.1" - "3.4" solidus-branch: - - "v4.1" - - "v4.2" - "v4.3" - "v4.4" - "v4.5" + - "main" database: - "postgresql" - "mysql" - "sqlite" exclude: + - solidus-branch: "main" + ruby-version: "3.1" - rails-version: "7.2" solidus-branch: "v4.3" - - rails-version: "7.2" - solidus-branch: "v4.2" - - rails-version: "7.2" - solidus-branch: "v4.1" - - rails-version: "7.1" - solidus-branch: "v4.2" - - rails-version: "7.1" - solidus-branch: "v4.1" - - ruby-version: "3.4" - rails-version: "7.0" - env: - CODECOV_COVERAGE_PATH: ./coverage/coverage.xml + - ruby-version: "3.1" + rails-version: "8.0" + - solidus-branch: "v4.3" + rails-version: "8.0" + - solidus-branch: "v4.4" + rails-version: "8.0" + services: + postgres: + image: postgres:16 + env: + POSTGRES_HOST_AUTH_METHOD: trust + options: >- + --health-cmd="pg_isready" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + ports: + - 5432:5432 + mysql: + image: mysql:8 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: "yes" + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + ports: + - 3306:3306 steps: - uses: actions/checkout@v4 - name: Run extension tests @@ -68,4 +87,4 @@ jobs: continue-on-error: true with: token: ${{ secrets.CODECOV_TOKEN }} - files: ${{ env.CODECOV_COVERAGE_PATH }} + files: ./coverage/coverage.xml From eb6780c3a7bc813c8bbd59ba25c56aafe98852ca Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Thu, 5 Feb 2026 14:16:58 -0800 Subject: [PATCH 6/8] Update enum syntax The previous syntax doesn't work on Rails 8+. --- app/models/solidus_subscriptions/interval.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/solidus_subscriptions/interval.rb b/app/models/solidus_subscriptions/interval.rb index 0be51b9e..ac89d37b 100644 --- a/app/models/solidus_subscriptions/interval.rb +++ b/app/models/solidus_subscriptions/interval.rb @@ -8,7 +8,7 @@ module SolidusSubscriptions module Interval def self.included(base) - base.enum interval_units: { + base.enum :interval_units, { day: 0, week: 1, month: 2, From dfe45c6c49f99b4a0b77cffd71518d3010ac4503 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Thu, 5 Feb 2026 14:40:03 -0800 Subject: [PATCH 7/8] Avoid problematic versions of state_machines --- Gemfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Gemfile b/Gemfile index c4ea023f..4265de56 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,10 @@ else gem "solidus_frontend", github: "solidusio/solidus", branch: branch end +if branch <= "v4.5" || branch == "main" + gem "state_machines", "<= 0.6" +end + rails_version = ENV.fetch("RAILS_VERSION", "7.0") gem "rails", "~> #{rails_version}" From 5896fdce100d3d8ba4fe8aacb2996f473f5da9e7 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Thu, 5 Feb 2026 14:58:10 -0800 Subject: [PATCH 8/8] Fix references to Spree::Deprecation --- spec/controllers/spree/api/users_controller_spec.rb | 2 +- .../spree/user/have_many_subscriptions_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/controllers/spree/api/users_controller_spec.rb b/spec/controllers/spree/api/users_controller_spec.rb index 026990dd..498e50c9 100644 --- a/spec/controllers/spree/api/users_controller_spec.rb +++ b/spec/controllers/spree/api/users_controller_spec.rb @@ -40,7 +40,7 @@ end it "updates the subscription line items" do - allow(::Spree::Deprecation).to receive(:warn).with(a_string_matching( + allow(::Spree.deprecator).to receive(:warn).with(a_string_matching( "Creating or updating subscriptions through #{Spree.user_class} nested attributes is deprecated" )) update_user diff --git a/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb b/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb index 9cbd3b06..be915fc3 100644 --- a/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb +++ b/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb @@ -10,11 +10,11 @@ describe "#subscriptions_attributes=" do it "throws a deprecation warning" do - allow(::Spree::Deprecation).to receive(:warn) + allow(::Spree.deprecator).to receive(:warn) user.subscriptions_attributes = [{interval_length: 2}] - expect(::Spree::Deprecation) + expect(::Spree.deprecator) .to have_received(:warn) .with(/Creating or updating subscriptions through #{Spree.user_class} nested attributes is deprecated/) end