Skip to content

Commit 11b9fa9

Browse files
committed
Allow using auth_devise with discard
paranoia is not required anymore since 3.0 ships without it. Who is using older versions of Solidus will see the deprecation as the rest of the paranoia code in core.
1 parent 09841c1 commit 11b9fa9

3 files changed

Lines changed: 27 additions & 16 deletions

File tree

app/models/spree/user.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'paranoia'
4-
53
module Spree
64
class User < Spree::Base
75
include UserMethods
@@ -10,8 +8,18 @@ class User < Spree::Base
108
:rememberable, :trackable, :validatable, :encryptable
119
devise :confirmable if Spree::Auth::Config[:confirmable]
1210

13-
acts_as_paranoid
11+
if defined?(Spree::SoftDeletable)
12+
include Spree::SoftDeletable
13+
else
14+
acts_as_paranoid
15+
include Spree::ParanoiaDeprecations
16+
17+
include Discard::Model
18+
self.discard_column = :deleted_at
19+
end
20+
1421
after_destroy :scramble_email_and_password
22+
after_discard :scramble_email_and_password
1523

1624
def password=(new_password)
1725
generate_spree_api_key if new_password.present? && spree_api_key.present?

solidus_auth_devise.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff 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

spec/models/user_spec.rb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,8 @@
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)
@@ -72,13 +62,27 @@
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

0 commit comments

Comments
 (0)