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.
|
# For APIs, you may want to use :null_session instead.
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
# config/initializers/pundit.rb
|
if (Rails.env.development? || Rails.env.test?)
|
||||||
# Extends the ApplicationController to add Pundit for authorization.
|
# https://github.com/RailsApps/rails-devise-pundit/issues/10
|
||||||
# Modify this file to change the behavior of a 'not authorized' error.
|
include Pundit
|
||||||
# Be sure to restart your server when you modify this file.
|
# https://github.com/elabs/pundit#ensuring-policies-are-used
|
||||||
module PunditHelper
|
#after_action :verify_authorized, except: :index
|
||||||
extend ActiveSupport::Concern
|
#after_action :verify_policy_scoped, only: :index
|
||||||
|
|
||||||
#included do
|
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
||||||
#include Pundit
|
|
||||||
#rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
|
||||||
#end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
@ -22,6 +19,4 @@ class ApplicationController < ActionController::Base
|
|||||||
redirect_to (request.referrer || root_path)
|
redirect_to (request.referrer || root_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ApplicationController.send :include, PunditHelper
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,6 +7,9 @@ module PunditHelper
|
|||||||
|
|
||||||
included do
|
included do
|
||||||
include Pundit
|
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
|
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -18,4 +21,4 @@ module PunditHelper
|
|||||||
end
|
end
|
||||||
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