pg_search 2.3.1 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f13cb418b0d27e5136ca3f62d70e67e43ca8c9917ec35415fb142096f415ef0
4
- data.tar.gz: 31d34f5408bdda3131920bf1daa9e8f3204c47ba1edfc867d8926d4f32bc5800
3
+ metadata.gz: 4c16f0c4421b4d6d6f4c247f556c4eb2fdb01242617a1e960fdd15785be84dbf
4
+ data.tar.gz: f580e760db34c55abf2401176681f8053500e3d249dd51edf8dce0dfb251f641
5
5
  SHA512:
6
- metadata.gz: 794064f36a7a6ebbea348273fb64fcf429a9d0ab44e0da83338858925ba8f311da348b259a3b447bbdc63ebf7da40dd87ee1bc8ef7e1b637aa3f77b264444099
7
- data.tar.gz: 4b5b80dc6964fede4e29e22ec34c0bdf20db9719e7f9ca8d094de11d60eb5b2937163a0d466de9c103e454bfc1cbf886ba62269cd240eed1d2b8469154e76b09
6
+ metadata.gz: f649091265d7b174c6b826a38e1f80f5eb57851184d2af4720926982d42c41ee1a4bc9399ca0cb1031c31f9a40313215cced168cb99d0a1cf65000fd7c4c6be9
7
+ data.tar.gz: 42c651d0689300bd1328089814562fe575a43d3cf522365b51f2de828eb33cc55d7eab69d242d525228e62d46bc99f74391e0569c4ef4cd39f27bbaec5deb073
@@ -3,6 +3,7 @@ bundler_args: --binstubs
3
3
  cache: bundler
4
4
 
5
5
  rvm:
6
+ - 2.7.0
6
7
  - 2.6.5
7
8
  - 2.5.7
8
9
  - 2.4.9
@@ -1,5 +1,10 @@
1
1
  # pg_search changelog
2
2
 
3
+ ## 2.3.2
4
+
5
+ * Autoload PgSearch::Document to prevent it from being loaded in projects that are not using multi-search.
6
+ * Rebuilder should use update_pg_search_document if additional_attributes is set (David Ramalho)
7
+
3
8
  ## 2.3.1
4
9
 
5
10
  * Drop support for Active Record < 5.2
@@ -15,6 +15,8 @@ require "pg_search/scope_options"
15
15
  require "pg_search/version"
16
16
 
17
17
  module PgSearch
18
+ autoload :Document, "pg_search/document"
19
+
18
20
  def self.included(base)
19
21
  ActiveSupport::Deprecation.warn <<-MESSAGE.strip_heredoc
20
22
  Directly including `PgSearch` into an Active Record model is deprecated and will be removed in pg_search 3.0.
@@ -67,8 +69,4 @@ module PgSearch
67
69
  end
68
70
  end
69
71
 
70
- ActiveSupport.on_load(:active_record) do
71
- require "pg_search/document"
72
- end
73
-
74
72
  require "pg_search/railtie" if defined?(Rails::Railtie)
@@ -13,7 +13,7 @@ module PgSearch
13
13
  def rebuild
14
14
  if model.respond_to?(:rebuild_pg_search_documents)
15
15
  model.rebuild_pg_search_documents
16
- elsif conditional? || dynamic?
16
+ elsif conditional? || dynamic? || additional_attributes?
17
17
  model.find_each(&:update_pg_search_document)
18
18
  else
19
19
  model.connection.execute(rebuild_sql)
@@ -33,6 +33,10 @@ module PgSearch
33
33
  columns.any? { |column| !column_names.include?(column.to_s) }
34
34
  end
35
35
 
36
+ def additional_attributes?
37
+ model.pg_search_multisearchable_options.key?(:additional_attributes)
38
+ end
39
+
36
40
  def connection
37
41
  model.connection
38
42
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgSearch
4
- VERSION = '2.3.1'
4
+ VERSION = '2.3.2'
5
5
  end
@@ -3,7 +3,7 @@
3
3
  require "spec_helper"
4
4
 
5
5
  describe PgSearch::Multisearch::Rebuilder do
6
- with_table "pg_search_documents", {}, &DOCUMENTS_SCHEMA
6
+ with_table "pg_search_documents", &DOCUMENTS_SCHEMA
7
7
 
8
8
  describe 'when initialized with a model that is not multisearchable' do
9
9
  with_model :not_multisearchable
@@ -223,6 +223,33 @@ describe PgSearch::Multisearch::Rebuilder do
223
223
  expect(record.pg_search_document).to be_present
224
224
  end
225
225
  end
226
+
227
+ context "when only additional_attributes is set" do
228
+ with_model :Model do
229
+ table do |t|
230
+ t.string :name
231
+ end
232
+
233
+ model do
234
+ include PgSearch::Model
235
+ multisearchable against: :name,
236
+ additional_attributes: ->(obj) { { additional_attribute_column: "#{obj.class}::#{obj.id}" } }
237
+ end
238
+ end
239
+
240
+ it "calls update_pg_search_document on each record" do
241
+ record_1 = Model.create!(name: "record_1", id: 1)
242
+ record_2 = Model.create!(name: "record_2", id: 2)
243
+
244
+ PgSearch::Document.delete_all
245
+
246
+ rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
247
+ rebuilder.rebuild
248
+
249
+ expect(record_1.reload.pg_search_document.additional_attribute_column).to eq("Model::1")
250
+ expect(record_2.reload.pg_search_document.additional_attribute_column).to eq("Model::2")
251
+ end
252
+ end
226
253
  end
227
254
 
228
255
  context "and multisearchable is conditional" do
@@ -3,7 +3,7 @@
3
3
  require "spec_helper"
4
4
 
5
5
  describe PgSearch::Multisearch do
6
- with_table "pg_search_documents", {}, &DOCUMENTS_SCHEMA
6
+ with_table "pg_search_documents", &DOCUMENTS_SCHEMA
7
7
 
8
8
  with_model :MultisearchableModel do
9
9
  table do |t|
@@ -3,7 +3,7 @@
3
3
  require "spec_helper"
4
4
 
5
5
  describe PgSearch::Multisearchable do
6
- with_table "pg_search_documents", {}, &DOCUMENTS_SCHEMA
6
+ with_table "pg_search_documents", &DOCUMENTS_SCHEMA
7
7
 
8
8
  describe "a model that is multisearchable" do
9
9
  with_model :ModelThatIsMultisearchable do
@@ -17,7 +17,7 @@ end
17
17
 
18
18
  describe PgSearch do
19
19
  describe ".multisearch" do
20
- with_table "pg_search_documents", {}, &DOCUMENTS_SCHEMA
20
+ with_table "pg_search_documents", &DOCUMENTS_SCHEMA
21
21
 
22
22
  describe "delegation to PgSearch::Document.search" do
23
23
  subject { PgSearch.multisearch(query) }
@@ -25,4 +25,7 @@ DOCUMENTS_SCHEMA = lambda do |t|
25
25
  t.belongs_to :searchable, polymorphic: true, index: true
26
26
  t.text :content
27
27
  t.timestamps null: false
28
+
29
+ # Used to test additional_attributes setup
30
+ t.text :additional_attribute_column
28
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Hutchins
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-12-22 00:00:00.000000000 Z
12
+ date: 2020-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  - !ruby/object:Gem::Version
228
228
  version: '0'
229
229
  requirements: []
230
- rubygems_version: 3.0.3
230
+ rubygems_version: 3.1.2
231
231
  signing_key:
232
232
  specification_version: 4
233
233
  summary: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's