pg_search 2.3.2 → 2.3.3

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