Skip to content

Instantly share code, notes, and snippets.

@cswalina
Created June 19, 2018 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cswalina/355949de225a3dfc9dfd0ccf5a853eba to your computer and use it in GitHub Desktop.
Save cswalina/355949de225a3dfc9dfd0ccf5a853eba to your computer and use it in GitHub Desktop.
RailsAdmin.config do |config|
config.authorize_with do
redirect_to main_app.root_path, error: "You are not authorized." unless current_user.is_admin?
end
.
.
.
end
--------
RSpec.describe "Rails Admin" do
describe "authentication" do
context "as an admin" do
it "allows access" do
sign_in create(:admin_user)
visit rails_admin.dashboard_path
expect(current_path).to eq rails_admin.dashboard_path
end
end
context "as a non-admin user" do
it "does not allow access" do
sign_in create(:user)
visit rails_admin.dashboard_path
expect(current_path).to eq root_path
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment