Add tests to user model and admin panel requests

This commit is contained in:
riggraz
2019-08-23 15:58:43 +02:00
parent 33ba4771d7
commit 75893bc4fd
6 changed files with 100 additions and 6 deletions

View File

@@ -32,9 +32,12 @@ module Admin
# for more information
def authenticate_admin
super # apply the generic rules for authentication in the admin panel...
# ...plus this one
unless user_signed_in?
flash[:alert] = "You must be logged in to access this page."
redirect_to new_user_session_path
return
end
unless current_user.admin?
flash[:alert] = "You do not have the privilegies to access this page."
redirect_to root_path

View File

@@ -6,7 +6,7 @@ class User < ApplicationRecord
enum role: [:user, :moderator, :admin]
after_initialize :set_default_role, if: :new_record?
validates :full_name, presence: true
validates :full_name, presence: true, length: { in: 2..32 }
def set_default_role
self.role ||= :user