diff --git a/admin/spec/controllers/solidus_admin/base_controller_spec.rb b/admin/spec/controllers/solidus_admin/base_controller_spec.rb new file mode 100644 index 00000000000..fbab33fa0af --- /dev/null +++ b/admin/spec/controllers/solidus_admin/base_controller_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe SolidusAdmin::BaseController, type: :controller do + controller(SolidusAdmin::BaseController) do + def index + authorize! :update, Spree::Order + render plain: 'test' + end + end + + context "unauthorized request" do + before do + allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(nil) + end + + it "redirects to unauthorized" do + get :index + expect(response).to redirect_to '/unauthorized' + end + end + + context "successful request" do + before do + user = create(:admin_user, email: 'admin@example.com') + allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user) + end + + it "returns a 200 response" do + get :index + expect(response.code).to eq "200" + end + end +end diff --git a/admin/spec/features/accounts_spec.rb b/admin/spec/features/accounts_spec.rb new file mode 100644 index 00000000000..a1241074c67 --- /dev/null +++ b/admin/spec/features/accounts_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe "Accounts", type: :feature do + let(:user) { create(:admin_user, email: 'admin@example.com') } + + 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 + + visit "/admin/account" + + expect(page).to have_content("Logged in as #{user.email}") + expect(page).to have_content("Log out") + end +end diff --git a/admin/spec/features/products_spec.rb b/admin/spec/features/products_spec.rb index 5ad5cc242fa..cd886ede925 100644 --- a/admin/spec/features/products_spec.rb +++ b/admin/spec/features/products_spec.rb @@ -3,6 +3,11 @@ require 'spec_helper' describe "Products", type: :feature do + before do + user = create(:admin_user, email: 'admin@example.com') + allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user) + end + it "lists products", :js do create(:product, name: "Just a product", price: 19.99)