Skip to content

Commit

Permalink
Merge pull request #5294 from solidusio/elia/admin/account-path-redirect
Browse files Browse the repository at this point in the history
[Admin] Use the current admin user page as the account path
  • Loading branch information
rainerdema authored Aug 1, 2023
2 parents 1b02916 + 806a5f9 commit 93549ae
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
3 changes: 3 additions & 0 deletions admin/app/controllers/solidus_admin/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

module SolidusAdmin
class AccountsController < SolidusAdmin::BaseController
def show
redirect_to spree.edit_admin_user_path(current_solidus_admin_user)
end
end
end
7 changes: 0 additions & 7 deletions admin/app/views/solidus_admin/accounts/show.html.erb

This file was deleted.

16 changes: 5 additions & 11 deletions admin/spec/features/accounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@
require 'spec_helper'

describe "Accounts", type: :feature do
let(:user) { create(:admin_user, email: '[email protected]') }

before do
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user)
end

it "shows account info" do
without_partial_double_verification do
allow(Spree::Core::Engine.routes.url_helpers).to receive(:admin_logout_path).and_return('/admin/logout')
end
user = create(:admin_user, email: '[email protected]')
stub_authorization! user
sign_in user

visit "/admin/account"

expect(page).to have_content("Logged in as #{user.email}")
expect(page).to have_content("Log out")
expect(page).to have_content(user.email)
expect(current_path).to eq("/admin/users/#{user.id}/edit")
end
end
5 changes: 1 addition & 4 deletions admin/spec/features/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
require 'spec_helper'

describe "Products", type: :feature do
before do
user = create(:admin_user, email: '[email protected]')
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user)
end
before { sign_in create(:admin_user, email: '[email protected]') }

it "lists products", :js do
create(:product, name: "Just a product", price: 19.99)
Expand Down
5 changes: 3 additions & 2 deletions admin/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@
Rails.cache.clear
end

config.include Capybara::RSpecMatchers, type: :component

config.include FactoryBot::Syntax::Methods

config.include SolidusAdmin::FeatureHelpers, type: :feature

config.include Capybara::RSpecMatchers, type: :component
config.include ViewComponent::TestHelpers, type: :component
config.include ViewComponent::SystemTestHelpers, type: :component
config.include SolidusAdmin::ComponentHelpers, type: :component
Expand Down
20 changes: 20 additions & 0 deletions admin/spec/support/solidus_admin/feature_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module SolidusAdmin
module FeatureHelpers
def sign_in(user)
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user)
end

def stub_authorization!(user)
ability = Spree::Ability.new(user)
if block_given?
yield ability
else
ability.can :manage, :all
end
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:current_ability).and_return(ability)
allow_any_instance_of(Spree::Admin::BaseController).to receive(:current_ability).and_return(ability)
end
end
end

0 comments on commit 93549ae

Please sign in to comment.