pg_search 2.3.5 → 2.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +80 -0
- data/.standard.yml +6 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +19 -6
- data/LICENSE +1 -1
- data/README.md +61 -39
- data/Rakefile +9 -6
- data/lib/pg_search/configuration/column.rb +6 -4
- data/lib/pg_search/configuration/foreign_column.rb +1 -1
- data/lib/pg_search/configuration.rb +13 -3
- data/lib/pg_search/document.rb +8 -8
- data/lib/pg_search/features/dmetaphone.rb +1 -1
- data/lib/pg_search/features/feature.rb +1 -1
- data/lib/pg_search/features/trigram.rb +4 -4
- data/lib/pg_search/features/tsearch.rb +15 -14
- data/lib/pg_search/migration/dmetaphone_generator.rb +2 -2
- data/lib/pg_search/migration/generator.rb +5 -5
- data/lib/pg_search/migration/multisearch_generator.rb +2 -2
- data/lib/pg_search/model.rb +6 -6
- data/lib/pg_search/multisearch.rb +16 -6
- data/lib/pg_search/multisearchable.rb +7 -7
- data/lib/pg_search/normalizer.rb +5 -5
- data/lib/pg_search/scope_options.rb +28 -10
- data/lib/pg_search/tasks.rb +2 -2
- data/lib/pg_search/version.rb +1 -1
- data/lib/pg_search.rb +5 -5
- data/pg_search.gemspec +17 -29
- data/spec/.rubocop.yml +20 -7
- data/spec/integration/.rubocop.yml +2 -2
- data/spec/integration/associations_spec.rb +106 -106
- data/spec/integration/deprecation_spec.rb +7 -8
- data/spec/integration/pg_search_spec.rb +339 -292
- data/spec/integration/single_table_inheritance_spec.rb +5 -5
- data/spec/lib/pg_search/configuration/association_spec.rb +15 -15
- data/spec/lib/pg_search/configuration/column_spec.rb +13 -1
- data/spec/lib/pg_search/configuration/foreign_column_spec.rb +4 -4
- data/spec/lib/pg_search/features/dmetaphone_spec.rb +4 -4
- data/spec/lib/pg_search/features/trigram_spec.rb +28 -28
- data/spec/lib/pg_search/features/tsearch_spec.rb +57 -39
- data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +17 -17
- data/spec/lib/pg_search/multisearch_spec.rb +15 -6
- data/spec/lib/pg_search/multisearchable_spec.rb +26 -26
- data/spec/lib/pg_search/normalizer_spec.rb +7 -7
- data/spec/lib/pg_search_spec.rb +20 -20
- data/spec/spec_helper.rb +15 -9
- data/spec/support/database.rb +9 -7
- metadata +13 -188
- data/.autotest +0 -5
- data/.codeclimate.yml +0 -17
- data/.rubocop.yml +0 -134
- data/.travis.yml +0 -42
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
#
|
5
|
+
# standard:disable RSpec/NestedGroups
|
6
6
|
describe PgSearch::Multisearch::Rebuilder do
|
7
7
|
with_table "pg_search_documents", &DOCUMENTS_SCHEMA
|
8
8
|
|
9
|
-
describe
|
9
|
+
describe "when initialized with a model that is not multisearchable" do
|
10
10
|
with_model :not_multisearchable
|
11
11
|
|
12
|
-
it
|
12
|
+
it "raises an exception" do
|
13
13
|
expect {
|
14
14
|
described_class.new(NotMultisearchable)
|
15
15
|
}.to raise_exception(
|
@@ -108,7 +108,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
#
|
111
|
+
# standard:disable RSpec/ExampleLength
|
112
112
|
it "executes the default SQL" do
|
113
113
|
time = Time.utc(2001, 1, 1, 0, 0, 0)
|
114
114
|
rebuilder = described_class.new(Model, -> { time })
|
@@ -137,7 +137,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
137
137
|
expect(executed_sql.length).to eq(1)
|
138
138
|
expect(executed_sql.first.strip).to eq(expected_sql.strip)
|
139
139
|
end
|
140
|
-
#
|
140
|
+
# standard:enable RSpec/ExampleLength
|
141
141
|
|
142
142
|
context "with a model with a camel case column" do
|
143
143
|
with_model :ModelWithCamelCaseColumn do
|
@@ -151,10 +151,10 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
|
-
it "
|
154
|
+
it "rebuilds without error" do
|
155
155
|
time = Time.utc(2001, 1, 1, 0, 0, 0)
|
156
156
|
rebuilder = described_class.new(Model, -> { time })
|
157
|
-
rebuilder.rebuild
|
157
|
+
expect { rebuilder.rebuild }.not_to raise_error
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -170,7 +170,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
-
#
|
173
|
+
# standard:disable RSpec/ExampleLength
|
174
174
|
it "generates SQL with the correct primary key" do
|
175
175
|
time = Time.utc(2001, 1, 1, 0, 0, 0)
|
176
176
|
rebuilder = described_class.new(ModelWithNonStandardPrimaryKey, -> { time })
|
@@ -199,7 +199,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
199
199
|
expect(executed_sql.length).to eq(1)
|
200
200
|
expect(executed_sql.first.strip).to eq(expected_sql.strip)
|
201
201
|
end
|
202
|
-
#
|
202
|
+
# standard:enable RSpec/ExampleLength
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
@@ -215,7 +215,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
|
-
#
|
218
|
+
# standard:disable RSpec/ExampleLength
|
219
219
|
it "calls update_pg_search_document on each record" do
|
220
220
|
record = Model.create!
|
221
221
|
|
@@ -241,7 +241,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
241
241
|
|
242
242
|
expect(record.pg_search_document).to be_present
|
243
243
|
end
|
244
|
-
#
|
244
|
+
# standard:enable RSpec/ExampleLength
|
245
245
|
end
|
246
246
|
|
247
247
|
context "when only additional_attributes is set" do
|
@@ -253,7 +253,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
253
253
|
model do
|
254
254
|
include PgSearch::Model
|
255
255
|
multisearchable against: :name,
|
256
|
-
|
256
|
+
additional_attributes: ->(obj) { {additional_attribute_column: "#{obj.class}::#{obj.id}"} }
|
257
257
|
end
|
258
258
|
end
|
259
259
|
|
@@ -285,7 +285,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
285
285
|
end
|
286
286
|
end
|
287
287
|
|
288
|
-
#
|
288
|
+
# standard:disable RSpec/ExampleLength
|
289
289
|
it "calls update_pg_search_document on each record" do
|
290
290
|
record_1 = Model.create!(active: true)
|
291
291
|
record_2 = Model.create!(active: false)
|
@@ -311,7 +311,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
311
311
|
expect(record_1.pg_search_document).to be_present
|
312
312
|
expect(record_2.pg_search_document).not_to be_present
|
313
313
|
end
|
314
|
-
#
|
314
|
+
# standard:enable RSpec/ExampleLength
|
315
315
|
end
|
316
316
|
|
317
317
|
context "via :unless" do
|
@@ -326,7 +326,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
326
326
|
end
|
327
327
|
end
|
328
328
|
|
329
|
-
#
|
329
|
+
# standard:disable RSpec/ExampleLength
|
330
330
|
it "calls update_pg_search_document on each record" do
|
331
331
|
record_1 = Model.create!(inactive: true)
|
332
332
|
record_2 = Model.create!(inactive: false)
|
@@ -352,10 +352,10 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
352
352
|
expect(record_1.pg_search_document).not_to be_present
|
353
353
|
expect(record_2.pg_search_document).to be_present
|
354
354
|
end
|
355
|
-
#
|
355
|
+
# standard:enable RSpec/ExampleLength
|
356
356
|
end
|
357
357
|
end
|
358
358
|
end
|
359
359
|
end
|
360
360
|
end
|
361
|
-
#
|
361
|
+
# standard:enable RSpec/NestedGroups
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
|
-
require "active_support/
|
4
|
+
require "active_support/core_ext/kernel/reporting"
|
5
5
|
|
6
|
-
#
|
6
|
+
# standard:disable RSpec/NestedGroups
|
7
7
|
describe PgSearch::Multisearch do
|
8
8
|
with_table "pg_search_documents", &DOCUMENTS_SCHEMA
|
9
9
|
|
@@ -33,6 +33,15 @@ describe PgSearch::Multisearch do
|
|
33
33
|
expect(model).to have_received(:transaction).once
|
34
34
|
end
|
35
35
|
|
36
|
+
context "when transactional is false" do
|
37
|
+
it "does not operate inside a transaction" do
|
38
|
+
allow(model).to receive(:transaction)
|
39
|
+
|
40
|
+
described_class.rebuild(model, transactional: false)
|
41
|
+
expect(model).not_to have_received(:transaction)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
36
45
|
describe "cleaning up search documents for this model" do
|
37
46
|
before do
|
38
47
|
connection.execute <<~SQL.squish
|
@@ -73,7 +82,7 @@ describe PgSearch::Multisearch do
|
|
73
82
|
|
74
83
|
context "when deprecated_clean_up is true" do
|
75
84
|
it "deletes the document for the model" do
|
76
|
-
|
85
|
+
silence_warnings { described_class.rebuild(model, true) }
|
77
86
|
expect(PgSearch::Document.count).to eq(1)
|
78
87
|
expect(PgSearch::Document.first.searchable_type).to eq("Bar")
|
79
88
|
end
|
@@ -81,7 +90,7 @@ describe PgSearch::Multisearch do
|
|
81
90
|
|
82
91
|
context "when deprecated_clean_up is false" do
|
83
92
|
it "does not delete the document for the model" do
|
84
|
-
|
93
|
+
silence_warnings { described_class.rebuild(model, false) }
|
85
94
|
expect(PgSearch::Document.count).to eq(2)
|
86
95
|
end
|
87
96
|
end
|
@@ -126,7 +135,7 @@ describe PgSearch::Multisearch do
|
|
126
135
|
end
|
127
136
|
|
128
137
|
describe "the generated SQL" do
|
129
|
-
let(:now) { Time.now }
|
138
|
+
let(:now) { Time.now } # standard:disable Rails/TimeZone
|
130
139
|
|
131
140
|
before { allow(Time).to receive(:now).and_return(now) }
|
132
141
|
|
@@ -186,4 +195,4 @@ describe PgSearch::Multisearch do
|
|
186
195
|
end
|
187
196
|
end
|
188
197
|
end
|
189
|
-
#
|
198
|
+
# standard:enable RSpec/NestedGroups
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
#
|
5
|
+
# standard:disable RSpec/NestedGroups
|
6
6
|
describe PgSearch::Multisearchable do
|
7
7
|
with_table "pg_search_documents", &DOCUMENTS_SCHEMA
|
8
8
|
|
@@ -36,7 +36,7 @@ describe PgSearch::Multisearchable do
|
|
36
36
|
belongs_to :multisearchable_parent
|
37
37
|
|
38
38
|
after_destroy do
|
39
|
-
multisearchable_parent.update_attribute(:secret, rand(1000).to_s)
|
39
|
+
multisearchable_parent.update_attribute(:secret, rand(1000).to_s)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -149,17 +149,17 @@ describe PgSearch::Multisearchable do
|
|
149
149
|
end
|
150
150
|
|
151
151
|
context "when searching against a single column" do
|
152
|
-
let(:multisearchable_options) { {
|
152
|
+
let(:multisearchable_options) { {against: :some_content} }
|
153
153
|
let(:text) { "foo bar" }
|
154
154
|
|
155
155
|
before do
|
156
156
|
without_partial_double_verification do
|
157
157
|
allow(record).to receive(:some_content) { text }
|
158
158
|
end
|
159
|
-
record.save
|
159
|
+
record.save!
|
160
160
|
end
|
161
161
|
|
162
|
-
describe
|
162
|
+
describe "#content" do
|
163
163
|
subject { super().pg_search_document.content }
|
164
164
|
|
165
165
|
it { is_expected.to eq(text) }
|
@@ -167,17 +167,17 @@ describe PgSearch::Multisearchable do
|
|
167
167
|
end
|
168
168
|
|
169
169
|
context "when searching against multiple columns" do
|
170
|
-
let(:multisearchable_options) { {
|
170
|
+
let(:multisearchable_options) { {against: %i[attr_1 attr_2]} }
|
171
171
|
|
172
172
|
before do
|
173
173
|
without_partial_double_verification do
|
174
|
-
allow(record).to receive(:attr_1).and_return(
|
175
|
-
allow(record).to receive(:attr_2).and_return(
|
174
|
+
allow(record).to receive(:attr_1).and_return("1")
|
175
|
+
allow(record).to receive(:attr_2).and_return("2")
|
176
176
|
end
|
177
|
-
record.save
|
177
|
+
record.save!
|
178
178
|
end
|
179
179
|
|
180
|
-
describe
|
180
|
+
describe "#content" do
|
181
181
|
subject { super().pg_search_document.content }
|
182
182
|
|
183
183
|
it { is_expected.to eq("1 2") }
|
@@ -195,17 +195,17 @@ describe PgSearch::Multisearchable do
|
|
195
195
|
end
|
196
196
|
|
197
197
|
context "when searching against a single column" do
|
198
|
-
let(:multisearchable_options) { {
|
198
|
+
let(:multisearchable_options) { {against: :some_content} }
|
199
199
|
let(:text) { "foo bar" }
|
200
200
|
|
201
201
|
before do
|
202
202
|
without_partial_double_verification do
|
203
203
|
allow(record).to receive(:some_content) { text }
|
204
204
|
end
|
205
|
-
record.save
|
205
|
+
record.save!
|
206
206
|
end
|
207
207
|
|
208
|
-
describe
|
208
|
+
describe "#content" do
|
209
209
|
subject { super().pg_search_document.content }
|
210
210
|
|
211
211
|
it { is_expected.to eq(text) }
|
@@ -213,17 +213,17 @@ describe PgSearch::Multisearchable do
|
|
213
213
|
end
|
214
214
|
|
215
215
|
context "when searching against multiple columns" do
|
216
|
-
let(:multisearchable_options) { {
|
216
|
+
let(:multisearchable_options) { {against: %i[attr_1 attr_2]} }
|
217
217
|
|
218
218
|
before do
|
219
219
|
without_partial_double_verification do
|
220
|
-
allow(record).to receive(:attr_1).and_return(
|
221
|
-
allow(record).to receive(:attr_2).and_return(
|
220
|
+
allow(record).to receive(:attr_1).and_return("1")
|
221
|
+
allow(record).to receive(:attr_2).and_return("2")
|
222
222
|
end
|
223
|
-
record.save
|
223
|
+
record.save!
|
224
224
|
end
|
225
225
|
|
226
|
-
describe
|
226
|
+
describe "#content" do
|
227
227
|
subject { super().pg_search_document.content }
|
228
228
|
|
229
229
|
it { is_expected.to eq("1 2") }
|
@@ -234,7 +234,7 @@ describe PgSearch::Multisearchable do
|
|
234
234
|
let(:multisearchable_options) do
|
235
235
|
{
|
236
236
|
additional_attributes: lambda do |record|
|
237
|
-
{
|
237
|
+
{foo: record.bar}
|
238
238
|
end
|
239
239
|
}
|
240
240
|
end
|
@@ -244,10 +244,10 @@ describe PgSearch::Multisearchable do
|
|
244
244
|
without_partial_double_verification do
|
245
245
|
allow(record).to receive(:bar).and_return(text)
|
246
246
|
allow(record).to receive(:create_pg_search_document)
|
247
|
-
record.save
|
247
|
+
record.save!
|
248
248
|
expect(record)
|
249
249
|
.to have_received(:create_pg_search_document)
|
250
|
-
.with(content:
|
250
|
+
.with(content: "", foo: text)
|
251
251
|
end
|
252
252
|
end
|
253
253
|
end
|
@@ -266,10 +266,10 @@ describe PgSearch::Multisearchable do
|
|
266
266
|
without_partial_double_verification do
|
267
267
|
allow(record).to receive(:bar?).and_return(false)
|
268
268
|
allow(record).to receive(:create_pg_search_document)
|
269
|
-
record.save
|
269
|
+
record.save!
|
270
270
|
expect(record)
|
271
271
|
.to have_received(:create_pg_search_document)
|
272
|
-
.with(content:
|
272
|
+
.with(content: "")
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
@@ -286,7 +286,7 @@ describe PgSearch::Multisearchable do
|
|
286
286
|
it "does not update the document" do
|
287
287
|
without_partial_double_verification do
|
288
288
|
allow(record.pg_search_document).to receive(:update)
|
289
|
-
record.save
|
289
|
+
record.save!
|
290
290
|
expect(record.pg_search_document).not_to have_received(:update)
|
291
291
|
end
|
292
292
|
end
|
@@ -301,7 +301,7 @@ describe PgSearch::Multisearchable do
|
|
301
301
|
|
302
302
|
it "updates the document" do
|
303
303
|
allow(record.pg_search_document).to receive(:update)
|
304
|
-
record.save
|
304
|
+
record.save!
|
305
305
|
expect(record.pg_search_document).to have_received(:update)
|
306
306
|
end
|
307
307
|
end
|
@@ -854,4 +854,4 @@ describe PgSearch::Multisearchable do
|
|
854
854
|
end
|
855
855
|
end
|
856
856
|
end
|
857
|
-
#
|
857
|
+
# standard:enable RSpec/NestedGroups
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
#
|
5
|
+
# standard:disable RSpec/NestedGroups
|
6
6
|
describe PgSearch::Normalizer do
|
7
7
|
describe "#add_normalization" do
|
8
8
|
context "when config[:ignore] includes :accents" do
|
9
9
|
context "when passed an Arel node" do
|
10
10
|
it "wraps the expression in unaccent()" do
|
11
|
-
config = instance_double(
|
11
|
+
config = instance_double(PgSearch::Configuration, "config", ignore: [:accents])
|
12
12
|
node = Arel::Nodes::NamedFunction.new("foo", [Arel::Nodes.build_quoted("bar")])
|
13
13
|
|
14
14
|
normalizer = described_class.new(config)
|
@@ -20,7 +20,7 @@ describe PgSearch::Normalizer do
|
|
20
20
|
allow(PgSearch).to receive(:unaccent_function).and_return("my_unaccent")
|
21
21
|
node = Arel::Nodes::NamedFunction.new("foo", [Arel::Nodes.build_quoted("bar")])
|
22
22
|
|
23
|
-
config = instance_double(
|
23
|
+
config = instance_double(PgSearch::Configuration, "config", ignore: [:accents])
|
24
24
|
|
25
25
|
normalizer = described_class.new(config)
|
26
26
|
expect(normalizer.add_normalization(node)).to eq("my_unaccent(foo('bar'))")
|
@@ -30,7 +30,7 @@ describe PgSearch::Normalizer do
|
|
30
30
|
|
31
31
|
context "when passed a String" do
|
32
32
|
it "wraps the expression in unaccent()" do
|
33
|
-
config = instance_double(
|
33
|
+
config = instance_double(PgSearch::Configuration, "config", ignore: [:accents])
|
34
34
|
|
35
35
|
normalizer = described_class.new(config)
|
36
36
|
expect(normalizer.add_normalization("foo")).to eq("unaccent(foo)")
|
@@ -40,7 +40,7 @@ describe PgSearch::Normalizer do
|
|
40
40
|
it "wraps the expression in that function" do
|
41
41
|
allow(PgSearch).to receive(:unaccent_function).and_return("my_unaccent")
|
42
42
|
|
43
|
-
config = instance_double(
|
43
|
+
config = instance_double(PgSearch::Configuration, "config", ignore: [:accents])
|
44
44
|
|
45
45
|
normalizer = described_class.new(config)
|
46
46
|
expect(normalizer.add_normalization("foo")).to eq("my_unaccent(foo)")
|
@@ -51,7 +51,7 @@ describe PgSearch::Normalizer do
|
|
51
51
|
|
52
52
|
context "when config[:ignore] does not include :accents" do
|
53
53
|
it "passes the expression through" do
|
54
|
-
config = instance_double(
|
54
|
+
config = instance_double(PgSearch::Configuration, "config", ignore: [])
|
55
55
|
|
56
56
|
normalizer = described_class.new(config)
|
57
57
|
expect(normalizer.add_normalization("foo")).to eq("foo")
|
@@ -59,4 +59,4 @@ describe PgSearch::Normalizer do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
|
-
#
|
62
|
+
# standard:enable RSpec/NestedGroups
|
data/spec/lib/pg_search_spec.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
# For Active Record 5.x
|
5
|
+
# For Active Record 5.x, the association reflection's cache needs be cleared
|
6
6
|
# because we're stubbing the related constants.
|
7
|
-
if ActiveRecord::VERSION::MAJOR == 5
|
7
|
+
if ActiveRecord::VERSION::MAJOR == 5
|
8
8
|
def clear_searchable_cache
|
9
9
|
PgSearch::Document.reflect_on_association(:searchable).clear_association_scope_cache
|
10
10
|
end
|
@@ -13,7 +13,7 @@ else
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
#
|
16
|
+
# standard:disable RSpec/NestedGroups
|
17
17
|
describe PgSearch do
|
18
18
|
describe ".multisearch" do
|
19
19
|
with_table "pg_search_documents", &DOCUMENTS_SCHEMA
|
@@ -21,8 +21,8 @@ describe PgSearch do
|
|
21
21
|
describe "delegation to PgSearch::Document.search" do
|
22
22
|
subject { described_class.multisearch(query) }
|
23
23
|
|
24
|
-
let(:query) { instance_double(
|
25
|
-
let(:relation) { instance_double(
|
24
|
+
let(:query) { instance_double(String, "query") }
|
25
|
+
let(:relation) { instance_double(ActiveRecord::Relation, "relation") }
|
26
26
|
|
27
27
|
before do
|
28
28
|
allow(PgSearch::Document).to receive(:search).with(query).and_return(relation)
|
@@ -49,7 +49,7 @@ describe PgSearch do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
let!(:soundalike_record) { MultisearchableModel.create!(title:
|
52
|
+
let!(:soundalike_record) { MultisearchableModel.create!(title: "foning") }
|
53
53
|
let(:query) { "Phoning" }
|
54
54
|
|
55
55
|
it { is_expected.to include(soundalike_record) }
|
@@ -65,9 +65,9 @@ describe PgSearch do
|
|
65
65
|
allow(described_class).to receive(:multisearch_options) do
|
66
66
|
lambda do |query, soundalike|
|
67
67
|
if soundalike
|
68
|
-
{
|
68
|
+
{using: :dmetaphone, query: query}
|
69
69
|
else
|
70
|
-
{
|
70
|
+
{query: query}
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -83,7 +83,7 @@ describe PgSearch do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
let!(:soundalike_record) { MultisearchableModel.create!(title:
|
86
|
+
let!(:soundalike_record) { MultisearchableModel.create!(title: "foning") }
|
87
87
|
let(:query) { "Phoning" }
|
88
88
|
|
89
89
|
context "with soundalike true" do
|
@@ -103,8 +103,8 @@ describe PgSearch do
|
|
103
103
|
context "with standard type column" do
|
104
104
|
with_model :SuperclassModel do
|
105
105
|
table do |t|
|
106
|
-
t.text
|
107
|
-
t.string
|
106
|
+
t.text "content"
|
107
|
+
t.string "type"
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -149,7 +149,7 @@ describe PgSearch do
|
|
149
149
|
expect(results.size).to eq(SearchableSubclassModel.count)
|
150
150
|
end
|
151
151
|
|
152
|
-
#
|
152
|
+
# standard:disable RSpec/MultipleExpectations
|
153
153
|
specify "reindexing works" do
|
154
154
|
NonSearchableSubclassModel.create!(content: "foo bar")
|
155
155
|
NonSearchableSubclassModel.create!(content: "baz")
|
@@ -171,7 +171,7 @@ describe PgSearch do
|
|
171
171
|
expect(PgSearch::Document.first.searchable.class).to be SearchableSubclassModel
|
172
172
|
expect(PgSearch::Document.first.searchable).to eq expected
|
173
173
|
end
|
174
|
-
#
|
174
|
+
# standard:enable RSpec/MultipleExpectations
|
175
175
|
|
176
176
|
it "reindexing searchable STI doesn't clobber other related STI models" do
|
177
177
|
SearchableSubclassModel.create!(content: "baz")
|
@@ -191,12 +191,12 @@ describe PgSearch do
|
|
191
191
|
context "with custom type column" do
|
192
192
|
with_model :SuperclassModel do
|
193
193
|
table do |t|
|
194
|
-
t.text
|
195
|
-
t.string
|
194
|
+
t.text "content"
|
195
|
+
t.string "inherit"
|
196
196
|
end
|
197
197
|
|
198
198
|
model do
|
199
|
-
self.inheritance_column =
|
199
|
+
self.inheritance_column = "inherit"
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
@@ -254,7 +254,7 @@ describe PgSearch do
|
|
254
254
|
multisearch_enabled_inside = described_class.multisearch_enabled?
|
255
255
|
raise
|
256
256
|
end
|
257
|
-
rescue
|
257
|
+
rescue
|
258
258
|
end
|
259
259
|
multisearch_enabled_after = described_class.multisearch_enabled?
|
260
260
|
|
@@ -263,7 +263,7 @@ describe PgSearch do
|
|
263
263
|
expect(multisearch_enabled_after).to be(true)
|
264
264
|
end
|
265
265
|
|
266
|
-
#
|
266
|
+
# standard:disable RSpec/ExampleLength
|
267
267
|
it "does not disable multisearch on other threads" do
|
268
268
|
values = Queue.new
|
269
269
|
sync = Queue.new
|
@@ -288,7 +288,7 @@ describe PgSearch do
|
|
288
288
|
expect(multisearch_enabled_inside).to be(true)
|
289
289
|
expect(multisearch_enabled_after).to be(true)
|
290
290
|
end
|
291
|
-
#
|
291
|
+
# standard:enable RSpec/ExampleLength
|
292
292
|
end
|
293
293
|
end
|
294
|
-
#
|
294
|
+
# standard:enable RSpec/NestedGroups
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
require
|
8
|
-
SimpleCov.
|
3
|
+
require "warning"
|
4
|
+
|
5
|
+
# https://github.com/grodowski/undercover#setting-up-required-lcov-reporting
|
6
|
+
require "simplecov"
|
7
|
+
require "simplecov-lcov"
|
8
|
+
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter(%r{^/spec/})
|
12
|
+
enable_coverage(:branch)
|
13
|
+
end
|
14
|
+
require "undercover"
|
9
15
|
|
10
16
|
require "bundler/setup"
|
11
17
|
require "pg_search"
|
@@ -21,11 +27,11 @@ RSpec.configure do |config|
|
|
21
27
|
mocks.verify_partial_doubles = true
|
22
28
|
end
|
23
29
|
|
24
|
-
config.example_status_persistence_file_path =
|
30
|
+
config.example_status_persistence_file_path = "tmp/examples.txt"
|
25
31
|
end
|
26
32
|
|
27
|
-
require
|
28
|
-
require
|
33
|
+
require "support/database"
|
34
|
+
require "support/with_model"
|
29
35
|
|
30
36
|
DOCUMENTS_SCHEMA = lambda do |t|
|
31
37
|
t.belongs_to :searchable, polymorphic: true, index: true
|
data/spec/support/database.rb
CHANGED
@@ -10,10 +10,12 @@ else
|
|
10
10
|
end
|
11
11
|
|
12
12
|
begin
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
connection_options = {adapter: "postgresql", database: "pg_search_test", min_messages: "warning"}
|
14
|
+
if ENV["CI"]
|
15
|
+
connection_options[:username] = "postgres"
|
16
|
+
connection_options[:password] = "postgres"
|
17
|
+
end
|
18
|
+
ActiveRecord::Base.establish_connection(connection_options)
|
17
19
|
connection = ActiveRecord::Base.connection
|
18
20
|
connection.execute("SELECT 1")
|
19
21
|
rescue ERROR_CLASS, ActiveRecord::NoDatabaseError => e
|
@@ -38,7 +40,7 @@ def install_extension(name)
|
|
38
40
|
return unless extension.none?
|
39
41
|
|
40
42
|
connection.execute "CREATE EXTENSION #{name};"
|
41
|
-
rescue
|
43
|
+
rescue => e
|
42
44
|
at_exit do
|
43
45
|
puts "-" * 80
|
44
46
|
puts "Please install the #{name} extension"
|
@@ -50,7 +52,7 @@ end
|
|
50
52
|
def install_extension_if_missing(name, query, expected_result)
|
51
53
|
result = ActiveRecord::Base.connection.select_value(query)
|
52
54
|
raise "Unexpected output for #{query}: #{result.inspect}" unless result.casecmp(expected_result).zero?
|
53
|
-
rescue
|
55
|
+
rescue
|
54
56
|
install_extension(name)
|
55
57
|
end
|
56
58
|
|
@@ -60,7 +62,7 @@ install_extension_if_missing("fuzzystrmatch", "SELECT dmetaphone('foo')", "f")
|
|
60
62
|
|
61
63
|
def load_sql(filename)
|
62
64
|
connection = ActiveRecord::Base.connection
|
63
|
-
file_contents = File.read(File.join(File.dirname(__FILE__),
|
65
|
+
file_contents = File.read(File.join(File.dirname(__FILE__), "..", "..", "sql", filename))
|
64
66
|
connection.execute(file_contents)
|
65
67
|
end
|
66
68
|
|