get some basic admin user tests going

This commit is contained in:
Torsten Ruger 2017-06-05 16:53:32 +03:00
parent cdd87bf56b
commit 79218f213d
5 changed files with 57 additions and 20 deletions

View File

@ -9,9 +9,20 @@ module Admin
before_filter :authenticate_admin
def authenticate_admin
ok = current_user != nil
ok = current_user.email == "torsten@villataika.fi" if ok
redirect_to "/" unless ok
user = current_user
if(user)
redirect_to "/" unless user.admin?
end
end
end
class AdminController < ApplicationController
before_filter :authenticate_admin
def authenticate_admin
user = current_user
if(user)
redirect_to "/" unless user.admin?
end
end
end
end

View File

@ -1,19 +1,4 @@
module Admin
class UsersController < Admin::ApplicationController
# To customize the behavior of this controller,
# simply overwrite any of the RESTful actions. For example:
#
# def index
# super
# @resources = User.all.paginate(10, params[:page])
# end
# Define a custom finder by overriding the `find_resource` method:
# def find_resource(param)
# User.find_by!(slug: param)
# end
# See https://administrate-docs.herokuapp.com/customizing_controller_actions
# for more information
class UsersController < Admin::ApplicationController #AdminController
end
end

View File

@ -0,0 +1,12 @@
describe User do
before(:each) do
sign_admin_in
end
it "lists users" do
visit_path admin_users_path
end
it "shows a user" do
user = create(:user)
visit_path admin_user_path(user)
end
end

View File

@ -3,7 +3,7 @@ describe UserPolicy do
let (:current_user) { FactoryGirl.build_stubbed :user }
let (:other_user) { FactoryGirl.build_stubbed :user }
let (:admin) { FactoryGirl.build_stubbed :user, :admin }
let (:admin) { FactoryGirl.build_stubbed :admin }
permissions :index? do
it "denies access if not an admin" do

View File

@ -0,0 +1,29 @@
module RequestHelper
def ensure_path path
expect(page.current_path).to eq path
end
def visit_path path
visit path
expect(status_code).to be 200
expect(page).not_to have_css(".translation_missing")
ensure_path path
end
def ensure_admin
admin = User.where(:role => :admin).first
admin = create :admin unless admin
expect(admin).not_to be nil
admin
end
def sign_admin_in
admin = ensure_admin
signin(admin.email, admin.password , ".footer-sign")
expect(page).to have_content I18n.t 'devise.sessions.signed_in'
admin
end
end
RSpec.configure do |config|
config.include RequestHelper
end