Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'rails_helper'
describe Admin::PanelController do
describe "GET index" do
context "user has access" do
it "allows access to admin panel" do
set_user_session("admin")
get :index
expect(response.status).to render_template(:index)
end
end
context "user does not have access" do
it "redirects him to login page" do
set_user_session("user")
get :index
expect(response).to redirect_to login_path
end
end
end
def set_user_session(access_level)
ben = build_stubbed(:user, access_level: access_level)
session[:user_id] = ben.id
expect(User).to receive(:find).and_return(ben)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.