pg_search 2.3.2 → 2.3.7

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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.github/workflows/ci.yml +80 -0
  4. data/.jrubyrc +1 -0
  5. data/.standard.yml +6 -0
  6. data/CHANGELOG.md +55 -20
  7. data/CODE_OF_CONDUCT.md +76 -0
  8. data/Gemfile +19 -6
  9. data/LICENSE +1 -1
  10. data/README.md +106 -43
  11. data/Rakefile +9 -6
  12. data/lib/pg_search/configuration/column.rb +6 -4
  13. data/lib/pg_search/configuration/foreign_column.rb +1 -1
  14. data/lib/pg_search/configuration.rb +13 -3
  15. data/lib/pg_search/document.rb +9 -9
  16. data/lib/pg_search/features/dmetaphone.rb +5 -7
  17. data/lib/pg_search/features/feature.rb +1 -1
  18. data/lib/pg_search/features/trigram.rb +4 -4
  19. data/lib/pg_search/features/tsearch.rb +26 -24
  20. data/lib/pg_search/migration/dmetaphone_generator.rb +2 -2
  21. data/lib/pg_search/migration/generator.rb +5 -5
  22. data/lib/pg_search/migration/multisearch_generator.rb +2 -2
  23. data/lib/pg_search/migration/templates/add_pg_search_dmetaphone_support_functions.rb.erb +6 -6
  24. data/lib/pg_search/migration/templates/create_pg_search_documents.rb.erb +2 -2
  25. data/lib/pg_search/model.rb +6 -6
  26. data/lib/pg_search/multisearch/rebuilder.rb +2 -2
  27. data/lib/pg_search/multisearch.rb +23 -4
  28. data/lib/pg_search/multisearchable.rb +7 -7
  29. data/lib/pg_search/normalizer.rb +5 -5
  30. data/lib/pg_search/scope_options.rb +31 -13
  31. data/lib/pg_search/tasks.rb +3 -3
  32. data/lib/pg_search/version.rb +1 -1
  33. data/lib/pg_search.rb +5 -5
  34. data/pg_search.gemspec +16 -24
  35. data/spec/.rubocop.yml +20 -7
  36. data/spec/integration/.rubocop.yml +11 -0
  37. data/spec/integration/associations_spec.rb +121 -160
  38. data/spec/integration/deprecation_spec.rb +7 -8
  39. data/spec/integration/pg_search_spec.rb +390 -332
  40. data/spec/integration/single_table_inheritance_spec.rb +5 -5
  41. data/spec/lib/pg_search/configuration/association_spec.rb +21 -19
  42. data/spec/lib/pg_search/configuration/column_spec.rb +13 -1
  43. data/spec/lib/pg_search/configuration/foreign_column_spec.rb +4 -4
  44. data/spec/lib/pg_search/features/dmetaphone_spec.rb +4 -4
  45. data/spec/lib/pg_search/features/trigram_spec.rb +32 -28
  46. data/spec/lib/pg_search/features/tsearch_spec.rb +57 -33
  47. data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +94 -63
  48. data/spec/lib/pg_search/multisearch_spec.rb +57 -29
  49. data/spec/lib/pg_search/multisearchable_spec.rb +160 -107
  50. data/spec/lib/pg_search/normalizer_spec.rb +12 -10
  51. data/spec/lib/pg_search_spec.rb +75 -64
  52. data/spec/spec_helper.rb +21 -9
  53. data/spec/support/database.rb +10 -8
  54. metadata +20 -134
  55. data/.autotest +0 -5
  56. data/.codeclimate.yml +0 -17
  57. data/.rubocop.yml +0 -56
  58. data/.travis.yml +0 -50
@@ -2,15 +2,16 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
+ # standard:disable RSpec/NestedGroups
5
6
  describe PgSearch::Multisearch::Rebuilder do
6
7
  with_table "pg_search_documents", &DOCUMENTS_SCHEMA
7
8
 
8
- describe 'when initialized with a model that is not multisearchable' do
9
+ describe "when initialized with a model that is not multisearchable" do
9
10
  with_model :not_multisearchable
10
11
 
11
- it 'raises an exception' do
12
+ it "raises an exception" do
12
13
  expect {
13
- PgSearch::Multisearch::Rebuilder.new(NotMultisearchable)
14
+ described_class.new(NotMultisearchable)
14
15
  }.to raise_exception(
15
16
  PgSearch::Multisearch::ModelNotMultisearchable,
16
17
  "NotMultisearchable is not multisearchable. See PgSearch::ClassMethods#multisearchable"
@@ -20,7 +21,7 @@ describe PgSearch::Multisearch::Rebuilder do
20
21
 
21
22
  describe "#rebuild" do
22
23
  context "when the model defines .rebuild_pg_search_documents" do
23
- context "and multisearchable is not conditional" do
24
+ context "when multisearchable is not conditional" do
24
25
  with_model :Model do
25
26
  model do
26
27
  include PgSearch::Model
@@ -31,14 +32,18 @@ describe PgSearch::Multisearch::Rebuilder do
31
32
  end
32
33
  end
33
34
 
34
- it "should call .rebuild_pg_search_documents" do
35
- rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
36
- expect(Model).to receive(:rebuild_pg_search_documents)
37
- rebuilder.rebuild
35
+ it "calls .rebuild_pg_search_documents" do
36
+ rebuilder = described_class.new(Model)
37
+
38
+ without_partial_double_verification do
39
+ allow(Model).to receive(:rebuild_pg_search_documents)
40
+ rebuilder.rebuild
41
+ expect(Model).to have_received(:rebuild_pg_search_documents)
42
+ end
38
43
  end
39
44
  end
40
45
 
41
- context "and multisearchable is conditional" do
46
+ context "when multisearchable is conditional" do
42
47
  %i[if unless].each do |conditional_key|
43
48
  context "via :#{conditional_key}" do
44
49
  with_model :Model do
@@ -55,10 +60,14 @@ describe PgSearch::Multisearch::Rebuilder do
55
60
  end
56
61
  end
57
62
 
58
- it "should call .rebuild_pg_search_documents" do
59
- rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
60
- expect(Model).to receive(:rebuild_pg_search_documents)
61
- rebuilder.rebuild
63
+ it "calls .rebuild_pg_search_documents" do
64
+ rebuilder = described_class.new(Model)
65
+
66
+ without_partial_double_verification do
67
+ allow(Model).to receive(:rebuild_pg_search_documents)
68
+ rebuilder.rebuild
69
+ expect(Model).to have_received(:rebuild_pg_search_documents)
70
+ end
62
71
  end
63
72
  end
64
73
  end
@@ -66,7 +75,7 @@ describe PgSearch::Multisearch::Rebuilder do
66
75
  end
67
76
 
68
77
  context "when the model does not define .rebuild_pg_search_documents" do
69
- context "and multisearchable is not conditional" do
78
+ context "when multisearchable is not conditional" do
70
79
  context "when :against only includes columns" do
71
80
  with_model :Model do
72
81
  table do |t|
@@ -79,8 +88,8 @@ describe PgSearch::Multisearch::Rebuilder do
79
88
  end
80
89
  end
81
90
 
82
- it "should not call :rebuild_pg_search_documents" do
83
- rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
91
+ it "does not call :rebuild_pg_search_documents" do
92
+ rebuilder = described_class.new(Model)
84
93
 
85
94
  # stub respond_to? to return false since should_not_receive defines the method
86
95
  original_respond_to = Model.method(:respond_to?)
@@ -92,24 +101,28 @@ describe PgSearch::Multisearch::Rebuilder do
92
101
  end
93
102
  end
94
103
 
95
- expect(Model).not_to receive(:rebuild_pg_search_documents)
96
- rebuilder.rebuild
104
+ without_partial_double_verification do
105
+ allow(Model).to receive(:rebuild_pg_search_documents)
106
+ rebuilder.rebuild
107
+ expect(Model).not_to have_received(:rebuild_pg_search_documents)
108
+ end
97
109
  end
98
110
 
99
- it "should execute the default SQL" do
111
+ # standard:disable RSpec/ExampleLength
112
+ it "executes the default SQL" do
100
113
  time = Time.utc(2001, 1, 1, 0, 0, 0)
101
- rebuilder = PgSearch::Multisearch::Rebuilder.new(Model, -> { time })
102
-
103
- expected_sql = <<-SQL.strip_heredoc
104
- INSERT INTO "pg_search_documents" (searchable_type, searchable_id, content, created_at, updated_at)
105
- SELECT 'Model' AS searchable_type,
106
- #{Model.quoted_table_name}.#{Model.primary_key} AS searchable_id,
107
- (
108
- coalesce(#{Model.quoted_table_name}."name"::text, '')
109
- ) AS content,
110
- '2001-01-01 00:00:00' AS created_at,
111
- '2001-01-01 00:00:00' AS updated_at
112
- FROM #{Model.quoted_table_name}
114
+ rebuilder = described_class.new(Model, -> { time })
115
+
116
+ expected_sql = <<~SQL.squish
117
+ INSERT INTO "pg_search_documents" (searchable_type, searchable_id, content, created_at, updated_at)
118
+ SELECT 'Model' AS searchable_type,
119
+ #{Model.quoted_table_name}.#{Model.primary_key} AS searchable_id,
120
+ (
121
+ coalesce(#{Model.quoted_table_name}."name"::text, '')
122
+ ) AS content,
123
+ '2001-01-01 00:00:00' AS created_at,
124
+ '2001-01-01 00:00:00' AS updated_at
125
+ FROM #{Model.quoted_table_name}
113
126
  SQL
114
127
 
115
128
  executed_sql = []
@@ -124,8 +137,9 @@ describe PgSearch::Multisearch::Rebuilder do
124
137
  expect(executed_sql.length).to eq(1)
125
138
  expect(executed_sql.first.strip).to eq(expected_sql.strip)
126
139
  end
140
+ # standard:enable RSpec/ExampleLength
127
141
 
128
- context "for a model with a camel case column" do
142
+ context "with a model with a camel case column" do
129
143
  with_model :ModelWithCamelCaseColumn do
130
144
  table do |t|
131
145
  t.string :camelName
@@ -137,14 +151,14 @@ describe PgSearch::Multisearch::Rebuilder do
137
151
  end
138
152
  end
139
153
 
140
- it "creates search document without PG error" do
154
+ it "rebuilds without error" do
141
155
  time = Time.utc(2001, 1, 1, 0, 0, 0)
142
- rebuilder = PgSearch::Multisearch::Rebuilder.new(Model, -> { time })
143
- rebuilder.rebuild
156
+ rebuilder = described_class.new(Model, -> { time })
157
+ expect { rebuilder.rebuild }.not_to raise_error
144
158
  end
145
159
  end
146
160
 
147
- context "for a model with a non-standard primary key" do
161
+ context "with a model with a non-standard primary key" do
148
162
  with_model :ModelWithNonStandardPrimaryKey do
149
163
  table primary_key: :non_standard_primary_key do |t|
150
164
  t.string :name
@@ -156,20 +170,21 @@ describe PgSearch::Multisearch::Rebuilder do
156
170
  end
157
171
  end
158
172
 
173
+ # standard:disable RSpec/ExampleLength
159
174
  it "generates SQL with the correct primary key" do
160
175
  time = Time.utc(2001, 1, 1, 0, 0, 0)
161
- rebuilder = PgSearch::Multisearch::Rebuilder.new(ModelWithNonStandardPrimaryKey, -> { time })
162
-
163
- expected_sql = <<-SQL.strip_heredoc
164
- INSERT INTO "pg_search_documents" (searchable_type, searchable_id, content, created_at, updated_at)
165
- SELECT 'ModelWithNonStandardPrimaryKey' AS searchable_type,
166
- #{ModelWithNonStandardPrimaryKey.quoted_table_name}.non_standard_primary_key AS searchable_id,
167
- (
168
- coalesce(#{ModelWithNonStandardPrimaryKey.quoted_table_name}."name"::text, '')
169
- ) AS content,
170
- '2001-01-01 00:00:00' AS created_at,
171
- '2001-01-01 00:00:00' AS updated_at
172
- FROM #{ModelWithNonStandardPrimaryKey.quoted_table_name}
176
+ rebuilder = described_class.new(ModelWithNonStandardPrimaryKey, -> { time })
177
+
178
+ expected_sql = <<~SQL.squish
179
+ INSERT INTO "pg_search_documents" (searchable_type, searchable_id, content, created_at, updated_at)
180
+ SELECT 'ModelWithNonStandardPrimaryKey' AS searchable_type,
181
+ #{ModelWithNonStandardPrimaryKey.quoted_table_name}.non_standard_primary_key AS searchable_id,
182
+ (
183
+ coalesce(#{ModelWithNonStandardPrimaryKey.quoted_table_name}."name"::text, '')
184
+ ) AS content,
185
+ '2001-01-01 00:00:00' AS created_at,
186
+ '2001-01-01 00:00:00' AS updated_at
187
+ FROM #{ModelWithNonStandardPrimaryKey.quoted_table_name}
173
188
  SQL
174
189
 
175
190
  executed_sql = []
@@ -184,14 +199,12 @@ describe PgSearch::Multisearch::Rebuilder do
184
199
  expect(executed_sql.length).to eq(1)
185
200
  expect(executed_sql.first.strip).to eq(expected_sql.strip)
186
201
  end
202
+ # standard:enable RSpec/ExampleLength
187
203
  end
188
204
  end
189
205
 
190
206
  context "when :against includes non-column dynamic methods" do
191
207
  with_model :Model do
192
- table do
193
- end
194
-
195
208
  model do
196
209
  include PgSearch::Model
197
210
  multisearchable against: [:foo]
@@ -202,10 +215,11 @@ describe PgSearch::Multisearch::Rebuilder do
202
215
  end
203
216
  end
204
217
 
218
+ # standard:disable RSpec/ExampleLength
205
219
  it "calls update_pg_search_document on each record" do
206
220
  record = Model.create!
207
221
 
208
- rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
222
+ rebuilder = described_class.new(Model)
209
223
 
210
224
  # stub respond_to? to return false since should_not_receive defines the method
211
225
  original_respond_to = Model.method(:respond_to?)
@@ -216,12 +230,18 @@ describe PgSearch::Multisearch::Rebuilder do
216
230
  original_respond_to.call(method_name, *args)
217
231
  end
218
232
  end
219
- expect(Model).not_to receive(:rebuild_pg_search_documents)
220
233
 
221
- rebuilder.rebuild
234
+ without_partial_double_verification do
235
+ allow(Model).to receive(:rebuild_pg_search_documents)
236
+
237
+ rebuilder.rebuild
238
+
239
+ expect(Model).not_to have_received(:rebuild_pg_search_documents)
240
+ end
222
241
 
223
242
  expect(record.pg_search_document).to be_present
224
243
  end
244
+ # standard:enable RSpec/ExampleLength
225
245
  end
226
246
 
227
247
  context "when only additional_attributes is set" do
@@ -233,7 +253,7 @@ describe PgSearch::Multisearch::Rebuilder do
233
253
  model do
234
254
  include PgSearch::Model
235
255
  multisearchable against: :name,
236
- additional_attributes: ->(obj) { { additional_attribute_column: "#{obj.class}::#{obj.id}" } }
256
+ additional_attributes: ->(obj) { {additional_attribute_column: "#{obj.class}::#{obj.id}"} }
237
257
  end
238
258
  end
239
259
 
@@ -243,7 +263,7 @@ describe PgSearch::Multisearch::Rebuilder do
243
263
 
244
264
  PgSearch::Document.delete_all
245
265
 
246
- rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
266
+ rebuilder = described_class.new(Model)
247
267
  rebuilder.rebuild
248
268
 
249
269
  expect(record_1.reload.pg_search_document.additional_attribute_column).to eq("Model::1")
@@ -252,7 +272,7 @@ describe PgSearch::Multisearch::Rebuilder do
252
272
  end
253
273
  end
254
274
 
255
- context "and multisearchable is conditional" do
275
+ context "when multisearchable is conditional" do
256
276
  context "via :if" do
257
277
  with_model :Model do
258
278
  table do |t|
@@ -265,11 +285,12 @@ describe PgSearch::Multisearch::Rebuilder do
265
285
  end
266
286
  end
267
287
 
288
+ # standard:disable RSpec/ExampleLength
268
289
  it "calls update_pg_search_document on each record" do
269
290
  record_1 = Model.create!(active: true)
270
291
  record_2 = Model.create!(active: false)
271
292
 
272
- rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
293
+ rebuilder = described_class.new(Model)
273
294
 
274
295
  # stub respond_to? to return false since should_not_receive defines the method
275
296
  original_respond_to = Model.method(:respond_to?)
@@ -280,13 +301,17 @@ describe PgSearch::Multisearch::Rebuilder do
280
301
  original_respond_to.call(method_name, *args)
281
302
  end
282
303
  end
283
- expect(Model).not_to receive(:rebuild_pg_search_documents)
284
304
 
285
- rebuilder.rebuild
305
+ without_partial_double_verification do
306
+ allow(Model).to receive(:rebuild_pg_search_documents)
307
+ rebuilder.rebuild
308
+ expect(Model).not_to have_received(:rebuild_pg_search_documents)
309
+ end
286
310
 
287
311
  expect(record_1.pg_search_document).to be_present
288
312
  expect(record_2.pg_search_document).not_to be_present
289
313
  end
314
+ # standard:enable RSpec/ExampleLength
290
315
  end
291
316
 
292
317
  context "via :unless" do
@@ -301,11 +326,12 @@ describe PgSearch::Multisearch::Rebuilder do
301
326
  end
302
327
  end
303
328
 
329
+ # standard:disable RSpec/ExampleLength
304
330
  it "calls update_pg_search_document on each record" do
305
331
  record_1 = Model.create!(inactive: true)
306
332
  record_2 = Model.create!(inactive: false)
307
333
 
308
- rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
334
+ rebuilder = described_class.new(Model)
309
335
 
310
336
  # stub respond_to? to return false since should_not_receive defines the method
311
337
  original_respond_to = Model.method(:respond_to?)
@@ -316,15 +342,20 @@ describe PgSearch::Multisearch::Rebuilder do
316
342
  original_respond_to.call(method_name, *args)
317
343
  end
318
344
  end
319
- expect(Model).not_to receive(:rebuild_pg_search_documents)
320
345
 
321
- rebuilder.rebuild
346
+ without_partial_double_verification do
347
+ allow(Model).to receive(:rebuild_pg_search_documents)
348
+ rebuilder.rebuild
349
+ expect(Model).not_to have_received(:rebuild_pg_search_documents)
350
+ end
322
351
 
323
352
  expect(record_1.pg_search_document).not_to be_present
324
353
  expect(record_2.pg_search_document).to be_present
325
354
  end
355
+ # standard:enable RSpec/ExampleLength
326
356
  end
327
357
  end
328
358
  end
329
359
  end
330
360
  end
361
+ # standard:enable RSpec/NestedGroups
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "spec_helper"
4
+ require "active_support/core_ext/kernel/reporting"
4
5
 
6
+ # standard:disable RSpec/NestedGroups
5
7
  describe PgSearch::Multisearch do
6
8
  with_table "pg_search_documents", &DOCUMENTS_SCHEMA
7
9
 
@@ -18,22 +20,31 @@ describe PgSearch::Multisearch do
18
20
 
19
21
  let(:model) { MultisearchableModel }
20
22
  let(:connection) { model.connection }
21
- let(:documents) { double(:documents) }
22
23
 
23
24
  describe ".rebuild" do
24
25
  before do
25
26
  model.multisearchable against: :title
26
27
  end
27
28
 
28
- it "should operate inside a transaction" do
29
- expect(model).to receive(:transaction).once
29
+ it "operates inside a transaction" do
30
+ allow(model).to receive(:transaction)
30
31
 
31
- PgSearch::Multisearch.rebuild(model)
32
+ described_class.rebuild(model)
33
+ expect(model).to have_received(:transaction).once
34
+ end
35
+
36
+ context "when transactional is false" do
37
+ it "does not operate inside a transaction" do
38
+ allow(model).to receive(:transaction)
39
+
40
+ described_class.rebuild(model, transactional: false)
41
+ expect(model).not_to have_received(:transaction)
42
+ end
32
43
  end
33
44
 
34
45
  describe "cleaning up search documents for this model" do
35
46
  before do
36
- connection.execute <<-SQL.strip_heredoc
47
+ connection.execute <<~SQL.squish
37
48
  INSERT INTO pg_search_documents
38
49
  (searchable_type, searchable_id, content, created_at, updated_at)
39
50
  VALUES
@@ -47,28 +58,39 @@ describe PgSearch::Multisearch do
47
58
  end
48
59
 
49
60
  context "when clean_up is not passed" do
50
- it "should delete the document for the model" do
51
- PgSearch::Multisearch.rebuild(model)
61
+ it "deletes the document for the model" do
62
+ described_class.rebuild(model)
52
63
  expect(PgSearch::Document.count).to eq(1)
53
64
  expect(PgSearch::Document.first.searchable_type).to eq("Bar")
54
65
  end
55
66
  end
56
67
 
57
68
  context "when clean_up is true" do
58
- let(:clean_up) { true }
59
-
60
- it "should delete the document for the model" do
61
- PgSearch::Multisearch.rebuild(model, clean_up)
69
+ it "deletes the document for the model" do
70
+ described_class.rebuild(model, clean_up: true)
62
71
  expect(PgSearch::Document.count).to eq(1)
63
72
  expect(PgSearch::Document.first.searchable_type).to eq("Bar")
64
73
  end
65
74
  end
66
75
 
67
76
  context "when clean_up is false" do
68
- let(:clean_up) { false }
77
+ it "does not delete the document for the model" do
78
+ described_class.rebuild(model, clean_up: false)
79
+ expect(PgSearch::Document.count).to eq(2)
80
+ end
81
+ end
69
82
 
70
- it "should not delete the document for the model" do
71
- PgSearch::Multisearch.rebuild(model, clean_up)
83
+ context "when deprecated_clean_up is true" do
84
+ it "deletes the document for the model" do
85
+ silence_warnings { described_class.rebuild(model, true) }
86
+ expect(PgSearch::Document.count).to eq(1)
87
+ expect(PgSearch::Document.first.searchable_type).to eq("Bar")
88
+ end
89
+ end
90
+
91
+ context "when deprecated_clean_up is false" do
92
+ it "does not delete the document for the model" do
93
+ silence_warnings { described_class.rebuild(model, false) }
72
94
  expect(PgSearch::Document.count).to eq(2)
73
95
  end
74
96
  end
@@ -76,7 +98,7 @@ describe PgSearch::Multisearch do
76
98
  context "when the model implements .rebuild_pg_search_documents" do
77
99
  before do
78
100
  def model.rebuild_pg_search_documents
79
- connection.execute <<-SQL.strip_heredoc
101
+ connection.execute <<~SQL.squish
80
102
  INSERT INTO pg_search_documents
81
103
  (searchable_type, searchable_id, content, created_at, updated_at)
82
104
  VALUES
@@ -85,31 +107,36 @@ describe PgSearch::Multisearch do
85
107
  end
86
108
  end
87
109
 
88
- it "should call .rebuild_pg_search_documents and skip the default behavior" do
89
- expect(PgSearch::Multisearch).not_to receive(:rebuild_sql)
90
- PgSearch::Multisearch.rebuild(model)
110
+ it "calls .rebuild_pg_search_documents and skips the default behavior" do
111
+ without_partial_double_verification do
112
+ allow(model).to receive(:rebuild_sql)
113
+ described_class.rebuild(model)
91
114
 
92
- record = PgSearch::Document.find_by_searchable_type_and_searchable_id("Baz", 789)
93
- expect(record.content).to eq("baz")
115
+ record = PgSearch::Document.find_by(searchable_type: "Baz", searchable_id: 789)
116
+ expect(model).not_to have_received(:rebuild_sql)
117
+ expect(record.content).to eq("baz")
118
+ end
94
119
  end
95
120
  end
96
121
  end
97
122
 
98
123
  describe "inserting the new documents" do
99
124
  let!(:new_models) { [] }
125
+
100
126
  before do
101
127
  new_models << model.create!(title: "Foo", content: "Bar")
102
128
  new_models << model.create!(title: "Baz", content: "Bar")
103
129
  end
104
130
 
105
- it "should create new documents for the two models" do
106
- PgSearch::Multisearch.rebuild(model)
131
+ it "creates new documents for the two models" do
132
+ described_class.rebuild(model)
107
133
  expect(PgSearch::Document.last(2).map(&:searchable).map(&:title)).to match_array(new_models.map(&:title))
108
134
  end
109
135
  end
110
136
 
111
137
  describe "the generated SQL" do
112
- let(:now) { Time.now }
138
+ let(:now) { Time.now } # standard:disable Rails/TimeZone
139
+
113
140
  before { allow(Time).to receive(:now).and_return(now) }
114
141
 
115
142
  context "with one attribute" do
@@ -117,8 +144,8 @@ describe PgSearch::Multisearch do
117
144
  model.multisearchable against: [:title]
118
145
  end
119
146
 
120
- it "should generate the proper SQL code" do
121
- expected_sql = <<-SQL.strip_heredoc
147
+ it "generates the proper SQL code" do
148
+ expected_sql = <<~SQL.squish
122
149
  INSERT INTO #{PgSearch::Document.quoted_table_name} (searchable_type, searchable_id, content, created_at, updated_at)
123
150
  SELECT #{connection.quote(model.name)} AS searchable_type,
124
151
  #{model.quoted_table_name}.id AS searchable_id,
@@ -133,7 +160,7 @@ describe PgSearch::Multisearch do
133
160
  statements = []
134
161
  allow(connection).to receive(:execute) { |sql| statements << sql.strip }
135
162
 
136
- PgSearch::Multisearch.rebuild(model)
163
+ described_class.rebuild(model)
137
164
 
138
165
  expect(statements).to include(expected_sql.strip)
139
166
  end
@@ -144,8 +171,8 @@ describe PgSearch::Multisearch do
144
171
  model.multisearchable against: %i[title content]
145
172
  end
146
173
 
147
- it "should generate the proper SQL code" do
148
- expected_sql = <<-SQL.strip_heredoc
174
+ it "generates the proper SQL code" do
175
+ expected_sql = <<~SQL.squish
149
176
  INSERT INTO #{PgSearch::Document.quoted_table_name} (searchable_type, searchable_id, content, created_at, updated_at)
150
177
  SELECT #{connection.quote(model.name)} AS searchable_type,
151
178
  #{model.quoted_table_name}.id AS searchable_id,
@@ -160,7 +187,7 @@ describe PgSearch::Multisearch do
160
187
  statements = []
161
188
  allow(connection).to receive(:execute) { |sql| statements << sql.strip }
162
189
 
163
- PgSearch::Multisearch.rebuild(model)
190
+ described_class.rebuild(model)
164
191
 
165
192
  expect(statements).to include(expected_sql.strip)
166
193
  end
@@ -168,3 +195,4 @@ describe PgSearch::Multisearch do
168
195
  end
169
196
  end
170
197
  end
198
+ # standard:enable RSpec/NestedGroups