pg_search 2.3.6 → 2.3.8

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +47 -35
  3. data/.github/workflows/codeql.yml +87 -0
  4. data/.standard.yml +6 -0
  5. data/CHANGELOG.md +23 -0
  6. data/Gemfile +21 -6
  7. data/LICENSE +1 -1
  8. data/README.md +133 -114
  9. data/Rakefile +4 -13
  10. data/lib/pg_search/configuration/column.rb +6 -4
  11. data/lib/pg_search/configuration/foreign_column.rb +1 -1
  12. data/lib/pg_search/configuration.rb +11 -27
  13. data/lib/pg_search/document.rb +8 -8
  14. data/lib/pg_search/features/dmetaphone.rb +1 -1
  15. data/lib/pg_search/features/trigram.rb +4 -4
  16. data/lib/pg_search/features/tsearch.rb +23 -30
  17. data/lib/pg_search/migration/dmetaphone_generator.rb +2 -2
  18. data/lib/pg_search/migration/generator.rb +5 -5
  19. data/lib/pg_search/migration/multisearch_generator.rb +2 -2
  20. data/lib/pg_search/model.rb +12 -14
  21. data/lib/pg_search/multisearch/rebuilder.rb +4 -3
  22. data/lib/pg_search/multisearch.rb +4 -2
  23. data/lib/pg_search/multisearchable.rb +7 -7
  24. data/lib/pg_search/normalizer.rb +17 -7
  25. data/lib/pg_search/scope_options.rb +36 -8
  26. data/lib/pg_search/tasks.rb +2 -2
  27. data/lib/pg_search/version.rb +1 -1
  28. data/lib/pg_search.rb +3 -3
  29. data/pg_search.gemspec +16 -31
  30. data/spec/integration/associations_spec.rb +118 -106
  31. data/spec/integration/deprecation_spec.rb +12 -9
  32. data/spec/integration/pagination_spec.rb +1 -0
  33. data/spec/integration/pg_search_spec.rb +343 -298
  34. data/spec/integration/single_table_inheritance_spec.rb +7 -5
  35. data/spec/lib/pg_search/configuration/association_spec.rb +17 -15
  36. data/spec/lib/pg_search/configuration/column_spec.rb +13 -1
  37. data/spec/lib/pg_search/configuration/foreign_column_spec.rb +5 -4
  38. data/spec/lib/pg_search/features/dmetaphone_spec.rb +4 -4
  39. data/spec/lib/pg_search/features/trigram_spec.rb +32 -33
  40. data/spec/lib/pg_search/features/tsearch_spec.rb +57 -39
  41. data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +70 -20
  42. data/spec/lib/pg_search/multisearch_spec.rb +8 -8
  43. data/spec/lib/pg_search/multisearchable_spec.rb +34 -26
  44. data/spec/lib/pg_search/normalizer_spec.rb +11 -11
  45. data/spec/lib/pg_search_spec.rb +22 -18
  46. data/spec/spec_helper.rb +3 -18
  47. data/spec/support/database.rb +6 -6
  48. metadata +11 -219
  49. data/.codeclimate.yml +0 -17
  50. data/.rubocop.yml +0 -137
  51. data/.travis.yml +0 -37
  52. data/spec/.rubocop.yml +0 -14
  53. data/spec/integration/.rubocop.yml +0 -11
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- # rubocop:disable RSpec/NestedGroups
5
+ # standard:disable RSpec/NestedGroups
6
6
  describe "a pg_search_scope" do
7
7
  context "when joining to another table" do
8
8
  context "without an :against" do
@@ -20,23 +20,24 @@ describe "a pg_search_scope" do
20
20
 
21
21
  model do
22
22
  include PgSearch::Model
23
- belongs_to :another_model, class_name: 'AssociatedModel'
24
23
 
25
- pg_search_scope :with_another, associated_against: { another_model: :title }
24
+ belongs_to :another_model, class_name: "AssociatedModel"
25
+
26
+ pg_search_scope :with_another, associated_against: {another_model: :title}
26
27
  end
27
28
  end
28
29
 
29
30
  it "returns rows that match the query in the columns of the associated model only" do
30
- associated = AssociatedModel.create!(title: 'abcdef')
31
+ associated = AssociatedModel.create!(title: "abcdef")
31
32
  included = [
32
- ModelWithoutAgainst.create!(title: 'abcdef', another_model: associated),
33
- ModelWithoutAgainst.create!(title: 'ghijkl', another_model: associated)
33
+ ModelWithoutAgainst.create!(title: "abcdef", another_model: associated),
34
+ ModelWithoutAgainst.create!(title: "ghijkl", another_model: associated)
34
35
  ]
35
36
  excluded = [
36
- ModelWithoutAgainst.create!(title: 'abcdef')
37
+ ModelWithoutAgainst.create!(title: "abcdef")
37
38
  ]
38
39
 
39
- results = ModelWithoutAgainst.with_another('abcdef')
40
+ results = ModelWithoutAgainst.with_another("abcdef")
40
41
  expect(results.map(&:title)).to match_array(included.map(&:title))
41
42
  expect(results).not_to include(excluded)
42
43
  end
@@ -45,34 +46,35 @@ describe "a pg_search_scope" do
45
46
  context "via a belongs_to association" do
46
47
  with_model :AssociatedModel do
47
48
  table do |t|
48
- t.string 'title'
49
+ t.string "title"
49
50
  end
50
51
  end
51
52
 
52
53
  with_model :ModelWithBelongsTo do
53
54
  table do |t|
54
- t.string 'title'
55
- t.belongs_to 'another_model', index: false
55
+ t.string "title"
56
+ t.belongs_to "another_model", index: false
56
57
  end
57
58
 
58
59
  model do
59
60
  include PgSearch::Model
60
- belongs_to :another_model, class_name: 'AssociatedModel'
61
61
 
62
- pg_search_scope :with_associated, against: :title, associated_against: { another_model: :title }
62
+ belongs_to :another_model, class_name: "AssociatedModel"
63
+
64
+ pg_search_scope :with_associated, against: :title, associated_against: {another_model: :title}
63
65
  end
64
66
  end
65
67
 
66
68
  it "returns rows that match the query in either its own columns or the columns of the associated model" do
67
- associated = AssociatedModel.create!(title: 'abcdef')
69
+ associated = AssociatedModel.create!(title: "abcdef")
68
70
  included = [
69
- ModelWithBelongsTo.create!(title: 'ghijkl', another_model: associated),
70
- ModelWithBelongsTo.create!(title: 'abcdef')
71
+ ModelWithBelongsTo.create!(title: "ghijkl", another_model: associated),
72
+ ModelWithBelongsTo.create!(title: "abcdef")
71
73
  ]
72
- excluded = ModelWithBelongsTo.create!(title: 'mnopqr',
73
- another_model: AssociatedModel.create!(title: 'stuvwx'))
74
+ excluded = ModelWithBelongsTo.create!(title: "mnopqr",
75
+ another_model: AssociatedModel.create!(title: "stuvwx"))
74
76
 
75
- results = ModelWithBelongsTo.with_associated('abcdef')
77
+ results = ModelWithBelongsTo.with_associated("abcdef")
76
78
  expect(results.map(&:title)).to match_array(included.map(&:title))
77
79
  expect(results).not_to include(excluded)
78
80
  end
@@ -81,61 +83,62 @@ describe "a pg_search_scope" do
81
83
  context "via a has_many association" do
82
84
  with_model :AssociatedModelWithHasMany do
83
85
  table do |t|
84
- t.string 'title'
85
- t.belongs_to 'ModelWithHasMany', index: false
86
+ t.string "title"
87
+ t.belongs_to "ModelWithHasMany", index: false
86
88
  end
87
89
  end
88
90
 
89
91
  with_model :ModelWithHasMany do
90
92
  table do |t|
91
- t.string 'title'
93
+ t.string "title"
92
94
  end
93
95
 
94
96
  model do
95
97
  include PgSearch::Model
96
- has_many :other_models, class_name: 'AssociatedModelWithHasMany', foreign_key: 'ModelWithHasMany_id'
97
98
 
98
- pg_search_scope :with_associated, against: [:title], associated_against: { other_models: :title }
99
+ has_many :other_models, class_name: "AssociatedModelWithHasMany", foreign_key: "ModelWithHasMany_id"
100
+
101
+ pg_search_scope :with_associated, against: [:title], associated_against: {other_models: :title}
99
102
  end
100
103
  end
101
104
 
102
105
  it "returns rows that match the query in either its own columns or the columns of the associated model" do
103
106
  included = [
104
- ModelWithHasMany.create!(title: 'abcdef', other_models: [
105
- AssociatedModelWithHasMany.create!(title: 'foo'),
106
- AssociatedModelWithHasMany.create!(title: 'bar')
107
+ ModelWithHasMany.create!(title: "abcdef", other_models: [
108
+ AssociatedModelWithHasMany.create!(title: "foo"),
109
+ AssociatedModelWithHasMany.create!(title: "bar")
107
110
  ]),
108
- ModelWithHasMany.create!(title: 'ghijkl', other_models: [
109
- AssociatedModelWithHasMany.create!(title: 'foo bar'),
110
- AssociatedModelWithHasMany.create!(title: 'mnopqr')
111
+ ModelWithHasMany.create!(title: "ghijkl", other_models: [
112
+ AssociatedModelWithHasMany.create!(title: "foo bar"),
113
+ AssociatedModelWithHasMany.create!(title: "mnopqr")
111
114
  ]),
112
- ModelWithHasMany.create!(title: 'foo bar')
115
+ ModelWithHasMany.create!(title: "foo bar")
113
116
  ]
114
- excluded = ModelWithHasMany.create!(title: 'stuvwx', other_models: [
115
- AssociatedModelWithHasMany.create!(title: 'abcdef')
117
+ excluded = ModelWithHasMany.create!(title: "stuvwx", other_models: [
118
+ AssociatedModelWithHasMany.create!(title: "abcdef")
116
119
  ])
117
120
 
118
- results = ModelWithHasMany.with_associated('foo bar')
121
+ results = ModelWithHasMany.with_associated("foo bar")
119
122
  expect(results.map(&:title)).to match_array(included.map(&:title))
120
123
  expect(results).not_to include(excluded)
121
124
  end
122
125
 
123
126
  it "uses an unscoped relation of the associated model" do
124
- excluded = ModelWithHasMany.create!(title: 'abcdef', other_models: [
125
- AssociatedModelWithHasMany.create!(title: 'abcdef')
127
+ excluded = ModelWithHasMany.create!(title: "abcdef", other_models: [
128
+ AssociatedModelWithHasMany.create!(title: "abcdef")
126
129
  ])
127
130
 
128
131
  included = [
129
- ModelWithHasMany.create!(title: 'abcdef', other_models: [
130
- AssociatedModelWithHasMany.create!(title: 'foo'),
131
- AssociatedModelWithHasMany.create!(title: 'bar')
132
+ ModelWithHasMany.create!(title: "abcdef", other_models: [
133
+ AssociatedModelWithHasMany.create!(title: "foo"),
134
+ AssociatedModelWithHasMany.create!(title: "bar")
132
135
  ])
133
136
  ]
134
137
 
135
138
  results = ModelWithHasMany
136
- .limit(1)
137
- .order(Arel.sql("#{ModelWithHasMany.quoted_table_name}.id ASC"))
138
- .with_associated('foo bar')
139
+ .limit(1)
140
+ .order(Arel.sql("#{ModelWithHasMany.quoted_table_name}.id ASC"))
141
+ .with_associated("foo bar")
139
142
 
140
143
  expect(results.map(&:title)).to match_array(included.map(&:title))
141
144
  expect(results).not_to include(excluded)
@@ -146,36 +149,36 @@ describe "a pg_search_scope" do
146
149
  context "when on different tables" do
147
150
  with_model :FirstAssociatedModel do
148
151
  table do |t|
149
- t.string 'title'
150
- t.belongs_to 'ModelWithManyAssociations', index: false
152
+ t.string "title"
153
+ t.belongs_to "ModelWithManyAssociations", index: false
151
154
  end
152
155
  end
153
156
 
154
157
  with_model :SecondAssociatedModel do
155
158
  table do |t|
156
- t.string 'title'
159
+ t.string "title"
157
160
  end
158
161
  end
159
162
 
160
163
  with_model :ModelWithManyAssociations do
161
164
  table do |t|
162
- t.string 'title'
163
- t.belongs_to 'model_of_second_type', index: false
165
+ t.string "title"
166
+ t.belongs_to "model_of_second_type", index: false
164
167
  end
165
168
 
166
169
  model do
167
170
  include PgSearch::Model
168
171
 
169
172
  has_many :models_of_first_type,
170
- class_name: 'FirstAssociatedModel',
171
- foreign_key: 'ModelWithManyAssociations_id'
173
+ class_name: "FirstAssociatedModel",
174
+ foreign_key: "ModelWithManyAssociations_id"
172
175
 
173
176
  belongs_to :model_of_second_type,
174
- class_name: 'SecondAssociatedModel'
177
+ class_name: "SecondAssociatedModel"
175
178
 
176
179
  pg_search_scope :with_associated,
177
- against: :title,
178
- associated_against: { models_of_first_type: :title, model_of_second_type: :title }
180
+ against: :title,
181
+ associated_against: {models_of_first_type: :title, model_of_second_type: :title}
179
182
  end
180
183
  end
181
184
 
@@ -184,25 +187,25 @@ describe "a pg_search_scope" do
184
187
  unmatching_second = SecondAssociatedModel.create!(title: "uiop")
185
188
 
186
189
  included = [
187
- ModelWithManyAssociations.create!(title: 'abcdef', models_of_first_type: [
188
- FirstAssociatedModel.create!(title: 'foo'),
189
- FirstAssociatedModel.create!(title: 'bar')
190
+ ModelWithManyAssociations.create!(title: "abcdef", models_of_first_type: [
191
+ FirstAssociatedModel.create!(title: "foo"),
192
+ FirstAssociatedModel.create!(title: "bar")
190
193
  ]),
191
- ModelWithManyAssociations.create!(title: 'ghijkl', models_of_first_type: [
192
- FirstAssociatedModel.create!(title: 'foo bar'),
193
- FirstAssociatedModel.create!(title: 'mnopqr')
194
+ ModelWithManyAssociations.create!(title: "ghijkl", models_of_first_type: [
195
+ FirstAssociatedModel.create!(title: "foo bar"),
196
+ FirstAssociatedModel.create!(title: "mnopqr")
194
197
  ]),
195
- ModelWithManyAssociations.create!(title: 'foo bar'),
196
- ModelWithManyAssociations.create!(title: 'qwerty', model_of_second_type: matching_second)
198
+ ModelWithManyAssociations.create!(title: "foo bar"),
199
+ ModelWithManyAssociations.create!(title: "qwerty", model_of_second_type: matching_second)
197
200
  ]
198
201
  excluded = [
199
- ModelWithManyAssociations.create!(title: 'stuvwx', models_of_first_type: [
200
- FirstAssociatedModel.create!(title: 'abcdef')
202
+ ModelWithManyAssociations.create!(title: "stuvwx", models_of_first_type: [
203
+ FirstAssociatedModel.create!(title: "abcdef")
201
204
  ]),
202
- ModelWithManyAssociations.create!(title: 'qwerty', model_of_second_type: unmatching_second)
205
+ ModelWithManyAssociations.create!(title: "qwerty", model_of_second_type: unmatching_second)
203
206
  ]
204
207
 
205
- results = ModelWithManyAssociations.with_associated('foo bar')
208
+ results = ModelWithManyAssociations.with_associated("foo bar")
206
209
  expect(results.map(&:title)).to match_array(included.map(&:title))
207
210
  excluded.each { |object| expect(results).not_to include(object) }
208
211
  end
@@ -211,58 +214,58 @@ describe "a pg_search_scope" do
211
214
  context "when on the same table" do
212
215
  with_model :DoublyAssociatedModel do
213
216
  table do |t|
214
- t.string 'title'
215
- t.belongs_to 'ModelWithDoubleAssociation', index: false
216
- t.belongs_to 'ModelWithDoubleAssociation_again', index: false
217
+ t.string "title"
218
+ t.belongs_to "ModelWithDoubleAssociation", index: false
219
+ t.belongs_to "ModelWithDoubleAssociation_again", index: false
217
220
  end
218
221
  end
219
222
 
220
223
  with_model :ModelWithDoubleAssociation do
221
224
  table do |t|
222
- t.string 'title'
225
+ t.string "title"
223
226
  end
224
227
 
225
228
  model do
226
229
  include PgSearch::Model
227
230
 
228
231
  has_many :things,
229
- class_name: 'DoublyAssociatedModel',
230
- foreign_key: 'ModelWithDoubleAssociation_id'
232
+ class_name: "DoublyAssociatedModel",
233
+ foreign_key: "ModelWithDoubleAssociation_id"
231
234
 
232
235
  has_many :thingamabobs,
233
- class_name: 'DoublyAssociatedModel',
234
- foreign_key: 'ModelWithDoubleAssociation_again_id'
236
+ class_name: "DoublyAssociatedModel",
237
+ foreign_key: "ModelWithDoubleAssociation_again_id"
235
238
 
236
239
  pg_search_scope :with_associated, against: :title,
237
- associated_against: { things: :title, thingamabobs: :title }
240
+ associated_against: {things: :title, thingamabobs: :title}
238
241
  end
239
242
  end
240
243
 
241
244
  it "returns rows that match the query in either its own columns or the columns of the associated model" do
242
245
  included = [
243
- ModelWithDoubleAssociation.create!(title: 'abcdef', things: [
244
- DoublyAssociatedModel.create!(title: 'foo'),
245
- DoublyAssociatedModel.create!(title: 'bar')
246
+ ModelWithDoubleAssociation.create!(title: "abcdef", things: [
247
+ DoublyAssociatedModel.create!(title: "foo"),
248
+ DoublyAssociatedModel.create!(title: "bar")
246
249
  ]),
247
- ModelWithDoubleAssociation.create!(title: 'ghijkl', things: [
248
- DoublyAssociatedModel.create!(title: 'foo bar'),
249
- DoublyAssociatedModel.create!(title: 'mnopqr')
250
+ ModelWithDoubleAssociation.create!(title: "ghijkl", things: [
251
+ DoublyAssociatedModel.create!(title: "foo bar"),
252
+ DoublyAssociatedModel.create!(title: "mnopqr")
250
253
  ]),
251
- ModelWithDoubleAssociation.create!(title: 'foo bar'),
252
- ModelWithDoubleAssociation.create!(title: 'qwerty', thingamabobs: [
254
+ ModelWithDoubleAssociation.create!(title: "foo bar"),
255
+ ModelWithDoubleAssociation.create!(title: "qwerty", thingamabobs: [
253
256
  DoublyAssociatedModel.create!(title: "foo bar")
254
257
  ])
255
258
  ]
256
259
  excluded = [
257
- ModelWithDoubleAssociation.create!(title: 'stuvwx', things: [
258
- DoublyAssociatedModel.create!(title: 'abcdef')
260
+ ModelWithDoubleAssociation.create!(title: "stuvwx", things: [
261
+ DoublyAssociatedModel.create!(title: "abcdef")
259
262
  ]),
260
- ModelWithDoubleAssociation.create!(title: 'qwerty', thingamabobs: [
263
+ ModelWithDoubleAssociation.create!(title: "qwerty", thingamabobs: [
261
264
  DoublyAssociatedModel.create!(title: "uiop")
262
265
  ])
263
266
  ]
264
267
 
265
- results = ModelWithDoubleAssociation.with_associated('foo bar')
268
+ results = ModelWithDoubleAssociation.with_associated("foo bar")
266
269
  expect(results.map(&:title)).to match_array(included.map(&:title))
267
270
  excluded.each { |object| expect(results).not_to include(object) }
268
271
  end
@@ -272,21 +275,22 @@ describe "a pg_search_scope" do
272
275
  context "when against multiple attributes on one association" do
273
276
  with_model :AssociatedModel do
274
277
  table do |t|
275
- t.string 'title'
276
- t.text 'author'
278
+ t.string "title"
279
+ t.text "author"
277
280
  end
278
281
  end
279
282
 
280
283
  with_model :ModelWithAssociation do
281
284
  table do |t|
282
- t.belongs_to 'another_model', index: false
285
+ t.belongs_to "another_model", index: false
283
286
  end
284
287
 
285
288
  model do
286
289
  include PgSearch::Model
287
- belongs_to :another_model, class_name: 'AssociatedModel'
288
290
 
289
- pg_search_scope :with_associated, associated_against: { another_model: %i[title author] }
291
+ belongs_to :another_model, class_name: "AssociatedModel"
292
+
293
+ pg_search_scope :with_associated, associated_against: {another_model: %i[title author]}
290
294
  end
291
295
  end
292
296
 
@@ -314,7 +318,7 @@ describe "a pg_search_scope" do
314
318
  )
315
319
  ]
316
320
 
317
- results = ModelWithAssociation.with_associated('foo bar')
321
+ results = ModelWithAssociation.with_associated("foo bar")
318
322
 
319
323
  expect(results.to_sql.scan("INNER JOIN #{AssociatedModel.quoted_table_name}").length).to eq(1)
320
324
  included.each { |object| expect(results).to include(object) }
@@ -325,21 +329,22 @@ describe "a pg_search_scope" do
325
329
  context "when against non-text columns" do
326
330
  with_model :AssociatedModel do
327
331
  table do |t|
328
- t.integer 'number'
332
+ t.integer "number"
329
333
  end
330
334
  end
331
335
 
332
336
  with_model :Model do
333
337
  table do |t|
334
- t.integer 'number'
335
- t.belongs_to 'another_model', index: false
338
+ t.integer "number"
339
+ t.belongs_to "another_model", index: false
336
340
  end
337
341
 
338
342
  model do
339
343
  include PgSearch::Model
340
- belongs_to :another_model, class_name: 'AssociatedModel'
341
344
 
342
- pg_search_scope :with_associated, associated_against: { another_model: :number }
345
+ belongs_to :another_model, class_name: "AssociatedModel"
346
+
347
+ pg_search_scope :with_associated, associated_against: {another_model: :number}
343
348
  end
344
349
  end
345
350
 
@@ -353,7 +358,7 @@ describe "a pg_search_scope" do
353
358
  Model.create!(number: 123)
354
359
  ]
355
360
 
356
- results = Model.with_associated('123')
361
+ results = Model.with_associated("123")
357
362
  expect(results.map(&:number)).to match_array(included.map(&:number))
358
363
  expect(results).not_to include(excluded)
359
364
  end
@@ -368,6 +373,7 @@ describe "a pg_search_scope" do
368
373
  model do
369
374
  has_many :children
370
375
  include PgSearch::Model
376
+
371
377
  pg_search_scope :search_name, against: :name
372
378
  end
373
379
  end
@@ -384,10 +390,10 @@ describe "a pg_search_scope" do
384
390
 
385
391
  # https://github.com/Casecommons/pg_search/issues/14
386
392
  it "supports queries with periods" do
387
- included = Parent.create!(name: 'bar.foo')
388
- excluded = Parent.create!(name: 'foo.bar')
393
+ included = Parent.create!(name: "bar.foo")
394
+ excluded = Parent.create!(name: "foo.bar")
389
395
 
390
- results = Parent.search_name('bar.foo').includes(:children)
396
+ results = Parent.search_name("bar.foo").includes(:children)
391
397
  results.to_a
392
398
 
393
399
  expect(results).to include(included)
@@ -398,6 +404,8 @@ describe "a pg_search_scope" do
398
404
 
399
405
  context "when merging a pg_search_scope into another model's scope" do
400
406
  with_model :ModelWithAssociation do
407
+ table
408
+
401
409
  model do
402
410
  has_many :associated_models
403
411
  end
@@ -411,6 +419,7 @@ describe "a pg_search_scope" do
411
419
 
412
420
  model do
413
421
  include PgSearch::Model
422
+
414
423
  belongs_to :model_with_association
415
424
 
416
425
  pg_search_scope :search_content, against: :content
@@ -418,10 +427,10 @@ describe "a pg_search_scope" do
418
427
  end
419
428
 
420
429
  it "finds records of the other model" do
421
- included_associated_1 = AssociatedModel.create(content: "foo bar")
422
- included_associated_2 = AssociatedModel.create(content: "foo baz")
423
- excluded_associated_1 = AssociatedModel.create(content: "baz quux")
424
- excluded_associated_2 = AssociatedModel.create(content: "baz bar")
430
+ included_associated_1 = AssociatedModel.create!(content: "foo bar")
431
+ included_associated_2 = AssociatedModel.create!(content: "foo baz")
432
+ excluded_associated_1 = AssociatedModel.create!(content: "baz quux")
433
+ excluded_associated_2 = AssociatedModel.create!(content: "baz bar")
425
434
 
426
435
  included = [
427
436
  ModelWithAssociation.create(associated_models: [included_associated_1]),
@@ -444,6 +453,8 @@ describe "a pg_search_scope" do
444
453
 
445
454
  context "when chained onto a has_many association" do
446
455
  with_model :Company do
456
+ table
457
+
447
458
  model do
448
459
  has_many :positions
449
460
  end
@@ -457,6 +468,7 @@ describe "a pg_search_scope" do
457
468
 
458
469
  model do
459
470
  include PgSearch::Model
471
+
460
472
  pg_search_scope :search, against: :title, using: %i[tsearch trigram]
461
473
  end
462
474
  end
@@ -477,11 +489,11 @@ describe "a pg_search_scope" do
477
489
  Position.create!(company_id: company.id, title: "penn 1")
478
490
  ]
479
491
 
480
- results = company.positions.search('teller 1')
492
+ results = company.positions.search("teller 1")
481
493
 
482
494
  expect(results).to include(*included)
483
495
  expect(results).not_to include(*excluded)
484
496
  end
485
497
  end
486
498
  end
487
- # rubocop:enable RSpec/NestedGroups
499
+ # standard:enable RSpec/NestedGroups
@@ -1,33 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "spec_helper"
4
+ require "active_support/core_ext/kernel/reporting"
4
5
 
5
6
  describe "Including the deprecated PgSearch module" do
6
7
  with_model :SomeModel do
8
+ table
9
+
7
10
  model do
8
- ActiveSupport::Deprecation.silence do
11
+ silence_warnings do
9
12
  include PgSearch
10
13
  end
11
14
  end
12
15
  end
13
16
 
14
- with_model :AnotherModel
17
+ with_model :AnotherModel do
18
+ table
19
+ end
15
20
 
16
21
  it "includes PgSearch::Model" do
17
22
  expect(SomeModel.ancestors).to include PgSearch::Model
18
23
  end
19
24
 
20
25
  it "prints a deprecation message" do
21
- allow(ActiveSupport::Deprecation).to receive(:warn)
26
+ allow(PgSearch).to receive(:warn)
22
27
 
23
28
  AnotherModel.include(PgSearch)
24
29
 
25
- expect(ActiveSupport::Deprecation).to have_received(:warn).with(
26
- <<~MESSAGE
27
- Directly including `PgSearch` into an Active Record model is deprecated and will be removed in pg_search 3.0.
30
+ expect(PgSearch).to have_received(:warn).with(<<~MESSAGE, category: :deprecated, uplevel: 1)
31
+ Directly including `PgSearch` into an Active Record model is deprecated and will be removed in pg_search 3.0.
28
32
 
29
- Please replace `include PgSearch` with `include PgSearch::Model`.
30
- MESSAGE
31
- )
33
+ Please replace `include PgSearch` with `include PgSearch::Model`.
34
+ MESSAGE
32
35
  end
33
36
  end
@@ -11,6 +11,7 @@ describe "pagination" do
11
11
 
12
12
  model do
13
13
  include PgSearch::Model
14
+
14
15
  pg_search_scope :search_name, against: :name
15
16
 
16
17
  def self.page(page_number)