Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Finish the display_on to storefront_visible migration (#14470)
Damian Legawiecd31a8a5edc0e
diff --git a/CLAUDE.md b/CLAUDE.mdindex 3373c2dfc8..3d84098ee2 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -70,6 +70,7 @@ Pending design work (drafts, no implementation yet):- `6.1-exchange-rates.md` — `Spree::ExchangeRate` + `ExchangeRateProvider` (ECB feed as the credential-free default, registry copied from `tax_providers`/`delivery_rate_providers`, keyed providers via `Spree::Integration`). **Rates fill fields, they never price anything** — a merchant gets editable suggestions for the other currencies and what persists is a plain number they own; Spree's "one explicit amount per currency, no FX" stance is unchanged. Never at charge time: EU VAT Directive Art. 91 pins the rate to the instant VAT becomes chargeable, so a commission invoice's VAT figure must be frozen with its rate/date/source or the platform cannot reproduce its own filed documents (Shopify converts at capture and is the wrong pattern here; Vendure/Medusa/Saleor never convert in core). Rates are stored historically and looked up **most-recent-on-or-before**, never exact-date (the ECB skips weekends); cross-currency derives through the base per Art. 91, never stored as a third row; rate precision is NOT money's `decimal(_,2)`. **Constraints now:** never set `Money.default_bank` or call `exchange_to` (the empty rate store raising `UnknownRate` is correct); new money configuration is born per currency, never one amount + a currency column; no conversion endpoint on any API. Also records two live promotion bugs found while researching it — `Calculator::FlatRate` silently discounts **zero** on a currency mismatch, and `Promotion::Rules::ItemTotal` stores a bare threshold with no currency — both independent of this feature.Shipped plans:+- `5.5-6.0-display-on-to-boolean.md` — Collapse `display_on` tri-state to a single `storefront_visible` boolean on DeliveryMethod, CustomFieldDefinition and PaymentMethod. Real column on all three, `Spree::DisplayOn` concern deleted; `display_on` survives only as a deprecated accessor until 6.1. **Constraints:** never filter admin listings by `storefront_visible` (the backoffice sees every method); a new model needing storefront/admin visibility adds its own column plus `storefront_visible`/`admin_only` scopes rather than a shared concern.- `5.4-store-api-bridges.md` — Bridge 6.0 naming into 5.4 Store API (PR #13782)- `5.4-spree-starter-and-create-spree-app.md` — Replace monorepo server/ with spree-starter template repo- `5.4-option-type-enhancements.md` — `kind` (dropdown/color_swatch/buttons) on OptionType + `color_code` on OptionValuediff --git a/docs/plans/5.5-6.0-display-on-to-boolean.md b/docs/plans/5.5-6.0-display-on-to-boolean.mdindex 2fbfc0a32a..7511fd7abd 100644--- a/docs/plans/5.5-6.0-display-on-to-boolean.md+++ b/docs/plans/5.5-6.0-display-on-to-boolean.md@@ -1,10 +1,10 @@# `display_on` → `storefront_visible` (PaymentMethod, ShippingMethod / DeliveryMethod)-**Status:** 5.5 bridge shipped (`storefront_visible` accessor + Ransacker on the `Spree::DisplayOn` concern). **DeliveryMethod completed the 6.0 flip on 2026-08-05** — real `storefront_visible` boolean column (`null: false, default: true`), off the concern, `display_on` kept as a deprecated reader/writer until 6.1; the tri-state `DISPLAY_ON_*` rate filter became `DeliveryMethod::STOREFRONT`/`BACKOFFICE`. **PaymentMethod and MetafieldDefinition are still on the concern** — their schema rename remains pending.+**Status:** COMPLETE (2026-08-19). All three models carry a real `storefront_visible` boolean column (`null: false, default: true`) and the `Spree::DisplayOn` concern is deleted. DeliveryMethod flipped on 2026-08-05 (the tri-state `DISPLAY_ON_*` rate filter became `DeliveryMethod::STOREFRONT`/`BACKOFFICE`), CustomFieldDefinition on 2026-08-09 as part of the metafields rename, and PaymentMethod on 2026-08-19. Each model keeps `display_on` as a deprecated reader/writer until 6.1.**Target:** 5.5 (API alias + `alias_attribute` shim ✓) + 6.0 (schema rename, drop the `Spree::DisplayOn` tri-state concern)**Depends on:** `5.4-6.0-custom-fields-rename.md` (same bridge pattern, already in flight). `6.0-fulfillment-and-delivery.md` (drives the `ShippingMethod → DeliveryMethod` rename — this plan piggybacks on that wave).**Author:** Damian + Claude-**Last updated:** 2026-05-20+**Last updated:** 2026-08-19## Summary@@ -153,32 +153,23 @@ Part of the 6.0 model rename wave (alongside `Shipment → Fulfillment`, `Shippi#### Migrations+As shipped for PaymentMethod (`ReplacePaymentMethodDisplayOnWithStorefrontVisible`):+```ruby-class AddStorefrontVisibleToPaymentMethods < ActiveRecord::Migration[7.2]- def change+class ReplacePaymentMethodDisplayOnWithStorefrontVisible < ActiveRecord::Migration[8.1]+ def upadd_column :spree_payment_methods, :storefront_visible, :boolean, default: true, null: false- # backfill via rake task before deploying the model change:- # UPDATE spree_payment_methods SET storefront_visible = (display_on != 'back_end')- remove_column :spree_payment_methods, :display_on, :string+ execute(<<~SQL.squish)+ UPDATE spree_payment_methods+ SET storefront_visible = #{connection.quoted_false}+ WHERE display_on = 'back_end'+ SQL+ remove_column :spree_payment_methods, :display_onendend```-Same shape for `spree_shipping_methods` (or `spree_delivery_methods` if the 6.0 table rename ships first — coordinate with `6.0-fulfillment-and-delivery.md`).--Data migration in a rake task (not the migration itself, per CLAUDE.md: "Data transformations go in rake tasks, never in migrations"):--```ruby-namespace :spree do- namespace :upgrade do- task display_on_to_storefront_visible: :environment do- Spree::PaymentMethod.unscoped.where(display_on: 'back_end').update_all(storefront_visible: false)- Spree::ShippingMethod.unscoped.where(display_on: 'back_end').update_all(storefront_visible: false)- # everything else (both, front_end, NULL) keeps the default true- end- end-end-```+**The conversion runs inside the migration, not in a rake task** — the usual "data transformations go in rake tasks" rule assumes the source column still exists when the task runs. Here the migration drops `display_on` in the same statement, so a follow-up task would have nothing left to read. Everything except `back_end` keeps the column default of `true`, which is why only one narrow `UPDATE` is needed. CustomFieldDefinition converted the same way; DeliveryMethod is the one exception, because its migration only added the column and left the backfill to `spree:migrate_shipping_to_delivery`, which converts and then clears `display_on` so re-running is safe.#### Model cleanup@@ -198,7 +189,7 @@ end### For Spree merchants / hosters (5.5 → 6.0)1. Update Spree to 5.5 — no action required. `display_on` keeps working; `storefront_visible` becomes available.-2. Update Spree to 6.0 — run `bin/rails spree:upgrade:display_on_to_storefront_visible` against the production database before deploying the 6.0 code.+2. Update Spree to 6.0 — run `bin/rails db:migrate`. Payment methods and custom field definitions convert atomically inside their own migrations, so there is no separate task to run and no window where the data is half-converted. Delivery methods convert in `spree:migrate_shipping_to_delivery`, already part of the 5.6 → 6.0 upgrade manifest.### For integrations consuming the Admin / Store API1. **5.5:** start reading `storefront_visible` (boolean) instead of `display_on` (string). Both ship side-by-side.@@ -212,16 +203,15 @@ end## Constraints on Current Work-- **All new Spree code (5.5+) should use `storefront_visible`** in serializers, controllers, models, specs, and the Admin SPA. `display_on` is in soft-deprecation as of this plan's adoption.-- **The `<DisplayOnSelect>` component shipped in [PR adding payment-method UX] stays callable for one minor cycle**, but new forms should use the new `<StorefrontVisibleSwitch>` once it lands. The existing component is not deleted in 5.5 — it just has no new callers.-- **Custom Fields (`MetafieldDefinition`) — handled by `5.4-6.0-custom-fields-rename.md`**. Don't try to consolidate the two plans; the custom-fields one is further along and renames more than just the visibility field.-- **The `Spree::DisplayOn` concern is frozen.** No new models should `include Spree::DisplayOn`; new resources that need storefront/admin visibility should add a `storefront_visible:boolean` column directly.+- **`storefront_visible` is the only name.** `display_on` survives on all three models purely as a deprecated reader/writer for out-of-tree code; nothing inside Spree may call it. The column is gone, so there is nothing to query.+- **No new model gets a visibility concern.** A resource that needs storefront/admin visibility adds its own `storefront_visible:boolean` column plus the two scopes — three copies of four lines never justified the indirection, which is why the concern was deleted rather than rewritten. Revisit only if a fourth caller appears.+- **Backoffice sees everything.** `storefront_visible` filters the customer-facing surface only; admin listings must not apply it. The old `available_on_back_end` scope (which returned `back_end` + `both`) had no boolean equivalent and was dropped rather than translated.-## Open Questions+## Resolved Questions-- **Should we also rename `available_on_front_end` (the instance predicate from `Spree::DisplayOn`) in 5.5?** Leaning yes — alias it to `storefront_visible` and add a deprecation warning when called. Removed in 6.0.-- **Does the Store API expose `display_on` on `ShippingMethod`?** Need to audit — if yes, the bridge needs to handle the Store API surface too, not just Admin.-- **Naming for the 6.0 concern (if any):** if a third caller wants storefront/admin visibility post-6.0, do we extract a `Spree::StorefrontVisible` concern, or just keep inline columns + scopes per model? Defer until a third caller appears.+- **Rename the `available_on_front_end?` predicate?** Yes. It survives on PaymentMethod as a deprecated shell delegating to `storefront_visible?`, removed in 6.1. DeliveryMethod and CustomFieldDefinition never carried it forward.+- **Does the Store API expose `display_on` on ShippingMethod?** No. The Store delivery-methods surface only ever filtered by it server-side; it was never a wire field, so no Store API bridge was needed.+- **Extract a `Spree::StorefrontVisible` concern in 6.0?** No — see the constraint above. Each model owns its column and scopes.## Referencesdiff --git a/spree/api/spec/controllers/spree/api/v3/admin/payment_methods_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/payment_methods_controller_spec.rbindex 160683e9b6..9e3d108157 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/payment_methods_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/payment_methods_controller_spec.rb@@ -188,14 +188,12 @@ RSpec.describe Spree::Api::V3::Admin::PaymentMethodsController, type: :controlleendend- # `storefront_visible` is the wire-level visibility flag. The- # underlying `display_on` column lives on until 6.0 (see- # docs/plans/5.5-6.0-display-on-to-boolean.md) but is no longer- # exposed or accepted by the Admin API — clients read/write only the- # boolean.+ # `storefront_visible` is the only visibility flag on the wire; the+ # tri-state `display_on` column was dropped in 6.0 (see+ # docs/plans/5.5-6.0-display-on-to-boolean.md).describe 'storefront_visible' docontext 'GET #show' do- it 'returns storefront_visible: false when display_on is back_end' do+ it 'returns false for a backoffice-only method' dopayment_method.update!(storefront_visible: false)get :show, params: { id: payment_method.prefixed_id }, as: :json@@ -204,8 +202,8 @@ RSpec.describe Spree::Api::V3::Admin::PaymentMethodsController, type: :controlleexpect(json_response).not_to have_key('display_on')end- it 'returns storefront_visible: true when display_on is both' do- payment_method.update!(display_on: 'both')+ it 'returns true for a customer-facing method' do+ payment_method.update!(storefront_visible: true)get :show, params: { id: payment_method.prefixed_id }, as: :json@@ -214,16 +212,16 @@ RSpec.describe Spree::Api::V3::Admin::PaymentMethodsController, type: :controlleendcontext 'PATCH #update' do- it 'maps storefront_visible: false to display_on: back_end' do+ it 'hides the method from the storefront' dopatch :update,params: { id: payment_method.prefixed_id, storefront_visible: false },as: :jsonexpect(response).to have_http_status(:ok)- expect(payment_method.reload.display_on).to eq('back_end')+ expect(payment_method.reload.storefront_visible).to be falseend- it 'maps storefront_visible: true to display_on: both' do+ it 'shows the method on the storefront' dopayment_method.update!(storefront_visible: false)patch :update,@@ -231,7 +229,7 @@ RSpec.describe Spree::Api::V3::Admin::PaymentMethodsController, type: :controlleas: :jsonexpect(response).to have_http_status(:ok)- expect(payment_method.reload.display_on).to eq('both')+ expect(payment_method.reload.storefront_visible).to be trueendendenddiff --git a/spree/core/app/models/concerns/spree/display_on.rb b/spree/core/app/models/concerns/spree/display_on.rbdeleted file mode 100644index 19c68f7ef5..0000000000--- a/spree/core/app/models/concerns/spree/display_on.rb+++ /dev/null@@ -1,50 +0,0 @@-module Spree- module DisplayOn- extend ActiveSupport::Concern-- DISPLAY = [:both, :front_end, :back_end]-- included do- scope :available, -> { where(display_on: [:both]) }- scope :available_on_front_end, -> { where(display_on: [:front_end, :both]) }- scope :available_on_back_end, -> { where(display_on: [:back_end, :both]) }-- # 5.5 → 6.0 bridge: see docs/plans/5.5-6.0-display-on-to-boolean.md.- # The tri-state `display_on` enum collapses to a single- # `storefront_visible` boolean in 6.0 — `back_end` becomes `false`,- # everything else becomes `true`. The legacy `front_end`-only value- # (visible to customers but hidden from staff) has no real use case- # and folds into `storefront_visible: true` on migration.- scope :storefront_visible, -> { where.not(display_on: 'back_end') }- scope :admin_only, -> { where(display_on: 'back_end') }-- # Expose `storefront_visible` to Ransack so admin clients can filter- # by it (e.g. `q[storefront_visible_eq]=true`) without knowing about- # the underlying tri-state `display_on` column.- ransacker :storefront_visible, type: :boolean do |parent|- # Wrap in `Grouping` so Postgres sees `(display_on != 'back_end') = TRUE`- # instead of the ambiguous `display_on != 'back_end' = TRUE`.- Arel::Nodes::Grouping.new(- Arel::Nodes::NotEqual.new(parent.table[:display_on], Arel::Nodes::Quoted.new('back_end'))- )- end-- self.whitelisted_ransackable_attributes =- (whitelisted_ransackable_attributes || []) | %w[storefront_visible]-- validates :display_on, presence: true, inclusion: { in: DISPLAY.map(&:to_s) }-- def available_on_front_end?- display_on == 'front_end' || display_on == 'both'- end-- def storefront_visible- display_on != 'back_end'- end-- def storefront_visible=(value)- self.display_on = value.to_b ? 'both' : 'back_end'- end- end- end-enddiff --git a/spree/core/app/models/concerns/spree/purchase/payment_processing.rb b/spree/core/app/models/concerns/spree/purchase/payment_processing.rbindex a883b44e11..ff908d5386 100644--- a/spree/core/app/models/concerns/spree/purchase/payment_processing.rb+++ b/spree/core/app/models/concerns/spree/purchase/payment_processing.rb@@ -35,7 +35,7 @@ module Spree## @return [Array<Spree::PaymentMethod>]def payment_methods- store.payment_methods.active.available_on_front_end.select { |payment_method| payment_method.available_for_order?(self) }+ store.payment_methods.active.storefront_visible.select { |payment_method| payment_method.available_for_order?(self) }end# Free checkouts have no money to collect.diff --git a/spree/core/app/models/spree/delivery_method.rb b/spree/core/app/models/spree/delivery_method.rbindex d2a0ede9fb..01d06cb000 100644--- a/spree/core/app/models/spree/delivery_method.rb+++ b/spree/core/app/models/spree/delivery_method.rb@@ -84,8 +84,7 @@ module Spreehas_many :shipping_rates, class_name: 'Spree::DeliveryRate', foreign_key: :delivery_method_id, deprecated: truehas_many :shipments, through: :delivery_rates, source: :fulfillment, deprecated: true- # Real column, so no ransacker is needed — only the allowlist entry the- # Spree::DisplayOn concern used to contribute.+ # Real column, so admin clients filter it directly — no ransacker needed.self.whitelisted_ransackable_attributes = %w[storefront_visible]validates :name, presence: truediff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rbindex b6fa85b843..e00ee4ac4e 100644--- a/spree/core/app/models/spree/order.rb+++ b/spree/core/app/models/spree/order.rb@@ -943,7 +943,7 @@ module Spreeenddef collect_backend_payment_methods- store.payment_methods.active.available_on_back_end.select { |pm| pm.available_for_order?(self) }+ store.payment_methods.active.select { |pm| pm.available_for_order?(self) }end@@ -1080,7 +1080,7 @@ module Spreedef collect_payment_methodsSpree::Deprecation.warn('`Order#collect_payment_methods` is deprecated and will be removed in Spree 6.1. Use `payment_methods` instead.')- store.payment_methods.available_on_front_end.select { |pm| pm.available_for_order?(self) }+ store.payment_methods.active.storefront_visible.select { |pm| pm.available_for_order?(self) }enddef credit_card_nil_payment?(attributes)diff --git a/spree/core/app/models/spree/payment_method.rb b/spree/core/app/models/spree/payment_method.rbindex ffe6df49c9..f0443b0b10 100644--- a/spree/core/app/models/spree/payment_method.rb+++ b/spree/core/app/models/spree/payment_method.rb@@ -12,7 +12,6 @@ module Spreeinclude Spree::StorePreferencesinclude Spree::HasCustomFieldsinclude Spree::Metadata- include Spree::DisplayOninclude Spree::CaptureMethodif defined?(Spree::Security::PaymentMethods)include Spree::Security::PaymentMethods@@ -36,13 +35,24 @@ module Spreeendscope :active, -> { where(active: true).order(position: :asc) }- scope :available, -> { active.where(display_on: [:front_end, :back_end, :both]) }+ # Every tri-state display_on value passed the old filter, so availability+ # only ever meant "active".+ scope :available, -> { active }scope :store_credit, -> { where(type: 'Spree::PaymentMethod::StoreCredit') }+ # Customer-facing methods vs backoffice-only ones (manual check entry,+ # internal wire transfers). The backoffice always sees every method.+ scope :storefront_visible, -> { where(storefront_visible: true) }+ scope :admin_only, -> { where(storefront_visible: false) }++ # Real column, so admin clients filter it directly — no ransacker needed.+ self.whitelisted_ransackable_attributes = %w[storefront_visible]+after_initialize :set_name, if: :new_record?validates :name, presence: truevalidates :store, presence: true+ validates :storefront_visible, inclusion: { in: [true, false] }normalizes :name, with: ->(value) { value&.to_s&.squish&.presence }belongs_to :store, class_name: 'Spree::Store'@@ -268,6 +278,24 @@ module Spreeendend+ # @deprecated Use {#storefront_visible?}; removed in 6.1.+ def available_on_front_end?+ Spree::Deprecation.warn('Spree::PaymentMethod#available_on_front_end? is deprecated and will be removed in Spree 6.1. Use #storefront_visible? instead.')+ storefront_visible?+ end++ # @deprecated Use {#storefront_visible}; removed in 6.1.+ def display_on+ Spree::Deprecation.warn('Spree::PaymentMethod#display_on is deprecated and will be removed in Spree 6.1. Use #storefront_visible instead.')+ storefront_visible? ? 'both' : 'back_end'+ end++ # @deprecated Use {#storefront_visible=}; removed in 6.1.+ def display_on=(value)+ Spree::Deprecation.warn('Spree::PaymentMethod#display_on= is deprecated and will be removed in Spree 6.1. Use #storefront_visible= instead.')+ self.storefront_visible = value.to_s != 'back_end'+ end+protecteddef public_preference_keysdiff --git a/spree/core/db/migrate/20260819000001_replace_payment_method_display_on_with_storefront_visible.rb b/spree/core/db/migrate/20260819000001_replace_payment_method_display_on_with_storefront_visible.rbnew file mode 100644index 0000000000..0dcce42373--- /dev/null+++ b/spree/core/db/migrate/20260819000001_replace_payment_method_display_on_with_storefront_visible.rb@@ -0,0 +1,25 @@+class ReplacePaymentMethodDisplayOnWithStorefrontVisible < ActiveRecord::Migration[8.1]+ # Payment methods are the last host of the tri-state display_on column+ # (docs/plans/5.5-6.0-display-on-to-boolean.md). Only back_end ever meant+ # "hide from the storefront"; both and the legacy front_end-only value+ # collapse to true.+ def up+ add_column :spree_payment_methods, :storefront_visible, :boolean, default: true, null: false+ execute(<<~SQL.squish)+ UPDATE spree_payment_methods+ SET storefront_visible = #{connection.quoted_false}+ WHERE display_on = 'back_end'+ SQL+ remove_column :spree_payment_methods, :display_on+ end++ def down+ add_column :spree_payment_methods, :display_on, :string, default: 'both'+ execute(<<~SQL.squish)+ UPDATE spree_payment_methods+ SET display_on = 'back_end'+ WHERE storefront_visible = #{connection.quoted_false}+ SQL+ remove_column :spree_payment_methods, :storefront_visible+ end+enddiff --git a/spree/core/db/sample_data/payment_methods.rb b/spree/core/db/sample_data/payment_methods.rbindex d77a2aab7b..3f6b997ded 100644--- a/spree/core/db/sample_data/payment_methods.rb+++ b/spree/core/db/sample_data/payment_methods.rb@@ -5,7 +5,7 @@ Spree::Store.all.find_each do |store|description: 'Bogus payment gateway.',active: true)- cc_payment_method.display_on = 'back_end'+ cc_payment_method.storefront_visible = falsecc_payment_method.save!check_payment_method = store.payment_methods.find_or_initialize_by(@@ -14,6 +14,6 @@ Spree::Store.all.find_each do |store|description: 'Pay by check.',active: true)- check_payment_method.display_on = 'back_end'+ check_payment_method.storefront_visible = falsecheck_payment_method.save!enddiff --git a/spree/core/spec/models/spree/concerns/display_on_spec.rb b/spree/core/spec/models/spree/concerns/display_on_spec.rbdeleted file mode 100644index 3f722ad96c..0000000000--- a/spree/core/spec/models/spree/concerns/display_on_spec.rb+++ /dev/null@@ -1,76 +0,0 @@-# frozen_string_literal: true--require 'spec_helper'--RSpec.describe Spree::DisplayOn do- # PaymentMethod and CustomFieldDefinition are the remaining hosts and- # include the concern identically. DeliveryMethod moved off it in 6.0 —- # it owns a real storefront_visible column.- let(:payment_method) { build(:check_payment_method) }-- describe '#storefront_visible' do- it 'returns false when display_on is back_end' do- payment_method.display_on = 'back_end'- expect(payment_method.storefront_visible).to be false- end-- it 'returns true when display_on is both' do- payment_method.display_on = 'both'- expect(payment_method.storefront_visible).to be true- end-- it 'returns true for the legacy front_end-only value' do- payment_method.display_on = 'front_end'- expect(payment_method.storefront_visible).to be true- end- end-- describe '#storefront_visible=' do- it 'maps true to display_on=both' do- payment_method.storefront_visible = true- expect(payment_method.display_on).to eq('both')- end-- it 'maps false to display_on=back_end' do- payment_method.storefront_visible = false- expect(payment_method.display_on).to eq('back_end')- end-- it 'coerces truthy strings to true (form payloads)' do- payment_method.storefront_visible = '1'- expect(payment_method.display_on).to eq('both')- end-- it 'coerces falsy strings to false (form payloads)' do- payment_method.storefront_visible = '0'- expect(payment_method.display_on).to eq('back_end')- end-- it 'round-trips: getter returns what setter set' do- payment_method.storefront_visible = false- expect(payment_method.storefront_visible).to be false-- payment_method.storefront_visible = true- expect(payment_method.storefront_visible).to be true- end- end-- describe 'scopes' do- let!(:storefront_method) { create(:check_payment_method) }- let!(:admin_only_method) { create(:check_payment_method, storefront_visible: false) }-- describe '.storefront_visible' do- it 'returns methods where display_on != back_end' do- expect(Spree::PaymentMethod.storefront_visible).to include(storefront_method)- expect(Spree::PaymentMethod.storefront_visible).not_to include(admin_only_method)- end- end-- describe '.admin_only' do- it 'returns methods where display_on == back_end' do- expect(Spree::PaymentMethod.admin_only).to include(admin_only_method)- expect(Spree::PaymentMethod.admin_only).not_to include(storefront_method)- end- end- end-enddiff --git a/spree/core/spec/models/spree/order_spec.rb b/spree/core/spec/models/spree/order_spec.rbindex 5fce83c648..1b082f7f6b 100644--- a/spree/core/spec/models/spree/order_spec.rb+++ b/spree/core/spec/models/spree/order_spec.rb@@ -476,6 +476,28 @@ describe Spree::Order, type: :model doendend+ # The deprecated twin of #payment_methods; it must keep matching its+ # replacement until it is removed in 6.1.+ describe '#collect_payment_methods' do+ it 'excludes an inactive method even when it is storefront-visible' do+ store.payment_methods.create!(name: 'Fake', active: false, storefront_visible: true)++ expect(order.send(:collect_payment_methods)).to be_empty+ end++ it 'excludes a backoffice-only method' do+ store.payment_methods.create!(name: 'Fake', active: true, storefront_visible: false)++ expect(order.send(:collect_payment_methods)).to be_empty+ end++ it 'includes an active storefront-visible method' do+ payment_method = store.payment_methods.create!(name: 'Fake', active: true, storefront_visible: true)++ expect(order.send(:collect_payment_methods)).to include(payment_method)+ end+ end+# Regression test for #4199describe '#collect_frontend_payment_methods' dolet(:ok_method) { double :payment_method, available_for_order?: true, available_for_store?: true, store: store }@@ -489,7 +511,7 @@ describe Spree::Order, type: :model doexpect(order.collect_frontend_payment_methods).to include(payment_method)end- it "includes 'both' payment methods" do+ it 'includes payment methods that are storefront-visible by default' dopayment_method = store.payment_methods.create!(name: 'Fake', active: true)expect(order.collect_frontend_payment_methods).to include(payment_method)end@@ -505,7 +527,7 @@ describe Spree::Order, type: :model doendit 'does not include a payment method that is not suitable for this order' do- allow(Spree::PaymentMethod).to receive(:available_on_front_end).and_return(methods)+ allow(order.store).to receive_message_chain(:payment_methods, :active, :storefront_visible).and_return(methods)expect(order.collect_frontend_payment_methods).to contain_exactly(ok_method)enddiff --git a/spree/core/spec/models/spree/payment_method_spec.rb b/spree/core/spec/models/spree/payment_method_spec.rbindex 1b828ee52e..1179a931e2 100644--- a/spree/core/spec/models/spree/payment_method_spec.rb+++ b/spree/core/spec/models/spree/payment_method_spec.rb@@ -18,50 +18,50 @@ describe Spree::PaymentMethod, type: :model doendcontext 'visibility scopes' do- before do- ['both', 'front_end', 'back_end'].each do |display_on|- store.payment_methods.create(- type: 'Spree::Gateway::Test',- name: 'Display Both',- display_on: display_on,- active: true,- description: 'foofah'- )- end+ let!(:visible_method) do+ store.payment_methods.create!(+ type: 'Spree::Gateway::Test', name: 'Visible', active: true, description: 'foofah'+ )+ end++ let!(:admin_only_method) do+ store.payment_methods.create!(+ type: 'Spree::Gateway::Test', name: 'Admin only', active: true,+ storefront_visible: false, description: 'foofah'+ )end- it 'has 5 total methods' do- expect(Spree::PaymentMethod.count).to eq(3)+ it 'defaults to visible on the storefront' do+ expect(visible_method.storefront_visible).to be trueend- describe '#available' do- it 'returns all methods available to front-end/back-end' do- methods = Spree::PaymentMethod.available- expect(methods.size).to eq(3)- expect(methods.pluck(:display_on)).to match_array(['both', 'front_end', 'back_end'])+ describe '.storefront_visible' do+ it 'returns only customer-facing methods' do+ expect(Spree::PaymentMethod.storefront_visible).to contain_exactly(visible_method)endend- describe '#available_on_front_end' do- it 'returns all methods available to front-end' do- methods = Spree::PaymentMethod.available_on_front_end- expect(methods.size).to eq(2)- expect(methods.pluck(:display_on)).to match_array(['both', 'front_end'])+ describe '.admin_only' do+ it 'returns only backoffice methods' do+ expect(Spree::PaymentMethod.admin_only).to contain_exactly(admin_only_method)endend- describe '#available_on_back_end' do- it 'returns all methods available to back-end' do- methods = Spree::PaymentMethod.available_on_back_end- expect(methods.size).to eq(2)- expect(methods.pluck(:display_on)).to match_array(['both', 'back_end'])+ describe '.available' do+ it 'returns every active method regardless of storefront visibility' do+ expect(Spree::PaymentMethod.available).to contain_exactly(visible_method, admin_only_method)+ end++ it 'excludes inactive methods' do+ visible_method.update!(active: false)+ expect(Spree::PaymentMethod.available).to contain_exactly(admin_only_method)endend- describe '#for_store' do- it 'returns all methods available to front-end/back-end for a store' do+ describe '.for_store' do+ it 'excludes methods belonging to another store' dostore_2 = create(:store)- method_from_other_store = store_2.payment_methods.create(+ method_from_other_store = store_2.payment_methods.create!(type: 'Spree::Gateway::Test',name: 'Display Both',active: true,@@ -69,11 +69,39 @@ describe Spree::PaymentMethod, type: :model do)methods = Spree::PaymentMethod.for_store(store)expect(methods).not_to include(method_from_other_store)- expect(methods.size).to eq(3)+ expect(methods).to contain_exactly(visible_method, admin_only_method)endendend+ describe 'legacy display_on bridge' do+ let(:visible_method) { build(:check_payment_method) }+ let(:admin_only_method) { build(:check_payment_method, storefront_visible: false) }++ it 'reads the boolean back as the old tri-state value' do+ expect(visible_method.display_on).to eq('both')+ expect(admin_only_method.display_on).to eq('back_end')+ end++ it 'writes back_end as hidden and every other value as visible' do+ method = build(:check_payment_method)++ method.display_on = 'back_end'+ expect(method.storefront_visible).to be false++ method.display_on = 'front_end'+ expect(method.storefront_visible).to be true++ method.display_on = 'both'+ expect(method.storefront_visible).to be true+ end++ it 'maps available_on_front_end? onto storefront visibility' do+ expect(visible_method.available_on_front_end?).to be true+ expect(admin_only_method.available_on_front_end?).to be false+ end+ end+describe '#auto_capture?' doclass TestGateway < Spree::Gatewaydef provider_class