Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin users did not work with custom user models #4238

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %>
waiting-for-dev marked this conversation as resolved.
Show resolved Hide resolved
</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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, my fault. This should fix the CI, right?

Suggested change
actual_user_class = Spree.user_class
actual_user_class = Spree.user_class.name

Spree.user_class = 'UserModel'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do an after block here too to make sure subsequent tests are using the original User.

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