From 67eccb4c586ef552da3b0ba9d0696c37ac4cd78d Mon Sep 17 00:00:00 2001 From: Edwin Cruz Date: Tue, 4 Jan 2022 12:30:07 -0600 Subject: [PATCH] Admin users did not work with custom user models 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 --- .../spree/admin/store_credits/index.html.erb | 2 +- .../views/spree/admin/users/index.html.erb | 4 +-- .../spree/admin/users_controller_spec.rb | 27 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/backend/app/views/spree/admin/store_credits/index.html.erb b/backend/app/views/spree/admin/store_credits/index.html.erb index ff90985947f..6a6d03a0c99 100644 --- a/backend/app/views/spree/admin/store_credits/index.html.erb +++ b/backend/app/views/spree/admin/store_credits/index.html.erb @@ -70,6 +70,6 @@
<%= render 'spree/admin/shared/no_objects_found', resource: Spree::StoreCredit, - new_resource_url: new_object_url %> + new_resource_url: spree.new_admin_user_store_credit_url %>
<% end %> diff --git a/backend/app/views/spree/admin/users/index.html.erb b/backend/app/views/spree/admin/users/index.html.erb index ae828516b52..81d82443b89 100644 --- a/backend/app/views/spree/admin/users/index.html.erb +++ b/backend/app/views/spree/admin/users/index.html.erb @@ -87,10 +87,10 @@ <%= l user.created_at.to_date %> <% 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 %> diff --git a/backend/spec/controllers/spree/admin/users_controller_spec.rb b/backend/spec/controllers/spree/admin/users_controller_spec.rb index 37d710f6eea..bb9f3ec8afa 100644 --- a/backend/spec/controllers/spree/admin/users_controller_spec.rb +++ b/backend/spec/controllers/spree/admin/users_controller_spec.rb @@ -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| + actual_user_class = Spree.user_class + Spree.user_class = 'UserModel' + UserModel.create(email: "a@solidus.io") + example.run + Spree.user_class = actual_user_class.name + end + + render_views + + it "renders the edit and delete links correctly" do + allow(Spree.user_class).to receive(:find_by). + with(hash_including(:spree_api_key)). + and_return(Spree.user_class.new) + + get :index + + expect(response).to be_successful + end + end end context "#show" do