Skip to content

Commit

Permalink
Merge pull request #3139 from aitbw/aitbw/avoid-user-destruction
Browse files Browse the repository at this point in the history
Don't allow deletion for users with orders
  • Loading branch information
kennyadsl authored Mar 20, 2019
2 parents 2ac5bb8 + 2e96c7a commit 7ca285d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<% if can?(:edit, user) %>
<%= link_to_edit user, no_text: true %>
<% end %>
<% if can?(:destroy, user) %>
<% if can?(:destroy, user) && user.orders.count.zero? %>
<%= link_to_delete user, no_text: true %>
<% end %>
</td>
Expand Down
18 changes: 18 additions & 0 deletions backend/spec/features/admin/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,24 @@ def always_invalid_email
end
end

context 'deleting users' do
let!(:an_user) { create(:user_with_addresses, email: 'an_user@example.com') }
let!(:order) { create(:completed_order_with_totals, user_id: an_user.id) }

context 'if an user has placed orders' do
before do
visit spree.admin_path
click_link 'Users'
end

it "can't be deleted" do
within "#spree_user_#{an_user.id}" do
expect(page).not_to have_selector('.fa-trash')
end
end
end
end

context 'order history with sorting' do
before do
orders
Expand Down

0 comments on commit 7ca285d

Please sign in to comment.