Skip to content

Commit 2e96c7a

Browse files
committed
Don't allow deletion for users with orders
1 parent 4d968a1 commit 2e96c7a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

backend/app/views/spree/admin/users/index.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<% if can?(:edit, user) %>
9090
<%= link_to_edit user, no_text: true %>
9191
<% end %>
92-
<% if can?(:destroy, user) %>
92+
<% if can?(:destroy, user) && user.orders.count.zero? %>
9393
<%= link_to_delete user, no_text: true %>
9494
<% end %>
9595
</td>

backend/spec/features/admin/users_spec.rb

+18
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,24 @@ def always_invalid_email
289289
end
290290
end
291291

292+
context 'deleting users' do
293+
let!(:an_user) { create(:user_with_addresses, email: 'an_user@example.com') }
294+
let!(:order) { create(:completed_order_with_totals, user_id: an_user.id) }
295+
296+
context 'if an user has placed orders' do
297+
before do
298+
visit spree.admin_path
299+
click_link 'Users'
300+
end
301+
302+
it "can't be deleted" do
303+
within "#spree_user_#{an_user.id}" do
304+
expect(page).not_to have_selector('.fa-trash')
305+
end
306+
end
307+
end
308+
end
309+
292310
context 'order history with sorting' do
293311
before do
294312
orders

0 commit comments

Comments
 (0)