Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Dropped the legacy `password_salt` from test app and fix handling missing method in Reset password

Damian Legawiec0110c2f22abc
diff --git a/spree/core/app/models/concerns/spree/admin_user_methods.rb b/spree/core/app/models/concerns/spree/admin_user_methods.rb
index 43e3d1eb70..6ff12e89ff 100644
--- a/spree/core/app/models/concerns/spree/admin_user_methods.rb
+++ b/spree/core/app/models/concerns/spree/admin_user_methods.rb
@@ -21,7 +21,10 @@ module Spree
# Token auto-invalidates when password changes (salt changes)
# Expiration is configurable via Spree::Config.admin_password_reset_expires_in (in minutes)
generates_token_for :password_reset, expires_in: Spree::Config.admin_password_reset_expires_in.minutes do
- password_salt&.last(10) || encrypted_password&.last(10)
+ # `try` rather than `&.`: models without a password_salt method or
+ # column at all (modern Devise) must fall through to encrypted_password
+ # — a bare call would raise NameError before the fallback.
+ try(:password_salt)&.last(10) || encrypted_password&.last(10)
end
def self.find_by_password_reset_token(token)
diff --git a/spree/core/app/models/concerns/spree/user_methods.rb b/spree/core/app/models/concerns/spree/user_methods.rb
index 0ae747d8da..8adc3543c3 100644
--- a/spree/core/app/models/concerns/spree/user_methods.rb
+++ b/spree/core/app/models/concerns/spree/user_methods.rb
@@ -48,7 +48,10 @@ module Spree
# Token auto-invalidates when password changes (salt changes)
# Expiration is configurable via Spree::Config.customer_password_reset_expires_in (in minutes)
generates_token_for :password_reset, expires_in: Spree::Config.customer_password_reset_expires_in.minutes do
- password_salt&.last(10) || encrypted_password&.last(10)
+ # `try` rather than `&.`: models without a password_salt method or
+ # column at all (modern Devise) must fall through to encrypted_password
+ # — a bare call would raise NameError before the fallback.
+ try(:password_salt)&.last(10) || encrypted_password&.last(10)
end
# we need to have this callback before any dependent: :destroy associations
diff --git a/spree/core/lib/generators/spree/authentication/dummy/templates/create_spree_admin_users.rb.tt b/spree/core/lib/generators/spree/authentication/dummy/templates/create_spree_admin_users.rb.tt
index 22fe4a3c61..64811a48df 100644
--- a/spree/core/lib/generators/spree/authentication/dummy/templates/create_spree_admin_users.rb.tt
+++ b/spree/core/lib/generators/spree/authentication/dummy/templates/create_spree_admin_users.rb.tt
@@ -2,7 +2,6 @@ class CreateSpreeAdminUsers < ActiveRecord::Migration<%= migration_version %>
def change
create_table :spree_admin_users do |t|
t.string :encrypted_password, limit: 128
- t.string :password_salt, limit: 128
t.string :email
t.string :remember_token
t.string :persistence_token
diff --git a/spree/core/spec/models/spree/admin_user_spec.rb b/spree/core/spec/models/spree/admin_user_spec.rb
index aabe55f4e2..d1c5e5fdfc 100644
--- a/spree/core/spec/models/spree/admin_user_spec.rb
+++ b/spree/core/spec/models/spree/admin_user_spec.rb
@@ -14,6 +14,17 @@ describe Spree.admin_user_class, type: :model do
admin_user.update!(password: 'new-secret-123', password_confirmation: 'new-secret-123')
expect(described_class.find_by_password_reset_token(token)).to be_nil
end
+
+ # Regression: modern admin schemas have no password_salt column and Devise
+ # defines no such method — the token payload must fall back to
+ # encrypted_password instead of raising NameError. The test table
+ # deliberately omits the legacy column so this spec exercises that path;
+ # if password_salt ever responds again, the schema drifted back to the
+ # legacy shape that masked the production 500.
+ it 'generates tokens without a password_salt column' do
+ expect(admin_user).not_to respond_to(:password_salt)
+ expect(admin_user.generate_token_for(:password_reset)).to be_present
+ end
end
describe '#send_devise_notification (Devise bridge)' do