File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3- require 'paranoia'
4-
53module Spree
64 class User < Spree ::Base
75 include UserMethods
@@ -11,8 +9,18 @@ class User < Spree::Base
119 devise :confirmable if Spree ::Auth ::Config [ :confirmable ]
1210 devise :omniauthable , omniauth_providers : Spree ::Auth ::Config [ :omniauthable ] if Spree ::Auth ::Config [ :omniauthable ] . present?
1311
14- acts_as_paranoid
12+ if defined? ( Spree ::SoftDeletable )
13+ include Spree ::SoftDeletable
14+ else
15+ acts_as_paranoid
16+ include Spree ::ParanoiaDeprecations
17+
18+ include Discard ::Model
19+ self . discard_column = :deleted_at
20+ end
21+
1522 after_destroy :scramble_email_and_password
23+ after_discard :scramble_email_and_password
1624
1725 def password = ( new_password )
1826 generate_spree_api_key if new_password . present? && spree_api_key . present?
Original file line number Diff line number Diff line change @@ -40,7 +40,6 @@ Gem::Specification.new do |s|
4040 s . add_dependency "deface" , "~> 1.0"
4141 s . add_dependency "devise" , '~> 4.1'
4242 s . add_dependency "devise-encryptable" , "0.2.0"
43- s . add_dependency "paranoia" , "~> 2.4"
4443 s . add_dependency "solidus_core" , solidus_version
4544 s . add_dependency "solidus_support" , "~> 0.5"
4645
Original file line number Diff line number Diff line change 5050 end
5151
5252 describe '#destroy' do
53- # Users with orders are not deletable in Solidus core
54- # therefore we cannot test this behaviour here.
55- # Also there are already sufficient specs in core.
5653 let ( :user ) { create ( :user ) }
5754
58- it 'acts_as_paranoid' do
59- # Instead of testing implementation details of `acts_as_paranoid`
60- # we are testing that we are using `acts_as_paranoid` by using duck typing
61- expect ( described_class ) . to respond_to ( :with_deleted )
62- expect ( user ) . to respond_to ( :deleted_at )
63- end
64-
6555 context 'with same email address as previously deleted account' do
6656 it 'will allow users to register later' do
6757 user1 = build ( :user )
7262 expect ( user2 . save ) . to be false
7363 expect ( user2 . errors . messages [ :email ] . first ) . to eq "has already been taken"
7464
75- user1 . destroy
65+ user1 . discard
7666 expect ( user2 . save ) . to be true
7767 end
7868 end
7969 end
8070
81- describe '#really_destroy!' do
71+ describe '#destroy' do
72+ let ( :user ) { create ( :user ) }
73+
74+ it 'removes the record from the database' do
75+ user . destroy
76+
77+ if defined? ( Spree ::ParanoiaDeprecations )
78+ expect ( Spree ::User . with_discarded . exists? ( id : user . id ) ) . to eql true
79+ else
80+ expect ( Spree ::User . with_discarded . exists? ( id : user . id ) ) . to eql false
81+ end
82+ end
83+ end
84+
85+ describe '#really_destroy!' , if : defined? ( Spree ::ParanoiaDeprecations ) do
8286 let ( :user ) { create ( :user ) }
8387
8488 it 'removes the record from the database' do
You can’t perform that action at this time.
0 commit comments