-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add authorization stub before running tests
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
admin/spec/controllers/solidus_admin/base_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
|