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.

Added `UserMethods#scramble_email_and_names`

Damian Legawiec4006c7d06a9d
diff --git a/core/app/models/concerns/spree/user_methods.rb b/core/app/models/concerns/spree/user_methods.rb
index 5158a19431..24c7e86b52 100644
--- a/core/app/models/concerns/spree/user_methods.rb
+++ b/core/app/models/concerns/spree/user_methods.rb
@@ -106,5 +106,13 @@ module Spree
def use_billing?
use_billing.in?([true, 'true', '1'])
end
+
+ def scramble_email_and_names
+ self.email = "#{SecureRandom.uuid}@example.net"
+ self.first_name = 'Deleted'
+ self.last_name = 'User'
+ self.login = email
+ save
+ end
end
end
diff --git a/core/spec/models/spree/concerns/user_methods_spec.rb b/core/spec/models/spree/concerns/user_methods_spec.rb
index 8056dde780..9c5da24b06 100644
--- a/core/spec/models/spree/concerns/user_methods_spec.rb
+++ b/core/spec/models/spree/concerns/user_methods_spec.rb
@@ -156,4 +156,13 @@ describe Spree::UserMethods do
expect(subject).not_to include(credit_card_with_inactive_payment_method)
end
end
+
+ describe '#scramble_email_and_names' do
+ it 'scramble email and names' do
+ expect { test_user.send(:scramble_email_and_names) }.to change(test_user, :email).and change(test_user, :first_name).and change(test_user, :last_name)
+ expect(test_user.login).to eq(test_user.email)
+ expect(test_user.first_name).to eq('Deleted')
+ expect(test_user.last_name).to eq('User')
+ end
+ end
end