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
Remove StateChange and LogEntry (#14407)
Damian Legawiec02b179a44b0c
diff --git a/docs/developer/core-concepts/payments.mdx b/docs/developer/core-concepts/payments.mdxindex 956404ec7d..f8b5f92f80 100644--- a/docs/developer/core-concepts/payments.mdx+++ b/docs/developer/core-concepts/payments.mdx@@ -80,10 +80,6 @@ erDiagraminteger refund_reason_id}- LogEntry {- text details- }-Order ||--o{ Payment : "has many"Order ||--o{ PaymentSession : "has many"Payment }o--|| PaymentMethod : "belongs to"@@ -91,7 +87,6 @@ erDiagramPayment }o--o| PaymentSource : "source"Payment }o--o| StoreCredit : "source"Payment ||--o| PaymentSession : "linked via response_code"- Payment ||--o{ LogEntry : "has many"Payment ||--o{ Refund : "has many"PaymentMethod ||--o{ PaymentSession : "has many"PaymentMethod ||--o{ PaymentSetupSession : "has many"@@ -513,13 +508,9 @@ Each payment update also recalculates the order's `payment_state`:| `paid` | This order has been paid for in full |<Warning>-You may want to keep tabs on the number of orders with a `payment_state` of `failed`. A sudden increase could indicate a problem with your payment gateway and most likely a serious problem affecting customer satisfaction. Check the latest `log_entries` for the most recent payments if this is happening.+You may want to keep tabs on the number of orders with a `payment_state` of `failed`. A sudden increase could indicate a problem with your payment gateway and most likely a serious problem affecting customer satisfaction. Check your payment gateway's dashboard for the most recent transactions if this is happening.</Warning>-### Log Entries--Responses from payment gateways are stored as log entries for debugging purposes. These can be viewed in the Admin Panel on the payment detail page.-## Payment SourcesPayment sources represent the actual instrument used for a payment. They are created automatically when a Payment Session completes.diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdxindex 14edb3882b..abc5e1b5c5 100644--- a/docs/developer/upgrades/5.6-to-6.0.mdx+++ b/docs/developer/upgrades/5.6-to-6.0.mdx@@ -354,6 +354,16 @@ Also note:- Localized number parsing still happens: `Spree::Price#amount=` runs `Spree::LocalizedNumber.parse`, so `set_price(currency, '1,599.99')` works as `price=` did.- The variant validation that inferred a missing price from the product's default variant is gone. Set prices explicitly (the product and variant factories already do).+### `StateChange` and `LogEntry` are gone++`Spree::StateChange` and `Spree::LogEntry` are removed — the models, the `state_changes` associations on `Order`, `Payment` and `Fulfillment`, the `log_entries` associations on `Payment` and `Refund`, and everything that wrote to them. Both were write-only: nothing in Spree read the rows back, and the admin screens that displayed them are gone.++**Events are the audit trail now.** Instead of querying state-change rows, subscribe to the lifecycle events that already fire on every meaningful transition: `order.placed`, `order.canceled`, `payment.completed`, `payment.voided`, `fulfillment.ready`, `fulfillment.fulfilled`, `fulfillment.canceled`, `fulfillment.resumed`, and the rest. If you need a persistent history, write it from a subscriber.++**Gateway responses are no longer stored in your database.** `LogEntry` kept every gateway response as serialized YAML. For transaction forensics, use your payment provider's dashboard — `Payment#gateway_dashboard_payment_url` links straight to the transaction — or `Spree::PaymentSession`, which holds the gateway-side state for session-based providers.++The `spree_state_changes` and `spree_log_entries` tables are **not dropped until 6.1**, so your existing rows survive the upgrade. If you want the history long-term, export it before upgrading to 6.1.+## Deprecated in 6.0, removed in 6.1Every rename keeps the legacy name working for one release with a deprecation warning. The notable ones:diff --git a/docs/plans/6.0-cart-order-split.md b/docs/plans/6.0-cart-order-split.mdindex 919f4aff6b..b79b740a44 100644--- a/docs/plans/6.0-cart-order-split.md+++ b/docs/plans/6.0-cart-order-split.md@@ -72,7 +72,7 @@ Every competitor treats this as load-bearing. `Spree::Carts::Complete`:- `completed?` ≡ `completed_at.present?`; `canceled?` ≡ status. `can_ship?`, `uneditable?`, `allow_cancel?` re-expressed over `status` + `completed_at` + fulfillment/return data.- Cancel/resume/approve remain services (`Orders::Cancel`/`Resume`/`Approve` — approve is already machine-free) flipping `status` and running today's side effects (restock/void/refund branches preserved verbatim). `awaiting_return`/`returned` states are **not** carried over — that lifecycle belongs to `6.0-returns-exchanges-claims.md`'s first-class Return models.- The `confirmation_required?` self-reference (the `|| confirm?` hack from #4117) dies with the machine: whether the confirm/review step exists is computed **from data only** (`Spree::Config[:always_include_confirm_step]` or any selected payment method requiring confirmation). A confirm-stage failure no longer "falls back" to an earlier state — there are no states; the client stays on review with the failure in `requirements`/errors.-- Order `state_changes` audit rows are dropped in favor of lifecycle events (`order.placed`, `order.canceled`, `order.resumed`, `order.approved` — already published today). Payment/fulfillment machines keep their own `StateChange` rows.+- Order `state_changes` audit rows are dropped in favor of lifecycle events (`order.placed`, `order.canceled`, `order.resumed`, `order.approved` — already published today). ~~Payment/fulfillment machines keep their own `StateChange` rows.~~ Superseded 2026-08-07: `Spree::StateChange` (and `Spree::LogEntry`) are removed entirely — lifecycle events are the audit everywhere; the tables survive to 6.1 as legacy data (see decisions.md).- **Event naming after the split (settled 2026-07-29, revised same day):** carts publish their own `cart.created` / `cart.updated` / `cart.deleted` lifecycle events (restoring the 5.x abandonment signal that incomplete orders' `order.*` events used to provide; Shopify `carts/*` parity). The placement event is **`order.placed`** — renamed from the historical `order.completed` (Medusa's exact term; avoids Medusa's `order.completed` = "fulfillment finished" collision and reads right to newcomers, the primary audience). 6.0 dual-emits the legacy name with `deprecated_alias_of` metadata; dropped in 6.1. `order.created` cannot take that role because it fires for every order row, including admin drafts and the pre-payment draft copy inside `Carts::Complete` (a failed payment then emits `order.deleted` for it). Admin confirmation resends publish the targeted `order.resend_confirmation_email`, no longer re-blasting the placement event to all consumers. The order event payload carries `cart_id` so abandonment tooling can cancel flows on conversion (BigCommerce `store/cart/converted` parity).- **Price-freeze guarantee** (what OSS platform C's `ArrangingPayment` lock provided): `completing_at` rejects cart mutations while payment is in flight, and the completed Order is immutable per split-adjustments' order-level freeze. Auditable price-at-completion also serves EU Omnibus.@@ -252,7 +252,7 @@ Also in 6.1 (2026-07-29): `spree_orders.market_id` and `spree_orders.channel_id`- Don't add checkout states, transitions, or `checkout_flow` steps — extend `Checkout::Registry` instead.- Don't read or filter on `order.state` in new code — use `completed_at`/`status` predicates and the requirements API.- New money/fulfillment tables are born with the cart/order owner XOR (already honored by split-adjustments and fulfillment plans).-- Don't build on `state_changes` rows where `name: 'order'` — they're going away; subscribe to lifecycle events.+- Don't build on `state_changes` rows at all — the model is gone (2026-08-07); subscribe to lifecycle events.## Resolved Questions@@ -262,7 +262,7 @@ Also in 6.1 (2026-07-29): `spree_orders.market_id` and `spree_orders.channel_id`4. **`confirmation_required?` self-reference eliminated** — confirm-step existence computed from config + payment-method data only.5. **Existing incomplete orders migrate to carts** in Phase 2 — no dual-model serving window; the API façade means clients never notice.6. **Guest token carried** cart → order; permission sets check the same credential.-7. **Order `state_changes` dropped** for lifecycle events; payment/fulfillment audits unaffected.+7. **Order `state_changes` dropped** for lifecycle events; payment/fulfillment rows followed on 2026-08-07 when `Spree::StateChange` was removed entirely.8. **`awaiting_return`/`returned` are not order statuses** — returns lifecycle belongs to the returns plan.9. **Completion resumability is structural**: `order.status: 'draft'` + `orders.cart_id` present + `cart.completed_at: nil` is the "finalize pending" marker — no completion-state column. Mid-completion drafts are excluded from the admin Drafts list by `cart_id: nil` scoping (backoffice drafts have no cart).10. **A completion-recovery sweeper** retries FINALIZE for stale `draft` orders with paid coverage and alerts on persistent failure; transient failures never trigger auto-refund. Pre-capture payment failures compensate by destroying the draft order; post-capture failures never do.diff --git a/docs/plans/decisions.md b/docs/plans/decisions.mdindex efe5610a61..e54af01b32 100644--- a/docs/plans/decisions.md+++ b/docs/plans/decisions.md@@ -1502,3 +1502,30 @@ and `Spree::CalculatedAdjustments` resolves an equivalent registryseparately. Extract a `Spree::RegisteredSubclasses` concern when a familyneeds the registry without preferences — that second consumer is thetrigger, and it would absorb CalculatedAdjustments too.++## 2026-08-07 — StateChange and LogEntry removed; lifecycle events are the only audit++**Decision:** Delete `Spree::StateChange` and `Spree::LogEntry` in 6.0 — models,+associations, state-machine writers, `Payment::Processing#record_response`,+`Refund#create_log_entry` and the `Order#log_state_changes` shell. This+supersedes the cart/order-split note that payment/fulfillment machines keep+their `StateChange` rows.++**Why:** Both were write-only. Nothing in the 6.0 codebase — no serializer, no+API endpoint, no dashboard page, no event payload — ever read them back; the+legacy Rails admin screens that displayed them are gone. Lifecycle events+(`payment.completed`/`voided`, `fulfillment.ready`/`fulfilled`/`canceled`/+`resumed`, `order.*`) are the sanctioned audit, the same call already made for+Order rows. Removing LogEntry also retires YAML-serialized gateway responses+in the database (a historic deserialization CVE surface); gateway dashboards+and `PaymentSession` own transaction forensics now.++**Tables survive to 6.1:** `spree_state_changes` and `spree_log_entries` stay+(same pattern as the returns-chain tables). The 5.6→6.0 upgrade tasks that+touch legacy rows (`migrate_incomplete_orders_to_carts`,+`migrate_shipping_to_delivery`) read the table through anonymous ActiveRecord+classes. Both tables drop in 6.1 alongside `spree_adjustments`.++**Kept:** `Spree::PaymentCaptureEvent` — functional money data, not audit:+`Payment#captured_amount` sums it, partial capture and capture-on-dispatch+depend on it, and the Admin API exposes `captured_amount`.diff --git a/spree/core/app/models/concerns/spree/publishable.rb b/spree/core/app/models/concerns/spree/publishable.rbindex bc87a56f35..62d1a69073 100644--- a/spree/core/app/models/concerns/spree/publishable.rb+++ b/spree/core/app/models/concerns/spree/publishable.rb@@ -14,7 +14,7 @@ module Spree# event_serializer_class to point to the parent serializer.## @example Disabling events for a specific model- # class Spree::LogEntry < Spree.base_class+ # class Spree::StockMovement < Spree.base_class# self.publish_events = false# end#@@ -93,7 +93,7 @@ module Spree# Disable lifecycle events for this model## @example- # class Spree::LogEntry < Spree.base_class+ # class Spree::StockMovement < Spree.base_class# skip_lifecycle_events# end#diff --git a/spree/core/app/models/spree/cart.rb b/spree/core/app/models/spree/cart.rbindex 3026ed66c2..dd254a4c7b 100644--- a/spree/core/app/models/spree/cart.rb+++ b/spree/core/app/models/spree/cart.rb@@ -144,7 +144,6 @@ module Spreefees.for_fulfillments.delete_allfulfillment_ids = fulfillments.map(&:id)- StateChange.where(stateful_type: %w[Spree::Shipment Spree::Fulfillment], stateful_id: fulfillment_ids).delete_allDeliveryRate.where(fulfillment_id: fulfillment_ids).delete_allfulfillments.delete_allfulfillment_items.resetdiff --git a/spree/core/app/models/spree/fulfillment.rb b/spree/core/app/models/spree/fulfillment.rbindex cf021e36f8..53b1d411dd 100644--- a/spree/core/app/models/spree/fulfillment.rb+++ b/spree/core/app/models/spree/fulfillment.rb@@ -28,7 +28,6 @@ module Spreewith_options dependent: :delete_all dohas_many :fulfillment_items, class_name: 'Spree::FulfillmentItem', inverse_of: :fulfillmenthas_many :delivery_rates, -> { order(:cost) }, class_name: 'Spree::DeliveryRate'- has_many :state_changes, as: :statefulendhas_many :tax_lines, class_name: 'Spree::TaxLine', dependent: :destroy, inverse_of: :fulfillmenthas_many :discounts, class_name: 'Spree::Discount', dependent: :destroy, inverse_of: :fulfillment@@ -128,14 +127,6 @@ module Spreetransition from: :canceled, to: :pendingendafter_transition from: :canceled, to: %i(pending ready fulfilled), do: [:after_resume, :publish_fulfillment_resumed_event]-- after_transition do |fulfillment, transition|- fulfillment.state_changes.create!(- previous_state: transition.from,- next_state: transition.to,- name: 'fulfillment'- )- endend# @deprecated Use {#fulfill}; removed in 6.1.diff --git a/spree/core/app/models/spree/log_entry.rb b/spree/core/app/models/spree/log_entry.rbdeleted file mode 100644index 8f74df18a8..0000000000--- a/spree/core/app/models/spree/log_entry.rb+++ /dev/null@@ -1,30 +0,0 @@-module Spree- class LogEntry < Spree.base_class- has_prefix_id :log-- if defined?(Spree::Security::LogEntries)- include Spree::Security::LogEntries- end-- belongs_to :source, polymorphic: true-- # Fix for #1767- # If a payment fails, we want to make sure we keep the record of it failing- after_rollback :save_anyway, if: proc { !Rails.env.test? }-- def save_anyway- Spree::LogEntry.create!(source: source, details: details)- end-- def parsed_details- @details ||= YAML.safe_load(- details,- permitted_classes: [- Spree::PaymentResponse,- ActiveSupport::HashWithIndifferentAccess,- (ActiveMerchant::Billing::Response if defined?(ActiveMerchant::Billing::Response))- ].compact- )- end- end-enddiff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rbindex 1fe3613990..c98a4d1c4b 100644--- a/spree/core/app/models/spree/order.rb+++ b/spree/core/app/models/spree/order.rb@@ -155,7 +155,6 @@ module Spreebelongs_to :preferred_stock_location, class_name: 'Spree::StockLocation', optional: truewith_options dependent: :destroy do- has_many :state_changes, as: :stateful, class_name: 'Spree::StateChange'has_many :line_items, -> { order(:created_at) }, inverse_of: :order, class_name: 'Spree::LineItem'has_many :payments, class_name: 'Spree::Payment'has_many :payment_sessions, inverse_of: :order, class_name: 'Spree::PaymentSession'@@ -652,16 +651,6 @@ module SpreeSpree::CouponCodes::CouponCodesHandler.new(order: self).use_all_codesend- def log_state_changes(state_name:, old_state:, new_state:)- Spree::Deprecation.warn('Spree::Order#log_state_changes is deprecated and will be removed in Spree 6.1.')- state_changes.create(- previous_state: old_state,- next_state: new_state,- name: state_name,- user_id: user_id- )- end-normalizes :coupon_code, with: ->(code) { code.to_s.strip.downcase.presence }def can_add_coupon?@@ -691,7 +680,6 @@ module Spreefees.for_fulfillments.delete_allshipment_ids = fulfillments.map(&:id)- StateChange.where(stateful_type: %w[Spree::Shipment Spree::Fulfillment], stateful_id: shipment_ids).delete_allDeliveryRate.where(fulfillment_id: shipment_ids).delete_allfulfillments.delete_alldiff --git a/spree/core/app/models/spree/payment.rb b/spree/core/app/models/spree/payment.rbindex b1da9fb3d4..2d4c2b30a6 100644--- a/spree/core/app/models/spree/payment.rb+++ b/spree/core/app/models/spree/payment.rb@@ -33,8 +33,6 @@ module Spreevalidate :exactly_one_ownerhas_many :offsets, -> { offset_payment }, class_name: 'Spree::Payment', foreign_key: :source_id- has_many :log_entries, as: :source- has_many :state_changes, as: :statefulhas_many :capture_events, class_name: 'Spree::PaymentCaptureEvent'has_many :refunds, inverse_of: :payment@@ -134,14 +132,6 @@ module Spreeevent :invalidate dotransition from: [:checkout], to: :invalidend-- after_transition do |payment, transition|- payment.state_changes.create!(- previous_state: transition.from,- next_state: transition.to,- name: 'payment'- )- endenddef sourcediff --git a/spree/core/app/models/spree/payment/processing.rb b/spree/core/app/models/spree/payment/processing.rbindex 71923742e0..1efc97b4fe 100644--- a/spree/core/app/models/spree/payment/processing.rb+++ b/spree/core/app/models/spree/payment/processing.rb@@ -74,7 +74,6 @@ module Spree# Standard void usageresponse = payment_method.void(response_code, gateway_options)end- record_response(response)if response.success?self.response_code = response.authorization@@ -142,8 +141,6 @@ module Spreeenddef handle_response(response, success_state, failure_state)- record_response(response)-if response.success?unless response.authorization.nil?self.response_code = response.authorization@@ -161,10 +158,6 @@ module Spreeendend- def record_response(response)- log_entries.create!(details: response.to_yaml)- end-def protect_from_connection_erroryieldrescue Spree::PaymentConnectionError => ediff --git a/spree/core/app/models/spree/refund.rb b/spree/core/app/models/spree/refund.rbindex c462406a95..6b5751ce0d 100644--- a/spree/core/app/models/spree/refund.rb+++ b/spree/core/app/models/spree/refund.rb@@ -18,8 +18,6 @@ module Spree# small and closed, and refunds are never bulk-queried in a hot path.belongs_to :originator, polymorphic: true, optional: true- has_many :log_entries, as: :source-with_options presence: true dovalidates :payment, :reason# can't require this on create because the perform! in after_create needs to run first@@ -29,7 +27,6 @@ module Spreevalidate :amount_is_less_than_or_equal_to_allowed_amount, on: :create, if: :amountafter_create :perform!- after_create :create_log_entryattr_reader :response@@ -113,10 +110,6 @@ module Spree# You can track refunds hereend- def create_log_entry- log_entries.create!(details: @response.to_yaml)- end-def amount_is_less_than_or_equal_to_allowed_amountif amount > payment.credit_allowederrors.add(:amount, :greater_than_allowed)diff --git a/spree/core/app/models/spree/state_change.rb b/spree/core/app/models/spree/state_change.rbdeleted file mode 100644index 71869dda72..0000000000--- a/spree/core/app/models/spree/state_change.rb+++ /dev/null@@ -1,12 +0,0 @@-module Spree- class StateChange < Spree.base_class- has_prefix_id :sc-- belongs_to :user, class_name: "::#{Spree.customer_class}", optional: true- belongs_to :stateful, polymorphic: true-- def <=>(other)- created_at <=> other.created_at- end- end-enddiff --git a/spree/core/app/services/spree/carts/empty.rb b/spree/core/app/services/spree/carts/empty.rbindex a0902bb1e9..8e9f25133e 100644--- a/spree/core/app/services/spree/carts/empty.rb+++ b/spree/core/app/services/spree/carts/empty.rb@@ -29,9 +29,6 @@ module Spreecart.discounts.destroy_allcart.fees.destroy_allcart.fulfillments.destroy_all- # Carts have no state machine — only legacy Order records carry- # state-change rows.- cart.state_changes.destroy_all if cart.respond_to?(:state_changes)cart.order_promotions.destroy_allcart.recalculate_totals!diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.ymlindex acda43ee47..a7b75fb093 100644--- a/spree/core/config/locales/en.yml+++ b/spree/core/config/locales/en.yml@@ -174,14 +174,6 @@ en:spree/state:abbr: Abbreviationname: Name- spree/state_change:- state_changes: State changes- state_from: State from- state_to: State to- timestamp: Timestamp- type: Type- updated: Updated- user: Userspree/store:address: Addresscontact_phone: Contact Phone@@ -505,9 +497,6 @@ en:spree/state:one: Stateother: States- spree/state_change:- one: State Change- other: State Changesspree/stock_item:one: Stock Itemother: Stock Items@@ -1059,7 +1048,6 @@ en:locale_not_supported_by_store: is not supported by this storelocation: Locationlock: Lock- log_entries: Log Entrieslogged_in_successfully: Logged in successfullylogin: Loginlogo: Logo@@ -1464,7 +1452,6 @@ en:start: Startstarts_at: Starts atstate: State- state_changes: State Changesstates: Statesstates_required: States Requiredstatus: Statusdiff --git a/spree/core/lib/spree/testing_support/factories/log_entry_factory.rb b/spree/core/lib/spree/testing_support/factories/log_entry_factory.rbdeleted file mode 100644index 8766a09423..0000000000--- a/spree/core/lib/spree/testing_support/factories/log_entry_factory.rb+++ /dev/null@@ -1,6 +0,0 @@-FactoryBot.define do- factory :log_entry, class: Spree::LogEntry do- source { build(:order) }- details { 'Some details' }- end-enddiff --git a/spree/core/lib/spree/testing_support/factories/state_change_factory.rb b/spree/core/lib/spree/testing_support/factories/state_change_factory.rbdeleted file mode 100644index 06c4986267..0000000000--- a/spree/core/lib/spree/testing_support/factories/state_change_factory.rb+++ /dev/null@@ -1,8 +0,0 @@-FactoryBot.define do- factory :state_change, class: Spree::StateChange do- stateful { build(:order) }- previous_state { 'cart' }- next_state { 'address' }- user { build(:user) }- end-enddiff --git a/spree/core/lib/tasks/carts_migration.rake b/spree/core/lib/tasks/carts_migration.rakeindex 212af66fb9..5b3e982ee0 100644--- a/spree/core/lib/tasks/carts_migration.rake+++ b/spree/core/lib/tasks/carts_migration.rake@@ -15,6 +15,10 @@ namespace :spree dobatch_size = ENV.fetch('BATCH_SIZE', 250).to_istats = Hash.new(0)+ # spree_state_changes has no model anymore (removed in 6.0; the table+ # survives until 6.1 as legacy data), so read it anonymously.+ state_changes = Class.new(ActiveRecord::Base) { self.table_name = 'spree_state_changes' }+incomplete = Spree::Order.unscoped.where(completed_at: nil, canceled_at: nil)with_sessions_ids = incomplete.joins(:payment_sessions).distinct.idsplain_ids = incomplete.where.not(id: with_sessions_ids).ids@@ -72,7 +76,7 @@ namespace :spree do# Order-owned support rows that don't survive the conversion: the# order row must go, and these reference it without a cart leg.Spree::FulfillmentItem.unscoped.where(order_id: order.id).update_all(order_id: nil)- Spree::StateChange.where(stateful_type: 'Spree::Order', stateful_id: order.id).delete_all+ state_changes.where(stateful_type: 'Spree::Order', stateful_id: order.id).delete_allorder.deletestats[:converted] += 1diff --git a/spree/core/lib/tasks/delivery_migration.rake b/spree/core/lib/tasks/delivery_migration.rakeindex 6e74ba50cd..eba6c614d9 100644--- a/spree/core/lib/tasks/delivery_migration.rake+++ b/spree/core/lib/tasks/delivery_migration.rake@@ -10,9 +10,13 @@ namespace :spree dosay = ->(message) { puts message }- # 1. Stored polymorphic class names.+ # 1. Stored polymorphic class names. spree_state_changes has no model+ # anymore (removed in 6.0; the table survives until 6.1 as legacy data),+ # so it is read through an anonymous ActiveRecord class.+ state_changes = Class.new(ActiveRecord::Base) { self.table_name = 'spree_state_changes' }+{- Spree::StateChange => :stateful_type,+ state_changes => :stateful_type,Spree::StockMovement => :originator_type}.each do |klass, column|count = klass.where(column => 'Spree::Shipment').in_batches(of: batch_size).update_all(column => 'Spree::Fulfillment')@@ -25,12 +29,12 @@ namespace :spree dosay.call "spree_adjustments.adjustable_type: #{count} rows Spree::Shipment → Spree::Fulfillment"end- # StateChange#name distinguishes the machine ('shipment' rows become+ # The name column distinguishes the machine ('shipment' rows become# 'fulfillment'); the recorded states keep their history except the# renamed terminal value.- Spree::StateChange.where(name: 'shipment').in_batches(of: batch_size).update_all(name: 'fulfillment')- Spree::StateChange.where(name: 'fulfillment', previous_state: 'shipped').in_batches(of: batch_size).update_all(previous_state: 'fulfilled')- Spree::StateChange.where(name: 'fulfillment', next_state: 'shipped').in_batches(of: batch_size).update_all(next_state: 'fulfilled')+ state_changes.where(name: 'shipment').in_batches(of: batch_size).update_all(name: 'fulfillment')+ state_changes.where(name: 'fulfillment', previous_state: 'shipped').in_batches(of: batch_size).update_all(previous_state: 'fulfilled')+ state_changes.where(name: 'fulfillment', next_state: 'shipped').in_batches(of: batch_size).update_all(next_state: 'fulfilled')# 2. Status value rename on fulfillments ('shipped' → 'fulfilled').count = Spree::Fulfillment.unscoped.where(status: 'shipped').in_batches(of: batch_size).update_all(status: 'fulfilled')diff --git a/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb b/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rbindex 745f71d914..712c61b17b 100644--- a/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb+++ b/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb@@ -31,17 +31,20 @@ describe '6.0 data migration tasks' dodescribe 'spree:migrate_shipping_to_delivery' dolet!(:order) { create(:order_with_line_items, store: store) }let(:fulfillment) { order.fulfillments.first }+ # The StateChange model is gone; legacy rows are reached the same way the+ # task reaches them.+ let(:state_changes) { Class.new(ActiveRecord::Base) { self.table_name = 'spree_state_changes' } }it 'renames stored class-name strings and the shipped status' dofulfillment.update_columns(status: 'shipped', fulfillment_type: nil)- Spree::StateChange.create!(stateful_type: 'Spree::Shipment', stateful_id: fulfillment.id,- name: 'shipment', previous_state: 'ready', next_state: 'shipped')+ state_changes.create!(stateful_type: 'Spree::Shipment', stateful_id: fulfillment.id,+ name: 'shipment', previous_state: 'ready', next_state: 'shipped')run_task('spree:migrate_shipping_to_delivery')expect(fulfillment.reload.status).to eq('fulfilled')expect(fulfillment.fulfillment_type).to eq('shipping')- change = Spree::StateChange.where(stateful_id: fulfillment.id).last+ change = state_changes.where(stateful_id: fulfillment.id).lastexpect(change.stateful_type).to eq('Spree::Fulfillment')expect(change.name).to eq('fulfillment')expect(change.next_state).to eq('fulfilled')diff --git a/spree/core/spec/models/spree/log_entry_spec.rb b/spree/core/spec/models/spree/log_entry_spec.rbdeleted file mode 100644index 14ef032f32..0000000000--- a/spree/core/spec/models/spree/log_entry_spec.rb+++ /dev/null@@ -1,15 +0,0 @@-require 'spec_helper'--describe Spree::LogEntry, type: :model do- let(:log_entry) { create(:log_entry, details: details) }- let(:details) { Spree::PaymentResponse.new(true, 'Bogus Gateway: Forced success', {}, test: true).to_yaml }-- describe '#parsed_details' do- subject { log_entry.parsed_details }-- it 'deserializes log entry with payment response' do- expect(subject).to be_instance_of(Spree::PaymentResponse)- expect(subject.message).to eq('Bogus Gateway: Forced success')- end- end-enddiff --git a/spree/core/spec/models/spree/payment_spec.rb b/spree/core/spec/models/spree/payment_spec.rbindex 4589931d4e..f440cc3874 100644--- a/spree/core/spec/models/spree/payment_spec.rb+++ b/spree/core/spec/models/spree/payment_spec.rb@@ -40,12 +40,6 @@ describe Spree::Payment, type: :model doendbefore do- # Rails >= 5.0.3 returns new object for association so we ugly mock it- allow(payment).to receive(:log_entries).and_return(payment.log_entries)-- # So it doesn't create log entries every time a processing method is called- allow(payment.log_entries).to receive(:create!)-allow(payment).to receive(:payment_method_available_for_order).and_return(nil)end@@ -338,12 +332,6 @@ describe Spree::Payment, type: :model dopayment.authorize!end- it 'logs the response' do- payment.save!- expect(payment.log_entries).to receive(:create!).with(details: anything)- payment.authorize!- end-context 'if successful' dobefore doexpect(payment.payment_method).to receive(:authorize).with(amount_in_cents,@@ -398,12 +386,6 @@ describe Spree::Payment, type: :model dopayment.purchase!end- it 'logs the response' do- payment.save!- expect(payment.log_entries).to receive(:create!).with(details: anything)- payment.purchase!- end-context 'if successful' dobefore doexpect(payment.payment_method).to receive(:purchase).with(amount_in_cents,@@ -618,7 +600,6 @@ describe Spree::Payment, type: :model doit 'does nothing' doexpect(payment).not_to receive(:complete)expect(payment.payment_method).not_to receive(:capture)- expect(payment.log_entries).not_to receive(:create!)payment.capture!endend@@ -646,11 +627,6 @@ describe Spree::Payment, type: :model doendend- it 'logs the response' do- expect(payment.log_entries).to receive(:create!).with(details: anything)- payment.void_transaction!- end-context 'if successful' doit 'updates the response_code with the authorization from the gateway' do# Change it to something different@@ -1190,21 +1166,6 @@ describe Spree::Payment, type: :model doendend- # Regression test for #4072 (kinda)- # The need for this was discovered in the research for #4072- context 'state changes' do- it 'are logged to the database' do- expect(payment.state_changes).to be_empty- expect(payment.process!).to be_a(Spree::PaymentCaptureEvent)- expect(payment.state_changes.count).to eq(2)- changes = payment.state_changes.map { |change| { change.previous_state => change.next_state } }- expect(changes).to match_array([- { 'checkout' => 'processing' },- { 'processing' => 'completed' }- ])- end- end-describe '#source' docontext 'with source required enabled' dolet(:payment) { create(:payment, payment_method: payment_method, source: card, state: 'completed') }diff --git a/spree/core/spec/models/spree/refund_spec.rb b/spree/core/spec/models/spree/refund_spec.rbindex f9734b658d..99fb0da98d 100644--- a/spree/core/spec/models/spree/refund_spec.rb+++ b/spree/core/spec/models/spree/refund_spec.rb@@ -75,10 +75,6 @@ describe Spree::Refund, type: :model doexpect(subject.reload.amount).to eq amountend- it 'creates a log entry' do- expect(subject.log_entries).to be_present- end-it 'does not attempt to process a transaction' doexpect(payment.payment_method).not_to receive(:credit)subject@@ -104,10 +100,6 @@ describe Spree::Refund, type: :model doexpect(subject.amount).to eq amountend- it 'creates a log entry' do- expect(subject.log_entries).to be_present- end-it 'attempts to process a transaction' doexpect(payment.payment_method).to receive(:credit).oncesubjectdiff --git a/spree/core/spec/models/spree/shipment_spec.rb b/spree/core/spec/models/spree/shipment_spec.rbindex 829384608a..44bd91c6d6 100644--- a/spree/core/spec/models/spree/shipment_spec.rb+++ b/spree/core/spec/models/spree/shipment_spec.rb@@ -1118,24 +1118,6 @@ describe Spree::Shipment, type: :model doendend- # Regression test for #4072 (kinda)- # The need for this was discovered in the research for #4702- context 'state changes' do- before do- # Must be stubbed so transition can succeed- allow(order).to receive_messages paid?: true- end-- it 'are logged to the database' do- expect(shipment.state_changes).to be_empty- expect(shipment.ready!).to be true- expect(shipment.state_changes.count).to eq(1)- state_change = shipment.state_changes.first- expect(state_change.previous_state).to eq('pending')- expect(state_change.next_state).to eq('ready')- end- end-describe '.ready_or_pending' dosubject { described_class.ready_or_pending }