pg_search 2.1.2 → 2.3.6

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 (66) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +1 -0
  3. data/.editorconfig +10 -0
  4. data/.github/dependabot.yml +11 -0
  5. data/.github/workflows/ci.yml +75 -0
  6. data/.jrubyrc +1 -0
  7. data/.rubocop.yml +95 -10
  8. data/.travis.yml +26 -48
  9. data/CHANGELOG.md +179 -112
  10. data/CODE_OF_CONDUCT.md +76 -0
  11. data/CONTRIBUTING.md +5 -3
  12. data/Gemfile +6 -4
  13. data/LICENSE +1 -1
  14. data/README.md +307 -198
  15. data/Rakefile +7 -3
  16. data/lib/pg_search/configuration/association.rb +2 -0
  17. data/lib/pg_search/configuration/column.rb +2 -0
  18. data/lib/pg_search/configuration/foreign_column.rb +2 -0
  19. data/lib/pg_search/configuration.rb +20 -6
  20. data/lib/pg_search/document.rb +7 -5
  21. data/lib/pg_search/features/dmetaphone.rb +7 -7
  22. data/lib/pg_search/features/feature.rb +4 -2
  23. data/lib/pg_search/features/trigram.rb +31 -5
  24. data/lib/pg_search/features/tsearch.rb +18 -14
  25. data/lib/pg_search/features.rb +2 -0
  26. data/lib/pg_search/migration/dmetaphone_generator.rb +3 -1
  27. data/lib/pg_search/migration/generator.rb +4 -2
  28. data/lib/pg_search/migration/multisearch_generator.rb +2 -1
  29. data/lib/pg_search/migration/templates/add_pg_search_dmetaphone_support_functions.rb.erb +6 -6
  30. data/lib/pg_search/migration/templates/create_pg_search_documents.rb.erb +3 -3
  31. data/lib/pg_search/model.rb +57 -0
  32. data/lib/pg_search/multisearch/rebuilder.rb +14 -6
  33. data/lib/pg_search/multisearch.rb +23 -6
  34. data/lib/pg_search/multisearchable.rb +10 -6
  35. data/lib/pg_search/normalizer.rb +2 -0
  36. data/lib/pg_search/railtie.rb +2 -0
  37. data/lib/pg_search/scope_options.rb +26 -49
  38. data/lib/pg_search/tasks.rb +5 -1
  39. data/lib/pg_search/version.rb +3 -1
  40. data/lib/pg_search.rb +17 -55
  41. data/pg_search.gemspec +19 -11
  42. data/spec/.rubocop.yml +2 -2
  43. data/spec/integration/.rubocop.yml +11 -0
  44. data/spec/integration/associations_spec.rb +125 -162
  45. data/spec/integration/deprecation_spec.rb +33 -0
  46. data/spec/integration/pagination_spec.rb +10 -8
  47. data/spec/integration/pg_search_spec.rb +359 -306
  48. data/spec/integration/single_table_inheritance_spec.rb +18 -17
  49. data/spec/lib/pg_search/configuration/association_spec.rb +17 -13
  50. data/spec/lib/pg_search/configuration/column_spec.rb +2 -0
  51. data/spec/lib/pg_search/configuration/foreign_column_spec.rb +6 -4
  52. data/spec/lib/pg_search/features/dmetaphone_spec.rb +6 -4
  53. data/spec/lib/pg_search/features/trigram_spec.rb +51 -20
  54. data/spec/lib/pg_search/features/tsearch_spec.rb +29 -21
  55. data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +151 -85
  56. data/spec/lib/pg_search/multisearch_spec.rb +67 -37
  57. data/spec/lib/pg_search/multisearchable_spec.rb +217 -123
  58. data/spec/lib/pg_search/normalizer_spec.rb +14 -10
  59. data/spec/lib/pg_search_spec.rb +102 -89
  60. data/spec/spec_helper.rb +25 -6
  61. data/spec/support/database.rb +19 -21
  62. data/spec/support/with_model.rb +2 -0
  63. metadata +106 -29
  64. data/.autotest +0 -5
  65. data/.rubocop_todo.yml +0 -163
  66. data/Guardfile +0 -6
@@ -1,36 +1,66 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
5
+ # rubocop:disable RSpec/NestedGroups
3
6
  describe PgSearch::Multisearchable do
4
- with_table "pg_search_documents", {}, &DOCUMENTS_SCHEMA
7
+ with_table "pg_search_documents", &DOCUMENTS_SCHEMA
5
8
 
6
9
  describe "a model that is multisearchable" do
7
10
  with_model :ModelThatIsMultisearchable do
8
11
  model do
9
- include PgSearch
12
+ include PgSearch::Model
10
13
  multisearchable
11
14
  end
12
15
  end
13
16
 
17
+ with_model :MultisearchableParent do
18
+ table do |t|
19
+ t.string :secret
20
+ end
21
+
22
+ model do
23
+ include PgSearch::Model
24
+ multisearchable
25
+
26
+ has_many :multisearchable_children, dependent: :destroy
27
+ end
28
+ end
29
+
30
+ with_model :MultisearchableChild do
31
+ table do |t|
32
+ t.belongs_to :multisearchable_parent, index: false
33
+ end
34
+
35
+ model do
36
+ belongs_to :multisearchable_parent
37
+
38
+ after_destroy do
39
+ multisearchable_parent.update_attribute(:secret, rand(1000).to_s) # rubocop:disable Rails/SkipsModelValidations
40
+ end
41
+ end
42
+ end
43
+
14
44
  describe "callbacks" do
15
45
  describe "after_create" do
16
46
  let(:record) { ModelThatIsMultisearchable.new }
17
47
 
18
48
  describe "saving the record" do
19
- it "should create a PgSearch::Document record" do
49
+ it "creates a PgSearch::Document record" do
20
50
  expect { record.save! }.to change(PgSearch::Document, :count).by(1)
21
51
  end
22
52
 
23
53
  context "with multisearch disabled" do
24
54
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
25
55
 
26
- it "should not create a PgSearch::Document record" do
56
+ it "does not create a PgSearch::Document record" do
27
57
  expect { record.save! }.not_to change(PgSearch::Document, :count)
28
58
  end
29
59
  end
30
60
  end
31
61
 
32
62
  describe "the document" do
33
- it "should be associated to the record" do
63
+ it "is associated to the record" do
34
64
  record.save!
35
65
  newest_pg_search_document = PgSearch::Document.last
36
66
  expect(record.pg_search_document).to eq(newest_pg_search_document)
@@ -47,20 +77,22 @@ describe PgSearch::Multisearchable do
47
77
 
48
78
  describe "saving the record" do
49
79
  it "calls save on the pg_search_document" do
50
- expect(record.pg_search_document).to receive(:save)
80
+ allow(record.pg_search_document).to receive(:save)
51
81
  record.save!
82
+ expect(record.pg_search_document).to have_received(:save)
52
83
  end
53
84
 
54
- it "should not create a PgSearch::Document record" do
85
+ it "does not create a PgSearch::Document record" do
55
86
  expect { record.save! }.not_to change(PgSearch::Document, :count)
56
87
  end
57
88
 
58
89
  context "with multisearch disabled" do
59
90
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
60
91
 
61
- it "should not create a PgSearch::Document record" do
62
- expect(record.pg_search_document).not_to receive(:save)
92
+ it "does not create a PgSearch::Document record" do
93
+ allow(record.pg_search_document).to receive(:save)
63
94
  expect { record.save! }.not_to change(PgSearch::Document, :count)
95
+ expect(record.pg_search_document).not_to have_received(:save)
64
96
  end
65
97
  end
66
98
  end
@@ -70,14 +102,14 @@ describe PgSearch::Multisearchable do
70
102
  before { record.pg_search_document = nil }
71
103
 
72
104
  describe "saving the record" do
73
- it "should create a PgSearch::Document record" do
105
+ it "creates a PgSearch::Document record" do
74
106
  expect { record.save! }.to change(PgSearch::Document, :count).by(1)
75
107
  end
76
108
 
77
109
  context "with multisearch disabled" do
78
110
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
79
111
 
80
- it "should not create a PgSearch::Document record" do
112
+ it "does not create a PgSearch::Document record" do
81
113
  expect { record.save! }.not_to change(PgSearch::Document, :count)
82
114
  end
83
115
  end
@@ -86,84 +118,114 @@ describe PgSearch::Multisearchable do
86
118
  end
87
119
 
88
120
  describe "after_destroy" do
89
- it "should remove its document" do
121
+ it "removes its document" do
90
122
  record = ModelThatIsMultisearchable.create!
91
123
  document = record.pg_search_document
92
124
  expect { record.destroy }.to change(PgSearch::Document, :count).by(-1)
93
125
  expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
94
126
  end
127
+
128
+ it "removes its document in case of complex associations" do
129
+ parent = MultisearchableParent.create!
130
+
131
+ MultisearchableChild.create!(multisearchable_parent: parent)
132
+ MultisearchableChild.create!(multisearchable_parent: parent)
133
+
134
+ document = parent.pg_search_document
135
+
136
+ expect { parent.destroy }.to change(PgSearch::Document, :count).by(-1)
137
+ expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
138
+ end
95
139
  end
96
140
  end
97
141
 
98
142
  describe "populating the searchable text" do
99
- let(:record) { ModelThatIsMultisearchable.new }
100
143
  subject { record }
101
144
 
145
+ let(:record) { ModelThatIsMultisearchable.new }
146
+
102
147
  before do
103
148
  ModelThatIsMultisearchable.multisearchable(multisearchable_options)
104
149
  end
105
150
 
106
151
  context "when searching against a single column" do
107
- let(:multisearchable_options) { {:against => :some_content} }
152
+ let(:multisearchable_options) { { against: :some_content } }
108
153
  let(:text) { "foo bar" }
154
+
109
155
  before do
110
- allow(record).to receive(:some_content) { text }
156
+ without_partial_double_verification do
157
+ allow(record).to receive(:some_content) { text }
158
+ end
111
159
  record.save
112
160
  end
113
161
 
114
162
  describe '#content' do
115
163
  subject { super().pg_search_document.content }
164
+
116
165
  it { is_expected.to eq(text) }
117
166
  end
118
167
  end
119
168
 
120
169
  context "when searching against multiple columns" do
121
- let(:multisearchable_options) { {:against => %i[attr1 attr2]} }
170
+ let(:multisearchable_options) { { against: %i[attr_1 attr_2] } }
171
+
122
172
  before do
123
- allow(record).to receive(:attr1) { '1' }
124
- allow(record).to receive(:attr2) { '2' }
173
+ without_partial_double_verification do
174
+ allow(record).to receive(:attr_1).and_return('1')
175
+ allow(record).to receive(:attr_2).and_return('2')
176
+ end
125
177
  record.save
126
178
  end
127
179
 
128
180
  describe '#content' do
129
181
  subject { super().pg_search_document.content }
182
+
130
183
  it { is_expected.to eq("1 2") }
131
184
  end
132
185
  end
133
186
  end
134
187
 
135
188
  describe "populating the searchable attributes" do
136
- let(:record) { ModelThatIsMultisearchable.new }
137
189
  subject { record }
138
190
 
191
+ let(:record) { ModelThatIsMultisearchable.new }
192
+
139
193
  before do
140
194
  ModelThatIsMultisearchable.multisearchable(multisearchable_options)
141
195
  end
142
196
 
143
197
  context "when searching against a single column" do
144
- let(:multisearchable_options) { {:against => :some_content} }
198
+ let(:multisearchable_options) { { against: :some_content } }
145
199
  let(:text) { "foo bar" }
200
+
146
201
  before do
147
- allow(record).to receive(:some_content) { text }
202
+ without_partial_double_verification do
203
+ allow(record).to receive(:some_content) { text }
204
+ end
148
205
  record.save
149
206
  end
150
207
 
151
208
  describe '#content' do
152
209
  subject { super().pg_search_document.content }
210
+
153
211
  it { is_expected.to eq(text) }
154
212
  end
155
213
  end
156
214
 
157
215
  context "when searching against multiple columns" do
158
- let(:multisearchable_options) { {:against => %i[attr1 attr2]} }
216
+ let(:multisearchable_options) { { against: %i[attr_1 attr_2] } }
217
+
159
218
  before do
160
- allow(record).to receive(:attr1) { '1' }
161
- allow(record).to receive(:attr2) { '2' }
219
+ without_partial_double_verification do
220
+ allow(record).to receive(:attr_1).and_return('1')
221
+ allow(record).to receive(:attr_2).and_return('2')
222
+ end
162
223
  record.save
163
224
  end
164
225
 
165
226
  describe '#content' do
166
227
  subject { super().pg_search_document.content }
228
+
167
229
  it { is_expected.to eq("1 2") }
168
230
  end
169
231
  end
@@ -171,7 +233,7 @@ describe PgSearch::Multisearchable do
171
233
  context "with additional_attributes" do
172
234
  let(:multisearchable_options) do
173
235
  {
174
- :additional_attributes => lambda do |record|
236
+ additional_attributes: lambda do |record|
175
237
  { foo: record.bar }
176
238
  end
177
239
  }
@@ -179,18 +241,21 @@ describe PgSearch::Multisearchable do
179
241
  let(:text) { "foo bar" }
180
242
 
181
243
  it "sets the attributes" do
182
- allow(record).to receive(:bar).and_return(text)
183
- expect(record)
184
- .to receive(:create_pg_search_document)
185
- .with(content: '', foo: text)
186
- record.save
244
+ without_partial_double_verification do
245
+ allow(record).to receive(:bar).and_return(text)
246
+ allow(record).to receive(:create_pg_search_document)
247
+ record.save
248
+ expect(record)
249
+ .to have_received(:create_pg_search_document)
250
+ .with(content: '', foo: text)
251
+ end
187
252
  end
188
253
  end
189
254
 
190
255
  context "when selectively updating" do
191
256
  let(:multisearchable_options) do
192
257
  {
193
- :update_if => lambda do |record|
258
+ update_if: lambda do |record|
194
259
  record.bar?
195
260
  end
196
261
  }
@@ -198,39 +263,46 @@ describe PgSearch::Multisearchable do
198
263
  let(:text) { "foo bar" }
199
264
 
200
265
  it "creates the document" do
201
- allow(record).to receive(:bar?).and_return(false)
202
- expect(record)
203
- .to receive(:create_pg_search_document)
204
- .with(content: '')
205
- record.save
266
+ without_partial_double_verification do
267
+ allow(record).to receive(:bar?).and_return(false)
268
+ allow(record).to receive(:create_pg_search_document)
269
+ record.save
270
+ expect(record)
271
+ .to have_received(:create_pg_search_document)
272
+ .with(content: '')
273
+ end
206
274
  end
207
275
 
208
- context "the document is created" do
276
+ context "when the document is created" do
209
277
  before { record.save }
210
278
 
211
- context "update_if returns false" do
279
+ context "when update_if returns false" do
212
280
  before do
213
- allow(record).to receive(:bar?).and_return(false)
281
+ without_partial_double_verification do
282
+ allow(record).to receive(:bar?).and_return(false)
283
+ end
214
284
  end
215
285
 
216
286
  it "does not update the document" do
217
- expect_any_instance_of(PgSearch::Document)
218
- .to_not receive(:update_attributes)
219
-
220
- record.save
287
+ without_partial_double_verification do
288
+ allow(record.pg_search_document).to receive(:update)
289
+ record.save
290
+ expect(record.pg_search_document).not_to have_received(:update)
291
+ end
221
292
  end
222
293
  end
223
294
 
224
- context "update_if returns true" do
295
+ context "when update_if returns true" do
225
296
  before do
226
- allow(record).to receive(:bar?).and_return(true)
297
+ without_partial_double_verification do
298
+ allow(record).to receive(:bar?).and_return(true)
299
+ end
227
300
  end
228
301
 
229
302
  it "updates the document" do
230
- expect_any_instance_of(PgSearch::Document)
231
- .to receive(:update_attributes)
232
-
303
+ allow(record.pg_search_document).to receive(:update)
233
304
  record.save
305
+ expect(record.pg_search_document).to have_received(:update)
234
306
  end
235
307
  end
236
308
  end
@@ -246,8 +318,8 @@ describe PgSearch::Multisearchable do
246
318
  end
247
319
 
248
320
  model do
249
- include PgSearch
250
- multisearchable :if => ->(record) { record.multisearchable? }
321
+ include PgSearch::Model
322
+ multisearchable if: ->(record) { record.multisearchable? }
251
323
  end
252
324
  end
253
325
 
@@ -255,25 +327,25 @@ describe PgSearch::Multisearchable do
255
327
  describe "after_create" do
256
328
  describe "saving the record" do
257
329
  context "when the condition is true" do
258
- let(:record) { ModelThatIsMultisearchable.new(:multisearchable => true) }
330
+ let(:record) { ModelThatIsMultisearchable.new(multisearchable: true) }
259
331
 
260
- it "should create a PgSearch::Document record" do
332
+ it "creates a PgSearch::Document record" do
261
333
  expect { record.save! }.to change(PgSearch::Document, :count).by(1)
262
334
  end
263
335
 
264
336
  context "with multisearch disabled" do
265
337
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
266
338
 
267
- it "should not create a PgSearch::Document record" do
339
+ it "does not create a PgSearch::Document record" do
268
340
  expect { record.save! }.not_to change(PgSearch::Document, :count)
269
341
  end
270
342
  end
271
343
  end
272
344
 
273
345
  context "when the condition is false" do
274
- let(:record) { ModelThatIsMultisearchable.new(:multisearchable => false) }
346
+ let(:record) { ModelThatIsMultisearchable.new(multisearchable: false) }
275
347
 
276
- it "should not create a PgSearch::Document record" do
348
+ it "does not create a PgSearch::Document record" do
277
349
  expect { record.save! }.not_to change(PgSearch::Document, :count)
278
350
  end
279
351
  end
@@ -281,7 +353,7 @@ describe PgSearch::Multisearchable do
281
353
  end
282
354
 
283
355
  describe "after_update" do
284
- let(:record) { ModelThatIsMultisearchable.create!(:multisearchable => true) }
356
+ let(:record) { ModelThatIsMultisearchable.create!(multisearchable: true) }
285
357
 
286
358
  context "when the document is present" do
287
359
  before { expect(record.pg_search_document).to be_present }
@@ -289,11 +361,12 @@ describe PgSearch::Multisearchable do
289
361
  describe "saving the record" do
290
362
  context "when the condition is true" do
291
363
  it "calls save on the pg_search_document" do
292
- expect(record.pg_search_document).to receive(:save)
364
+ allow(record.pg_search_document).to receive(:save)
293
365
  record.save!
366
+ expect(record.pg_search_document).to have_received(:save)
294
367
  end
295
368
 
296
- it "should not create a PgSearch::Document record" do
369
+ it "does not create a PgSearch::Document record" do
297
370
  expect { record.save! }.not_to change(PgSearch::Document, :count)
298
371
  end
299
372
  end
@@ -302,11 +375,12 @@ describe PgSearch::Multisearchable do
302
375
  before { record.multisearchable = false }
303
376
 
304
377
  it "calls destroy on the pg_search_document" do
305
- expect(record.pg_search_document).to receive(:destroy)
378
+ allow(record.pg_search_document).to receive(:destroy)
306
379
  record.save!
380
+ expect(record.pg_search_document).to have_received(:destroy)
307
381
  end
308
382
 
309
- it "should remove its document" do
383
+ it "removes its document" do
310
384
  document = record.pg_search_document
311
385
  expect { record.save! }.to change(PgSearch::Document, :count).by(-1)
312
386
  expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
@@ -318,9 +392,10 @@ describe PgSearch::Multisearchable do
318
392
  allow(PgSearch).to receive(:multisearch_enabled?).and_return(false)
319
393
  end
320
394
 
321
- it "should not create a PgSearch::Document record" do
322
- expect(record.pg_search_document).not_to receive(:save)
395
+ it "does not create a PgSearch::Document record" do
396
+ allow(record.pg_search_document).to receive(:save)
323
397
  expect { record.save! }.not_to change(PgSearch::Document, :count)
398
+ expect(record.pg_search_document).not_to have_received(:save)
324
399
  end
325
400
  end
326
401
  end
@@ -331,14 +406,14 @@ describe PgSearch::Multisearchable do
331
406
 
332
407
  describe "saving the record" do
333
408
  context "when the condition is true" do
334
- it "should create a PgSearch::Document record" do
409
+ it "creates a PgSearch::Document record" do
335
410
  expect { record.save! }.to change(PgSearch::Document, :count).by(1)
336
411
  end
337
412
 
338
413
  context "with multisearch disabled" do
339
414
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
340
415
 
341
- it "should not create a PgSearch::Document record" do
416
+ it "does not create a PgSearch::Document record" do
342
417
  expect { record.save! }.not_to change(PgSearch::Document, :count)
343
418
  end
344
419
  end
@@ -347,7 +422,7 @@ describe PgSearch::Multisearchable do
347
422
  context "when the condition is false" do
348
423
  before { record.multisearchable = false }
349
424
 
350
- it "should not create a PgSearch::Document record" do
425
+ it "does not create a PgSearch::Document record" do
351
426
  expect { record.save! }.not_to change(PgSearch::Document, :count)
352
427
  end
353
428
  end
@@ -356,9 +431,9 @@ describe PgSearch::Multisearchable do
356
431
  end
357
432
 
358
433
  describe "after_destroy" do
359
- let(:record) { ModelThatIsMultisearchable.create!(:multisearchable => true) }
434
+ let(:record) { ModelThatIsMultisearchable.create!(multisearchable: true) }
360
435
 
361
- it "should remove its document" do
436
+ it "removes its document" do
362
437
  document = record.pg_search_document
363
438
  expect { record.destroy }.to change(PgSearch::Document, :count).by(-1)
364
439
  expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
@@ -374,8 +449,8 @@ describe PgSearch::Multisearchable do
374
449
  end
375
450
 
376
451
  model do
377
- include PgSearch
378
- multisearchable :unless => ->(record) { record.not_multisearchable? }
452
+ include PgSearch::Model
453
+ multisearchable unless: ->(record) { record.not_multisearchable? }
379
454
  end
380
455
  end
381
456
 
@@ -383,25 +458,25 @@ describe PgSearch::Multisearchable do
383
458
  describe "after_create" do
384
459
  describe "saving the record" do
385
460
  context "when the condition is false" do
386
- let(:record) { ModelThatIsMultisearchable.new(:not_multisearchable => false) }
461
+ let(:record) { ModelThatIsMultisearchable.new(not_multisearchable: false) }
387
462
 
388
- it "should create a PgSearch::Document record" do
463
+ it "creates a PgSearch::Document record" do
389
464
  expect { record.save! }.to change(PgSearch::Document, :count).by(1)
390
465
  end
391
466
 
392
467
  context "with multisearch disabled" do
393
468
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
394
469
 
395
- it "should not create a PgSearch::Document record" do
470
+ it "does not create a PgSearch::Document record" do
396
471
  expect { record.save! }.not_to change(PgSearch::Document, :count)
397
472
  end
398
473
  end
399
474
  end
400
475
 
401
476
  context "when the condition is true" do
402
- let(:record) { ModelThatIsMultisearchable.new(:not_multisearchable => true) }
477
+ let(:record) { ModelThatIsMultisearchable.new(not_multisearchable: true) }
403
478
 
404
- it "should not create a PgSearch::Document record" do
479
+ it "does not create a PgSearch::Document record" do
405
480
  expect { record.save! }.not_to change(PgSearch::Document, :count)
406
481
  end
407
482
  end
@@ -409,7 +484,7 @@ describe PgSearch::Multisearchable do
409
484
  end
410
485
 
411
486
  describe "after_update" do
412
- let!(:record) { ModelThatIsMultisearchable.create!(:not_multisearchable => false) }
487
+ let!(:record) { ModelThatIsMultisearchable.create!(not_multisearchable: false) }
413
488
 
414
489
  context "when the document is present" do
415
490
  before { expect(record.pg_search_document).to be_present }
@@ -417,21 +492,26 @@ describe PgSearch::Multisearchable do
417
492
  describe "saving the record" do
418
493
  context "when the condition is false" do
419
494
  it "calls save on the pg_search_document" do
420
- expect(record.pg_search_document).to receive(:save)
495
+ allow(record.pg_search_document).to receive(:save)
421
496
  record.save!
497
+ expect(record.pg_search_document).to have_received(:save)
422
498
  end
423
499
 
424
- it "should not create a PgSearch::Document record" do
500
+ it "does not create a PgSearch::Document record" do
425
501
  expect { record.save! }.not_to change(PgSearch::Document, :count)
426
502
  end
427
503
 
428
504
  context "with multisearch disabled" do
429
505
  before do
430
506
  allow(PgSearch).to receive(:multisearch_enabled?).and_return(false)
431
- expect(record.pg_search_document).not_to receive(:save)
507
+ allow(record.pg_search_document).to receive(:save)
508
+ end
509
+
510
+ it "does not call save on the document" do
511
+ expect(record.pg_search_document).not_to have_received(:save)
432
512
  end
433
513
 
434
- it "should not create a PgSearch::Document record" do
514
+ it "does not create a PgSearch::Document record" do
435
515
  expect { record.save! }.not_to change(PgSearch::Document, :count)
436
516
  end
437
517
  end
@@ -441,11 +521,12 @@ describe PgSearch::Multisearchable do
441
521
  before { record.not_multisearchable = true }
442
522
 
443
523
  it "calls destroy on the pg_search_document" do
444
- expect(record.pg_search_document).to receive(:destroy)
524
+ allow(record.pg_search_document).to receive(:destroy)
445
525
  record.save!
526
+ expect(record.pg_search_document).to have_received(:destroy)
446
527
  end
447
528
 
448
- it "should remove its document" do
529
+ it "removes its document" do
449
530
  document = record.pg_search_document
450
531
  expect { record.save! }.to change(PgSearch::Document, :count).by(-1)
451
532
  expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
@@ -459,7 +540,7 @@ describe PgSearch::Multisearchable do
459
540
 
460
541
  describe "saving the record" do
461
542
  context "when the condition is false" do
462
- it "should create a PgSearch::Document record" do
543
+ it "creates a PgSearch::Document record" do
463
544
  expect { record.save! }.to change(PgSearch::Document, :count).by(1)
464
545
  end
465
546
  end
@@ -467,7 +548,7 @@ describe PgSearch::Multisearchable do
467
548
  context "when the condition is true" do
468
549
  before { record.not_multisearchable = true }
469
550
 
470
- it "should not create a PgSearch::Document record" do
551
+ it "does not create a PgSearch::Document record" do
471
552
  expect { record.save! }.not_to change(PgSearch::Document, :count)
472
553
  end
473
554
  end
@@ -475,7 +556,7 @@ describe PgSearch::Multisearchable do
475
556
  context "with multisearch disabled" do
476
557
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
477
558
 
478
- it "should not create a PgSearch::Document record" do
559
+ it "does not create a PgSearch::Document record" do
479
560
  expect { record.save! }.not_to change(PgSearch::Document, :count)
480
561
  end
481
562
  end
@@ -484,7 +565,7 @@ describe PgSearch::Multisearchable do
484
565
  end
485
566
 
486
567
  describe "after_destroy" do
487
- it "should remove its document" do
568
+ it "removes its document" do
488
569
  record = ModelThatIsMultisearchable.create!
489
570
  document = record.pg_search_document
490
571
  expect { record.destroy }.to change(PgSearch::Document, :count).by(-1)
@@ -503,8 +584,8 @@ describe PgSearch::Multisearchable do
503
584
  end
504
585
 
505
586
  model do
506
- include PgSearch
507
- multisearchable :if => :multisearchable?
587
+ include PgSearch::Model
588
+ multisearchable if: :multisearchable?
508
589
  end
509
590
  end
510
591
 
@@ -512,25 +593,25 @@ describe PgSearch::Multisearchable do
512
593
  describe "after_create" do
513
594
  describe "saving the record" do
514
595
  context "when the condition is true" do
515
- let(:record) { ModelThatIsMultisearchable.new(:multisearchable => true) }
596
+ let(:record) { ModelThatIsMultisearchable.new(multisearchable: true) }
516
597
 
517
- it "should create a PgSearch::Document record" do
598
+ it "creates a PgSearch::Document record" do
518
599
  expect { record.save! }.to change(PgSearch::Document, :count).by(1)
519
600
  end
520
601
 
521
602
  context "with multisearch disabled" do
522
603
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
523
604
 
524
- it "should not create a PgSearch::Document record" do
605
+ it "does not create a PgSearch::Document record" do
525
606
  expect { record.save! }.not_to change(PgSearch::Document, :count)
526
607
  end
527
608
  end
528
609
  end
529
610
 
530
611
  context "when the condition is false" do
531
- let(:record) { ModelThatIsMultisearchable.new(:multisearchable => false) }
612
+ let(:record) { ModelThatIsMultisearchable.new(multisearchable: false) }
532
613
 
533
- it "should not create a PgSearch::Document record" do
614
+ it "does not create a PgSearch::Document record" do
534
615
  expect { record.save! }.not_to change(PgSearch::Document, :count)
535
616
  end
536
617
  end
@@ -538,7 +619,7 @@ describe PgSearch::Multisearchable do
538
619
  end
539
620
 
540
621
  describe "after_update" do
541
- let!(:record) { ModelThatIsMultisearchable.create!(:multisearchable => true) }
622
+ let!(:record) { ModelThatIsMultisearchable.create!(multisearchable: true) }
542
623
 
543
624
  context "when the document is present" do
544
625
  before { expect(record.pg_search_document).to be_present }
@@ -546,21 +627,26 @@ describe PgSearch::Multisearchable do
546
627
  describe "saving the record" do
547
628
  context "when the condition is true" do
548
629
  it "calls save on the pg_search_document" do
549
- expect(record.pg_search_document).to receive(:save)
630
+ allow(record.pg_search_document).to receive(:save)
550
631
  record.save!
632
+ expect(record.pg_search_document).to have_received(:save)
551
633
  end
552
634
 
553
- it "should not create a PgSearch::Document record" do
635
+ it "does not create a PgSearch::Document record" do
554
636
  expect { record.save! }.not_to change(PgSearch::Document, :count)
555
637
  end
556
638
 
557
639
  context "with multisearch disabled" do
558
640
  before do
559
641
  allow(PgSearch).to receive(:multisearch_enabled?).and_return(false)
560
- expect(record.pg_search_document).not_to receive(:save)
642
+ allow(record.pg_search_document).to receive(:save)
561
643
  end
562
644
 
563
- it "should not create a PgSearch::Document record" do
645
+ it "does not call save on the document" do
646
+ expect(record.pg_search_document).not_to have_received(:save)
647
+ end
648
+
649
+ it "does not create a PgSearch::Document record" do
564
650
  expect { record.save! }.not_to change(PgSearch::Document, :count)
565
651
  end
566
652
  end
@@ -570,11 +656,12 @@ describe PgSearch::Multisearchable do
570
656
  before { record.multisearchable = false }
571
657
 
572
658
  it "calls destroy on the pg_search_document" do
573
- expect(record.pg_search_document).to receive(:destroy)
659
+ allow(record.pg_search_document).to receive(:destroy)
574
660
  record.save!
661
+ expect(record.pg_search_document).to have_received(:destroy)
575
662
  end
576
663
 
577
- it "should remove its document" do
664
+ it "removes its document" do
578
665
  document = record.pg_search_document
579
666
  expect { record.save! }.to change(PgSearch::Document, :count).by(-1)
580
667
  expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
@@ -591,7 +678,7 @@ describe PgSearch::Multisearchable do
591
678
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(true) }
592
679
 
593
680
  context "when the condition is true" do
594
- it "should create a PgSearch::Document record" do
681
+ it "creates a PgSearch::Document record" do
595
682
  expect { record.save! }.to change(PgSearch::Document, :count).by(1)
596
683
  end
597
684
  end
@@ -599,7 +686,7 @@ describe PgSearch::Multisearchable do
599
686
  context "when the condition is false" do
600
687
  before { record.multisearchable = false }
601
688
 
602
- it "should not create a PgSearch::Document record" do
689
+ it "does not create a PgSearch::Document record" do
603
690
  expect { record.save! }.not_to change(PgSearch::Document, :count)
604
691
  end
605
692
  end
@@ -608,7 +695,7 @@ describe PgSearch::Multisearchable do
608
695
  context "with multisearch disabled" do
609
696
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
610
697
 
611
- it "should not create a PgSearch::Document record" do
698
+ it "does not create a PgSearch::Document record" do
612
699
  expect { record.save! }.not_to change(PgSearch::Document, :count)
613
700
  end
614
701
  end
@@ -617,9 +704,9 @@ describe PgSearch::Multisearchable do
617
704
  end
618
705
 
619
706
  describe "after_destroy" do
620
- let(:record) { ModelThatIsMultisearchable.create!(:multisearchable => true) }
707
+ let(:record) { ModelThatIsMultisearchable.create!(multisearchable: true) }
621
708
 
622
- it "should remove its document" do
709
+ it "removes its document" do
623
710
  document = record.pg_search_document
624
711
  expect { record.destroy }.to change(PgSearch::Document, :count).by(-1)
625
712
  expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
@@ -635,8 +722,8 @@ describe PgSearch::Multisearchable do
635
722
  end
636
723
 
637
724
  model do
638
- include PgSearch
639
- multisearchable :unless => :not_multisearchable?
725
+ include PgSearch::Model
726
+ multisearchable unless: :not_multisearchable?
640
727
  end
641
728
  end
642
729
 
@@ -644,24 +731,24 @@ describe PgSearch::Multisearchable do
644
731
  describe "after_create" do
645
732
  describe "saving the record" do
646
733
  context "when the condition is true" do
647
- let(:record) { ModelThatIsMultisearchable.new(:not_multisearchable => true) }
734
+ let(:record) { ModelThatIsMultisearchable.new(not_multisearchable: true) }
648
735
 
649
- it "should not create a PgSearch::Document record" do
736
+ it "does not create a PgSearch::Document record" do
650
737
  expect { record.save! }.not_to change(PgSearch::Document, :count)
651
738
  end
652
739
  end
653
740
 
654
741
  context "when the condition is false" do
655
- let(:record) { ModelThatIsMultisearchable.new(:not_multisearchable => false) }
742
+ let(:record) { ModelThatIsMultisearchable.new(not_multisearchable: false) }
656
743
 
657
- it "should create a PgSearch::Document record" do
744
+ it "creates a PgSearch::Document record" do
658
745
  expect { record.save! }.to change(PgSearch::Document, :count).by(1)
659
746
  end
660
747
 
661
748
  context "with multisearch disabled" do
662
749
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
663
750
 
664
- it "should not create a PgSearch::Document record" do
751
+ it "does not create a PgSearch::Document record" do
665
752
  expect { record.save! }.not_to change(PgSearch::Document, :count)
666
753
  end
667
754
  end
@@ -670,7 +757,7 @@ describe PgSearch::Multisearchable do
670
757
  end
671
758
 
672
759
  describe "after_update" do
673
- let!(:record) { ModelThatIsMultisearchable.create!(:not_multisearchable => false) }
760
+ let!(:record) { ModelThatIsMultisearchable.create!(not_multisearchable: false) }
674
761
 
675
762
  context "when the document is present" do
676
763
  before { expect(record.pg_search_document).to be_present }
@@ -680,11 +767,12 @@ describe PgSearch::Multisearchable do
680
767
  before { record.not_multisearchable = true }
681
768
 
682
769
  it "calls destroy on the pg_search_document" do
683
- expect(record.pg_search_document).to receive(:destroy)
770
+ allow(record.pg_search_document).to receive(:destroy)
684
771
  record.save!
772
+ expect(record.pg_search_document).to have_received(:destroy)
685
773
  end
686
774
 
687
- it "should remove its document" do
775
+ it "removes its document" do
688
776
  document = record.pg_search_document
689
777
  expect { record.save! }.to change(PgSearch::Document, :count).by(-1)
690
778
  expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
@@ -693,21 +781,26 @@ describe PgSearch::Multisearchable do
693
781
 
694
782
  context "when the condition is false" do
695
783
  it "calls save on the pg_search_document" do
696
- expect(record.pg_search_document).to receive(:save)
784
+ allow(record.pg_search_document).to receive(:save)
697
785
  record.save!
786
+ expect(record.pg_search_document).to have_received(:save)
698
787
  end
699
788
 
700
- it "should not create a PgSearch::Document record" do
789
+ it "does not create a PgSearch::Document record" do
701
790
  expect { record.save! }.not_to change(PgSearch::Document, :count)
702
791
  end
703
792
 
704
793
  context "with multisearch disabled" do
705
794
  before do
706
795
  allow(PgSearch).to receive(:multisearch_enabled?).and_return(false)
707
- expect(record.pg_search_document).not_to receive(:save)
796
+ allow(record.pg_search_document).to receive(:save)
797
+ end
798
+
799
+ it "does not call save on the document" do
800
+ expect(record.pg_search_document).not_to have_received(:save)
708
801
  end
709
802
 
710
- it "should not create a PgSearch::Document record" do
803
+ it "does not create a PgSearch::Document record" do
711
804
  expect { record.save! }.not_to change(PgSearch::Document, :count)
712
805
  end
713
806
  end
@@ -725,20 +818,20 @@ describe PgSearch::Multisearchable do
725
818
  context "when the condition is true" do
726
819
  before { record.not_multisearchable = true }
727
820
 
728
- it "should not create a PgSearch::Document record" do
821
+ it "does not create a PgSearch::Document record" do
729
822
  expect { record.save! }.not_to change(PgSearch::Document, :count)
730
823
  end
731
824
  end
732
825
 
733
826
  context "when the condition is false" do
734
- it "should create a PgSearch::Document record" do
827
+ it "creates a PgSearch::Document record" do
735
828
  expect { record.save! }.to change(PgSearch::Document, :count).by(1)
736
829
  end
737
830
 
738
831
  context "with multisearch disabled" do
739
832
  before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
740
833
 
741
- it "should not create a PgSearch::Document record" do
834
+ it "does not create a PgSearch::Document record" do
742
835
  expect { record.save! }.not_to change(PgSearch::Document, :count)
743
836
  end
744
837
  end
@@ -749,9 +842,9 @@ describe PgSearch::Multisearchable do
749
842
  end
750
843
 
751
844
  describe "after_destroy" do
752
- let(:record) { ModelThatIsMultisearchable.create!(:not_multisearchable => false) }
845
+ let(:record) { ModelThatIsMultisearchable.create!(not_multisearchable: false) }
753
846
 
754
- it "should remove its document" do
847
+ it "removes its document" do
755
848
  document = record.pg_search_document
756
849
  expect { record.destroy }.to change(PgSearch::Document, :count).by(-1)
757
850
  expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
@@ -761,3 +854,4 @@ describe PgSearch::Multisearchable do
761
854
  end
762
855
  end
763
856
  end
857
+ # rubocop:enable RSpec/NestedGroups