Fix pundit authorize in test environment
This commit is contained in:
parent
7dd3b98565
commit
44839d9ddd
@ -3,17 +3,14 @@ class ApplicationController < ActionController::Base
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
# config/initializers/pundit.rb
|
||||
# Extends the ApplicationController to add Pundit for authorization.
|
||||
# Modify this file to change the behavior of a 'not authorized' error.
|
||||
# Be sure to restart your server when you modify this file.
|
||||
module PunditHelper
|
||||
extend ActiveSupport::Concern
|
||||
if (Rails.env.development? || Rails.env.test?)
|
||||
# https://github.com/RailsApps/rails-devise-pundit/issues/10
|
||||
include Pundit
|
||||
# https://github.com/elabs/pundit#ensuring-policies-are-used
|
||||
#after_action :verify_authorized, except: :index
|
||||
#after_action :verify_policy_scoped, only: :index
|
||||
|
||||
#included do
|
||||
#include Pundit
|
||||
#rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
||||
#end
|
||||
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
||||
|
||||
private
|
||||
|
||||
@ -22,6 +19,4 @@ class ApplicationController < ActionController::Base
|
||||
redirect_to (request.referrer || root_path)
|
||||
end
|
||||
end
|
||||
|
||||
ApplicationController.send :include, PunditHelper
|
||||
end
|
||||
|
||||
@ -7,6 +7,9 @@ module PunditHelper
|
||||
|
||||
included do
|
||||
include Pundit
|
||||
# https://github.com/elabs/pundit#ensuring-policies-are-used
|
||||
#after_filter :verify_authorized, except: :index
|
||||
#after_filter :verify_policy_scoped, only: :index
|
||||
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
||||
end
|
||||
|
||||
@ -18,4 +21,4 @@ module PunditHelper
|
||||
end
|
||||
end
|
||||
|
||||
ApplicationController.send :include, PunditHelper
|
||||
ApplicationController.send :include, PunditHelper unless (Rails.env.development? || Rails.env.test?)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user