Skip to content

Commit

Permalink
Add authorization stub before running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
the-krg committed Jul 28, 2023
1 parent 8b701eb commit 60c72d9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
35 changes: 35 additions & 0 deletions admin/spec/controllers/solidus_admin/base_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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: '[email protected]')
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
22 changes: 22 additions & 0 deletions admin/spec/features/accounts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

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

visit "/admin/account"

expect(page).to have_content("Logged in as #{user.email}")
expect(page).to have_content("Log out")
end
end
5 changes: 5 additions & 0 deletions admin/spec/features/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
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

it "lists products", :js do
create(:product, name: "Just a product", price: 19.99)

Expand Down

0 comments on commit 60c72d9

Please sign in to comment.