diff --git a/lib/pg_search.rb b/lib/pg_search.rb index 9ad67ada..3206e1ff 100644 --- a/lib/pg_search.rb +++ b/lib/pg_search.rb @@ -18,7 +18,7 @@ module PgSearch autoload :Document, "pg_search/document" def self.included(base) - ActiveSupport::Deprecation.warn <<~MESSAGE + warn(<<~MESSAGE, category: :deprecated, uplevel: 1) Directly including `PgSearch` into an Active Record model is deprecated and will be removed in pg_search 3.0. Please replace `include PgSearch` with `include PgSearch::Model`. @@ -34,8 +34,8 @@ def self.included(base) self.unaccent_function = "unaccent" class << self - def multisearch(*args) - PgSearch::Document.search(*args) + def multisearch(...) + PgSearch::Document.search(...) end def disable_multisearch diff --git a/lib/pg_search/features/tsearch.rb b/lib/pg_search/features/tsearch.rb index a4136bde..c2a3cc9d 100644 --- a/lib/pg_search/features/tsearch.rb +++ b/lib/pg_search/features/tsearch.rb @@ -70,9 +70,11 @@ def deprecated_headline_options unless value.nil? key = deprecated_key.camelize - ActiveSupport::Deprecation.warn( + warn( "pg_search 3.0 will no longer accept :#{deprecated_key} as an argument to :ts_headline, " \ - "use :#{key} instead." + "use :#{key} instead.", + category: :deprecated, + uplevel: 1 ) hash[key] = ts_headline_option_value(value) diff --git a/lib/pg_search/multisearch.rb b/lib/pg_search/multisearch.rb index 271d4582..bbe150dc 100644 --- a/lib/pg_search/multisearch.rb +++ b/lib/pg_search/multisearch.rb @@ -7,9 +7,11 @@ module Multisearch class << self def rebuild(model, deprecated_clean_up = nil, clean_up: true, transactional: true) unless deprecated_clean_up.nil? - ActiveSupport::Deprecation.warn( + warn( "pg_search 3.0 will no longer accept a boolean second argument to PgSearchMultisearch.rebuild, " \ - "use keyword argument `clean_up:` instead." + "use keyword argument `clean_up:` instead.", + category: :deprecated, + uplevel: 1 ) clean_up = deprecated_clean_up end diff --git a/spec/integration/deprecation_spec.rb b/spec/integration/deprecation_spec.rb index 1f5ee149..919c1163 100644 --- a/spec/integration/deprecation_spec.rb +++ b/spec/integration/deprecation_spec.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true require "spec_helper" +require "active_support/core_ext/kernel/reporting" describe "Including the deprecated PgSearch module" do with_model :SomeModel do model do - ActiveSupport::Deprecation.silence do + silence_warnings do include PgSearch end end @@ -18,16 +19,14 @@ end it "prints a deprecation message" do - allow(ActiveSupport::Deprecation).to receive(:warn) + allow(PgSearch).to receive(:warn) AnotherModel.include(PgSearch) - expect(ActiveSupport::Deprecation).to have_received(:warn).with( - <<~MESSAGE - Directly including `PgSearch` into an Active Record model is deprecated and will be removed in pg_search 3.0. + expect(PgSearch).to have_received(:warn).with(<<~MESSAGE, category: :deprecated, uplevel: 1) + Directly including `PgSearch` into an Active Record model is deprecated and will be removed in pg_search 3.0. - Please replace `include PgSearch` with `include PgSearch::Model`. - MESSAGE - ) + Please replace `include PgSearch` with `include PgSearch::Model`. + MESSAGE end end diff --git a/spec/lib/pg_search/features/tsearch_spec.rb b/spec/lib/pg_search/features/tsearch_spec.rb index de639d1d..04be5a24 100644 --- a/spec/lib/pg_search/features/tsearch_spec.rb +++ b/spec/lib/pg_search/features/tsearch_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "spec_helper" -require "active_support/deprecation" +require "active_support/core_ext/kernel/reporting" describe PgSearch::Features::TSearch do describe "#rank" do @@ -251,7 +251,7 @@ feature = described_class.new(query, options, columns, Model, normalizer) - highlight_sql = ActiveSupport::Deprecation.silence { feature.highlight.to_sql } + highlight_sql = silence_warnings { feature.highlight.to_sql } expected_sql = %{(ts_headline('simple', (coalesce((#{Model.quoted_table_name}."name")::text, '')), (to_tsquery('simple', ''' ' || 'query' || ' ''')), 'StartSel = "", StopSel = "", MaxFragments = 3, MaxWords = 123, MinWords = 456, ShortWord = 4, FragmentDelimiter = "…", HighlightAll = FALSE'))} expect(highlight_sql).to eq(expected_sql) diff --git a/spec/lib/pg_search/multisearch_spec.rb b/spec/lib/pg_search/multisearch_spec.rb index 8d7eab86..3329a883 100644 --- a/spec/lib/pg_search/multisearch_spec.rb +++ b/spec/lib/pg_search/multisearch_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "spec_helper" -require "active_support/deprecation" +require "active_support/core_ext/kernel/reporting" # rubocop:disable RSpec/NestedGroups describe PgSearch::Multisearch do @@ -82,7 +82,7 @@ context "when deprecated_clean_up is true" do it "deletes the document for the model" do - ActiveSupport::Deprecation.silence { described_class.rebuild(model, true) } + silence_warnings { described_class.rebuild(model, true) } expect(PgSearch::Document.count).to eq(1) expect(PgSearch::Document.first.searchable_type).to eq("Bar") end @@ -90,7 +90,7 @@ context "when deprecated_clean_up is false" do it "does not delete the document for the model" do - ActiveSupport::Deprecation.silence { described_class.rebuild(model, false) } + silence_warnings { described_class.rebuild(model, false) } expect(PgSearch::Document.count).to eq(2) end end