Skip to content

Commit

Permalink
Merge pull request #4238 from softr8/fix-admin-users
Browse files Browse the repository at this point in the history
Admin users did not work with custom user models
  • Loading branch information
waiting-for-dev authored Jan 18, 2022
2 parents 9f54d19 + 67eccb4 commit 65a26af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/store_credits/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@
<div class="no-objects-found">
<%= 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 %>
</div>
<% end %>
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|
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
Expand Down

0 comments on commit 65a26af

Please sign in to comment.