Skip to content

Commit 60c72d9

Browse files
committed
Add authorization stub before running tests
1 parent 8b701eb commit 60c72d9

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
describe SolidusAdmin::BaseController, type: :controller do
6+
controller(SolidusAdmin::BaseController) do
7+
def index
8+
authorize! :update, Spree::Order
9+
render plain: 'test'
10+
end
11+
end
12+
13+
context "unauthorized request" do
14+
before do
15+
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(nil)
16+
end
17+
18+
it "redirects to unauthorized" do
19+
get :index
20+
expect(response).to redirect_to '/unauthorized'
21+
end
22+
end
23+
24+
context "successful request" do
25+
before do
26+
user = create(:admin_user, email: '[email protected]')
27+
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user)
28+
end
29+
30+
it "returns a 200 response" do
31+
get :index
32+
expect(response.code).to eq "200"
33+
end
34+
end
35+
end

admin/spec/features/accounts_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe "Accounts", type: :feature do
6+
let(:user) { create(:admin_user, email: '[email protected]') }
7+
8+
before do
9+
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user)
10+
end
11+
12+
it "shows account info" do
13+
without_partial_double_verification do
14+
allow(Spree::Core::Engine.routes.url_helpers).to receive(:admin_logout_path).and_return('/admin/logout')
15+
end
16+
17+
visit "/admin/account"
18+
19+
expect(page).to have_content("Logged in as #{user.email}")
20+
expect(page).to have_content("Log out")
21+
end
22+
end

admin/spec/features/products_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
require 'spec_helper'
44

55
describe "Products", type: :feature do
6+
before do
7+
user = create(:admin_user, email: '[email protected]')
8+
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user)
9+
end
10+
611
it "lists products", :js do
712
create(:product, name: "Just a product", price: 19.99)
813

0 commit comments

Comments
 (0)