Skip to content

Commit

Permalink
Merge pull request #376 from kddeisz/fix-deprecation-warnings
Browse files Browse the repository at this point in the history
Rails 5.2.0.beta2 compatibility
  • Loading branch information
nertzy committed Dec 23, 2017
2 parents 419b077 + 3cd0ff8 commit 0955838
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Expand Up @@ -46,5 +46,7 @@ Bundler/DuplicatedGem:
Style/EmptyMethod:
EnforcedStyle: expanded

# Waiting on false positives to go away with:
# https://github.com/bbatsov/rubocop/pull/5230
Style/FormatStringToken:
Enabled: false
4 changes: 1 addition & 3 deletions lib/pg_search.rb
Expand Up @@ -37,9 +37,7 @@ def pg_search_scope(name, options)
end

def multisearchable(options = {})
# rubocop:disable Style/MixinUsage
include PgSearch::Multisearchable
# rubocop:enable Style/MixinUsage
include PgSearch::Multisearchable # rubocop:disable Style/MixinUsage
class_attribute :pg_search_multisearchable_options
self.pg_search_multisearchable_options = options
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pg_search/scope_options.rb
Expand Up @@ -16,7 +16,7 @@ def apply(scope)

scope
.joins(rank_join(rank_table_alias))
.order("#{rank_table_alias}.rank DESC, #{order_within_rank}")
.order(Arel.sql("#{rank_table_alias}.rank DESC, #{order_within_rank}"))
.extend(DisableEagerLoading)
.extend(WithPgSearchRank)
.extend(WithPgSearchHighlight[feature_for(:tsearch)])
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/associations_spec.rb
Expand Up @@ -131,7 +131,7 @@

results = ModelWithHasMany
.limit(1)
.order("#{ModelWithHasMany.quoted_table_name}.id ASC")
.order(Arel.sql("#{ModelWithHasMany.quoted_table_name}.id ASC"))
.with_associated('foo bar')

expect(results.map(&:title)).to match_array(included.map(&:title))
Expand Down
25 changes: 23 additions & 2 deletions spec/lib/pg_search_spec.rb
@@ -1,5 +1,18 @@
require "spec_helper"

# For AR 5 and greater, the association reflection's cache needs be cleared
# because we're stubbing the related constants.
class << PgSearch::Document
if ActiveRecord::VERSION::MAJOR >= 5
def clear_searchable_cache
reflect_on_association(:searchable).clear_association_scope_cache
end
else
def clear_searchable_cache
end
end
end

describe PgSearch do
describe ".multisearch" do
with_table "pg_search_documents", {}, &DOCUMENTS_SCHEMA
Expand All @@ -18,7 +31,10 @@

context "with PgSearch.multisearch_options set to a Hash" do
before { allow(PgSearch).to receive(:multisearch_options).and_return(:using => :dmetaphone) }
subject { PgSearch.multisearch(query).map(&:searchable) }
subject do
PgSearch::Document.clear_searchable_cache
PgSearch.multisearch(query).map(&:searchable)
end

with_model :MultisearchableModel do
table do |t|
Expand All @@ -36,7 +52,10 @@
end

context "with PgSearch.multisearch_options set to a Proc" do
subject { PgSearch.multisearch(query, soundalike).map(&:searchable) }
subject do
PgSearch::Document.clear_searchable_cache
PgSearch.multisearch(query, soundalike).map(&:searchable)
end

before do
allow(PgSearch).to receive(:multisearch_options) do
Expand Down Expand Up @@ -140,6 +159,7 @@

PgSearch::Multisearch.rebuild(SearchableSubclassModel)

PgSearch::Document.clear_searchable_cache
expect(PgSearch::Document.count).to be 1
expect(PgSearch::Document.first.searchable.class).to be SearchableSubclassModel
expect(PgSearch::Document.first.searchable).to eq expected
Expand All @@ -153,6 +173,7 @@
PgSearch::Multisearch.rebuild(SearchableSubclassModel)
expect(PgSearch::Document.count).to be 2

PgSearch::Document.clear_searchable_cache
classes = PgSearch::Document.all.collect {|d| d.searchable.class }
expect(classes).to include SearchableSubclassModel
expect(classes).to include AnotherSearchableSubclassModel
Expand Down

0 comments on commit 0955838

Please sign in to comment.