Skip to content

Commit

Permalink
Admin users did not work with custom user models
Browse files Browse the repository at this point in the history
If Spree.user_class was other than Spree::User, it was failing
to create edit and delete url's in Admin::UsersController#index,
using CustomUser for example, it tried to generate: admin_custom_user_url
instead of using the existing admin_user_url
  • Loading branch information
softr8 committed Jan 4, 2022
1 parent fda6073 commit 893a282
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend/app/views/spree/admin/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@
<td class="align-center"><%= l user.created_at.to_date %></td>
<td data-hook="admin_users_index_row_actions" class="actions">
<% if can?(:edit, user) %>
<%= link_to_edit user, no_text: true %>
<%= link_to_edit user, no_text: true, url: spree.admin_user_path(user) %>
<% end %>
<% if can?(:destroy, user) && user.orders.count.zero? %>
<%= link_to_delete user, no_text: true %>
<%= link_to_delete user, no_text: true, url: spree.admin_user_path(user) %>
<% end %>
</td>
</tr>
Expand Down
27 changes: 27 additions & 0 deletions backend/spec/controllers/spree/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,33 @@
expect(assigns(:collection)).to eq [user]
end
end

context "when Spree.user_class have a different namespace than Spree" do
class UserModel < ApplicationRecord
self.table_name = 'spree_users'
include Spree::UserMethods
end

around do |example|
Spree.user_class = 'UserModel'
UserModel.create(email: "a@solidus.io")
example.run
Spree.user_class = 'Spree::LegacyUser'
end


stub_authorization! do |_user|
can :manage, Spree.user_class
end

render_views

it "renders the edit and delete links correctly" do
get :index

expect(response).to be_successful
end
end
end

context "#show" do
Expand Down

0 comments on commit 893a282

Please sign in to comment.