From 0455f59ff635948938a5ece786812ffa695cdc05 Mon Sep 17 00:00:00 2001 From: Kim Burgestrand Date: Tue, 4 Jan 2022 17:56:23 +0100 Subject: [PATCH] Use activesupport deprecation module for more detailed deprecation warning --- lib/pundit.rb | 4 +++- spec/pundit_spec.rb | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/pundit.rb b/lib/pundit.rb index 0ebda55..e8e7320 100644 --- a/lib/pundit.rb +++ b/lib/pundit.rb @@ -55,7 +55,9 @@ module Pundit class NotDefinedError < Error; end def self.included(base) - warn "[DEPRECATION] 'include Pundit' is deprecated. Please use 'include Pundit::Authorization' instead." + ActiveSupport::Deprecation.warn <<~WARNING.strip_heredoc + 'include Pundit' is deprecated. Please use 'include Pundit::Authorization' instead. + WARNING base.include Authorization end diff --git a/spec/pundit_spec.rb b/spec/pundit_spec.rb index 5f3bdb5..beb6b52 100644 --- a/spec/pundit_spec.rb +++ b/spec/pundit_spec.rb @@ -398,18 +398,23 @@ RSpec.describe Pundit do describe ".included" do it "includes Authorization module" do klass = Class.new - klass.include Pundit + + ActiveSupport::Deprecation.silence do + klass.include Pundit + end expect(klass).to include Pundit::Authorization end it "warns about deprecation" do - allow(Pundit).to receive(:warn) - klass = Class.new - klass.include Pundit + allow(ActiveSupport::Deprecation).to receive(:warn) - expect(Pundit).to have_received(:warn).with start_with("[DEPRECATION]") + ActiveSupport::Deprecation.silence do + klass.include Pundit + end + + expect(ActiveSupport::Deprecation).to have_received(:warn).with start_with("'include Pundit' is deprecated") end end