pg_search 0.7.4 → 0.7.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +30 -13
- data/lib/pg_search/document.rb +4 -2
- data/lib/pg_search/features/tsearch.rb +23 -19
- data/lib/pg_search/migration/associated_against_generator.rb +4 -16
- data/lib/pg_search/migration/dmetaphone_generator.rb +4 -16
- data/lib/pg_search/migration/generator.rb +28 -0
- data/lib/pg_search/migration/multisearch_generator.rb +4 -8
- data/lib/pg_search/migration/templates/add_pg_search_associated_against_support_functions.rb.erb +2 -2
- data/lib/pg_search/migration/templates/{create_pg_search_documents.rb → create_pg_search_documents.rb.erb} +0 -0
- data/lib/pg_search/scope_options.rb +3 -1
- data/lib/pg_search/version.rb +1 -1
- data/pg_search.gemspec +1 -1
- data/spec/integration/associations_spec.rb +25 -25
- data/spec/integration/pagination_spec.rb +4 -4
- data/spec/integration/pg_search_spec.rb +123 -103
- data/spec/lib/pg_search/configuration/column_spec.rb +2 -2
- data/spec/lib/pg_search/document_spec.rb +11 -4
- data/spec/lib/pg_search/features/dmetaphone_spec.rb +4 -2
- data/spec/lib/pg_search/features/tsearch_spec.rb +4 -2
- data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +16 -16
- data/spec/lib/pg_search/multisearch_spec.rb +15 -18
- data/spec/lib/pg_search/multisearchable_spec.rb +39 -38
- data/spec/lib/pg_search/normalizer_spec.rb +8 -8
- data/spec/spec_helper.rb +8 -94
- data/spec/support/coveralls.rb +7 -0
- data/spec/support/database.rb +83 -0
- data/spec/support/with_model.rb +5 -0
- metadata +14 -7
@@ -28,21 +28,28 @@ describe PgSearch::Document do
|
|
28
28
|
let(:multisearchable_options) { {:against => :some_content} }
|
29
29
|
let(:text) { "foo bar" }
|
30
30
|
before do
|
31
|
-
searchable.
|
31
|
+
allow(searchable).to receive(:some_content) { text }
|
32
32
|
document.valid?
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
describe '#content' do
|
36
|
+
subject { super().content }
|
37
|
+
it { should == text }
|
38
|
+
end
|
36
39
|
end
|
37
40
|
|
38
41
|
context "when searching against multiple columns" do
|
39
42
|
let(:multisearchable_options) { {:against => [:attr1, :attr2]} }
|
40
43
|
before do
|
41
|
-
searchable.
|
44
|
+
allow(searchable).to receive(:attr1) { '1' }
|
45
|
+
allow(searchable).to receive(:attr2) { '2' }
|
42
46
|
document.valid?
|
43
47
|
end
|
44
48
|
|
45
|
-
|
49
|
+
describe '#content' do
|
50
|
+
subject { super().content }
|
51
|
+
it { should == "1 2" }
|
52
|
+
end
|
46
53
|
end
|
47
54
|
end
|
48
55
|
end
|
@@ -20,8 +20,9 @@ describe PgSearch::Features::DMetaphone do
|
|
20
20
|
normalizer = PgSearch::Normalizer.new(config)
|
21
21
|
|
22
22
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
23
|
-
feature.rank.to_sql.
|
23
|
+
expect(feature.rank.to_sql).to eq(
|
24
24
|
%Q{(ts_rank((to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."name"::text, ''))) || to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."content"::text, '')))), (to_tsquery('simple', ''' ' || pg_search_dmetaphone('query') || ' ''')), 0))}
|
25
|
+
)
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
@@ -44,8 +45,9 @@ describe PgSearch::Features::DMetaphone do
|
|
44
45
|
normalizer = PgSearch::Normalizer.new(config)
|
45
46
|
|
46
47
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
47
|
-
feature.conditions.to_sql.
|
48
|
+
expect(feature.conditions.to_sql).to eq(
|
48
49
|
%Q{((to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."name"::text, ''))) || to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."content"::text, '')))) @@ (to_tsquery('simple', ''' ' || pg_search_dmetaphone('query') || ' ''')))}
|
50
|
+
)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -20,8 +20,9 @@ describe PgSearch::Features::TSearch do
|
|
20
20
|
normalizer = PgSearch::Normalizer.new(config)
|
21
21
|
|
22
22
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
23
|
-
feature.rank.to_sql.
|
23
|
+
expect(feature.rank.to_sql).to eq(
|
24
24
|
%Q{(ts_rank((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))), (to_tsquery('simple', ''' ' || 'query' || ' ''')), 0))}
|
25
|
+
)
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
@@ -44,8 +45,9 @@ describe PgSearch::Features::TSearch do
|
|
44
45
|
normalizer = PgSearch::Normalizer.new(config)
|
45
46
|
|
46
47
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
47
|
-
feature.conditions.to_sql.
|
48
|
+
expect(feature.conditions.to_sql).to eq(
|
48
49
|
%Q{((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'query' || ' ''')))}
|
50
|
+
)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -18,7 +18,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
18
18
|
|
19
19
|
it "should call .rebuild_pg_search_documents" do
|
20
20
|
rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
|
21
|
-
Model.
|
21
|
+
expect(Model).to receive(:rebuild_pg_search_documents)
|
22
22
|
rebuilder.rebuild
|
23
23
|
end
|
24
24
|
end
|
@@ -42,7 +42,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
42
42
|
|
43
43
|
it "should call .rebuild_pg_search_documents" do
|
44
44
|
rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
|
45
|
-
Model.
|
45
|
+
expect(Model).to receive(:rebuild_pg_search_documents)
|
46
46
|
rebuilder.rebuild
|
47
47
|
end
|
48
48
|
end
|
@@ -68,7 +68,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
68
68
|
|
69
69
|
# stub respond_to? to return false since should_not_receive defines the method
|
70
70
|
original_respond_to = Model.method(:respond_to?)
|
71
|
-
Model.
|
71
|
+
allow(Model).to receive(:respond_to?) do |method_name, *args|
|
72
72
|
if method_name == :rebuild_pg_search_documents
|
73
73
|
false
|
74
74
|
else
|
@@ -76,7 +76,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
Model.
|
79
|
+
expect(Model).not_to receive(:rebuild_pg_search_documents)
|
80
80
|
rebuilder.rebuild
|
81
81
|
end
|
82
82
|
|
@@ -120,8 +120,8 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
120
120
|
rebuilder.rebuild
|
121
121
|
ActiveSupport::Notifications.unsubscribe(notifier)
|
122
122
|
|
123
|
-
executed_sql.length.
|
124
|
-
executed_sql.first.
|
123
|
+
expect(executed_sql.length).to eq(1)
|
124
|
+
expect(executed_sql.first).to eq(expected_sql)
|
125
125
|
end
|
126
126
|
|
127
127
|
context "for a model with a non-standard primary key" do
|
@@ -176,8 +176,8 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
176
176
|
rebuilder.rebuild
|
177
177
|
ActiveSupport::Notifications.unsubscribe(notifier)
|
178
178
|
|
179
|
-
executed_sql.length.
|
180
|
-
executed_sql.first.
|
179
|
+
expect(executed_sql.length).to eq(1)
|
180
|
+
expect(executed_sql.first).to eq(expected_sql)
|
181
181
|
end
|
182
182
|
end
|
183
183
|
end
|
@@ -203,19 +203,19 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
203
203
|
|
204
204
|
# stub respond_to? to return false since should_not_receive defines the method
|
205
205
|
original_respond_to = Model.method(:respond_to?)
|
206
|
-
Model.
|
206
|
+
allow(Model).to receive(:respond_to?) do |method_name, *args|
|
207
207
|
if method_name == :rebuild_pg_search_documents
|
208
208
|
false
|
209
209
|
else
|
210
210
|
original_respond_to.call(method_name, *args)
|
211
211
|
end
|
212
212
|
end
|
213
|
-
Model.
|
213
|
+
expect(Model).not_to receive(:rebuild_pg_search_documents)
|
214
214
|
|
215
215
|
rebuilder.rebuild
|
216
216
|
|
217
|
-
record1.pg_search_document.
|
218
|
-
record2.pg_search_document.
|
217
|
+
expect(record1.pg_search_document).to be_present
|
218
|
+
expect(record2.pg_search_document).not_to be_present
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
@@ -239,19 +239,19 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
239
239
|
|
240
240
|
# stub respond_to? to return false since should_not_receive defines the method
|
241
241
|
original_respond_to = Model.method(:respond_to?)
|
242
|
-
Model.
|
242
|
+
allow(Model).to receive(:respond_to?) do |method_name, *args|
|
243
243
|
if method_name == :rebuild_pg_search_documents
|
244
244
|
false
|
245
245
|
else
|
246
246
|
original_respond_to.call(method_name, *args)
|
247
247
|
end
|
248
248
|
end
|
249
|
-
Model.
|
249
|
+
expect(Model).not_to receive(:rebuild_pg_search_documents)
|
250
250
|
|
251
251
|
rebuilder.rebuild
|
252
252
|
|
253
|
-
record1.pg_search_document.
|
254
|
-
record2.pg_search_document.
|
253
|
+
expect(record1.pg_search_document).not_to be_present
|
254
|
+
expect(record2.pg_search_document).to be_present
|
255
255
|
end
|
256
256
|
end
|
257
257
|
end
|
@@ -24,7 +24,7 @@ describe PgSearch::Multisearch do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should operate inside a transaction" do
|
27
|
-
model.
|
27
|
+
expect(model).to receive(:transaction).once
|
28
28
|
|
29
29
|
PgSearch::Multisearch.rebuild(model)
|
30
30
|
end
|
@@ -41,14 +41,14 @@ describe PgSearch::Multisearch do
|
|
41
41
|
VALUES
|
42
42
|
('Bar', 123, 'foo', now(), now());
|
43
43
|
SQL
|
44
|
-
PgSearch::Document.count.
|
44
|
+
expect(PgSearch::Document.count).to eq(2)
|
45
45
|
end
|
46
46
|
|
47
47
|
context "when clean_up is not passed" do
|
48
48
|
it "should delete the document for the model" do
|
49
49
|
PgSearch::Multisearch.rebuild(model)
|
50
|
-
PgSearch::Document.count.
|
51
|
-
PgSearch::Document.first.searchable_type.
|
50
|
+
expect(PgSearch::Document.count).to eq(1)
|
51
|
+
expect(PgSearch::Document.first.searchable_type).to eq("Bar")
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -57,8 +57,8 @@ describe PgSearch::Multisearch do
|
|
57
57
|
|
58
58
|
it "should delete the document for the model" do
|
59
59
|
PgSearch::Multisearch.rebuild(model, clean_up)
|
60
|
-
PgSearch::Document.count.
|
61
|
-
PgSearch::Document.first.searchable_type.
|
60
|
+
expect(PgSearch::Document.count).to eq(1)
|
61
|
+
expect(PgSearch::Document.first.searchable_type).to eq("Bar")
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -67,7 +67,7 @@ describe PgSearch::Multisearch do
|
|
67
67
|
|
68
68
|
it "should not delete the document for the model" do
|
69
69
|
PgSearch::Multisearch.rebuild(model, clean_up)
|
70
|
-
PgSearch::Document.count.
|
70
|
+
expect(PgSearch::Document.count).to eq(2)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -84,11 +84,11 @@ describe PgSearch::Multisearch do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should call .rebuild_pg_search_documents and skip the default behavior" do
|
87
|
-
PgSearch::Multisearch.
|
87
|
+
expect(PgSearch::Multisearch).not_to receive(:rebuild_sql)
|
88
88
|
PgSearch::Multisearch.rebuild(model)
|
89
89
|
|
90
90
|
record = PgSearch::Document.find_by_searchable_type_and_searchable_id("Baz", 789)
|
91
|
-
record.content.
|
91
|
+
expect(record.content).to eq("baz")
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
@@ -102,16 +102,13 @@ describe PgSearch::Multisearch do
|
|
102
102
|
|
103
103
|
it "should create new documents for the two models" do
|
104
104
|
PgSearch::Multisearch.rebuild(model)
|
105
|
-
PgSearch::Document.last(2).map(&:searchable).map(&:title).
|
105
|
+
expect(PgSearch::Document.last(2).map(&:searchable).map(&:title)).to match_array(new_models.map(&:title))
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
describe "the generated SQL" do
|
110
110
|
let(:now) { Time.now }
|
111
|
-
|
112
|
-
before do
|
113
|
-
Time.stub(:now => now)
|
114
|
-
end
|
111
|
+
before { allow(Time).to receive(:now).and_return(now) }
|
115
112
|
|
116
113
|
context "with one attribute" do
|
117
114
|
before do
|
@@ -132,11 +129,11 @@ describe PgSearch::Multisearch do
|
|
132
129
|
SQL
|
133
130
|
|
134
131
|
statements = []
|
135
|
-
connection.
|
132
|
+
allow(connection).to receive(:execute) { |sql| statements << sql }
|
136
133
|
|
137
134
|
PgSearch::Multisearch.rebuild(model)
|
138
135
|
|
139
|
-
statements.
|
136
|
+
expect(statements).to include(expected_sql)
|
140
137
|
end
|
141
138
|
end
|
142
139
|
|
@@ -159,11 +156,11 @@ describe PgSearch::Multisearch do
|
|
159
156
|
SQL
|
160
157
|
|
161
158
|
statements = []
|
162
|
-
connection.
|
159
|
+
allow(connection).to receive(:execute) { |sql| statements << sql }
|
163
160
|
|
164
161
|
PgSearch::Multisearch.rebuild(model)
|
165
162
|
|
166
|
-
statements.
|
163
|
+
expect(statements).to include(expected_sql)
|
167
164
|
end
|
168
165
|
end
|
169
166
|
end
|
@@ -21,7 +21,7 @@ describe PgSearch::Multisearchable do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
context "with multisearch disabled" do
|
24
|
-
before { PgSearch.
|
24
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
|
25
25
|
|
26
26
|
it "should not create a PgSearch::Document record" do
|
27
27
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
@@ -33,8 +33,8 @@ describe PgSearch::Multisearchable do
|
|
33
33
|
it "should be associated to the record" do
|
34
34
|
record.save!
|
35
35
|
newest_pg_search_document = PgSearch::Document.last
|
36
|
-
record.pg_search_document.
|
37
|
-
newest_pg_search_document.searchable.
|
36
|
+
expect(record.pg_search_document).to eq(newest_pg_search_document)
|
37
|
+
expect(newest_pg_search_document.searchable).to eq(record)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -43,11 +43,11 @@ describe PgSearch::Multisearchable do
|
|
43
43
|
let!(:record) { ModelThatIsMultisearchable.create! }
|
44
44
|
|
45
45
|
context "when the document is present" do
|
46
|
-
before { record.pg_search_document.
|
46
|
+
before { expect(record.pg_search_document).to be_present }
|
47
47
|
|
48
48
|
describe "saving the record" do
|
49
49
|
it "calls save on the pg_search_document" do
|
50
|
-
record.pg_search_document.
|
50
|
+
expect(record.pg_search_document).to receive(:save)
|
51
51
|
record.save!
|
52
52
|
end
|
53
53
|
|
@@ -56,10 +56,10 @@ describe PgSearch::Multisearchable do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
context "with multisearch disabled" do
|
59
|
-
before { PgSearch.
|
59
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
|
60
60
|
|
61
61
|
it "should not create a PgSearch::Document record" do
|
62
|
-
record.pg_search_document.
|
62
|
+
expect(record.pg_search_document).not_to receive(:save)
|
63
63
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
64
64
|
end
|
65
65
|
end
|
@@ -75,7 +75,7 @@ describe PgSearch::Multisearchable do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
context "with multisearch disabled" do
|
78
|
-
before { PgSearch.
|
78
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
|
79
79
|
|
80
80
|
it "should not create a PgSearch::Document record" do
|
81
81
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
@@ -120,7 +120,7 @@ describe PgSearch::Multisearchable do
|
|
120
120
|
end
|
121
121
|
|
122
122
|
context "with multisearch disabled" do
|
123
|
-
before { PgSearch.
|
123
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
|
124
124
|
|
125
125
|
it "should not create a PgSearch::Document record" do
|
126
126
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
@@ -142,12 +142,12 @@ describe PgSearch::Multisearchable do
|
|
142
142
|
let(:record) { ModelThatIsMultisearchable.create!(:multisearchable => true) }
|
143
143
|
|
144
144
|
context "when the document is present" do
|
145
|
-
before { record.pg_search_document.
|
145
|
+
before { expect(record.pg_search_document).to be_present }
|
146
146
|
|
147
147
|
describe "saving the record" do
|
148
148
|
context "when the condition is true" do
|
149
149
|
it "calls save on the pg_search_document" do
|
150
|
-
record.pg_search_document.
|
150
|
+
expect(record.pg_search_document).to receive(:save)
|
151
151
|
record.save!
|
152
152
|
end
|
153
153
|
|
@@ -160,7 +160,7 @@ describe PgSearch::Multisearchable do
|
|
160
160
|
before { record.multisearchable = false }
|
161
161
|
|
162
162
|
it "calls destroy on the pg_search_document" do
|
163
|
-
record.pg_search_document.
|
163
|
+
expect(record.pg_search_document).to receive(:destroy)
|
164
164
|
record.save!
|
165
165
|
end
|
166
166
|
|
@@ -173,11 +173,11 @@ describe PgSearch::Multisearchable do
|
|
173
173
|
|
174
174
|
context "with multisearch disabled" do
|
175
175
|
before do
|
176
|
-
PgSearch.
|
177
|
-
record.pg_search_document.should_not_receive(:save)
|
176
|
+
allow(PgSearch).to receive(:multisearch_enabled?).and_return(false)
|
178
177
|
end
|
179
178
|
|
180
179
|
it "should not create a PgSearch::Document record" do
|
180
|
+
expect(record.pg_search_document).not_to receive(:save)
|
181
181
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
182
182
|
end
|
183
183
|
end
|
@@ -194,7 +194,7 @@ describe PgSearch::Multisearchable do
|
|
194
194
|
end
|
195
195
|
|
196
196
|
context "with multisearch disabled" do
|
197
|
-
before { PgSearch.
|
197
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
|
198
198
|
|
199
199
|
it "should not create a PgSearch::Document record" do
|
200
200
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
@@ -248,7 +248,7 @@ describe PgSearch::Multisearchable do
|
|
248
248
|
end
|
249
249
|
|
250
250
|
context "with multisearch disabled" do
|
251
|
-
before { PgSearch.
|
251
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
|
252
252
|
|
253
253
|
it "should not create a PgSearch::Document record" do
|
254
254
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
@@ -270,12 +270,12 @@ describe PgSearch::Multisearchable do
|
|
270
270
|
let!(:record) { ModelThatIsMultisearchable.create!(:not_multisearchable => false) }
|
271
271
|
|
272
272
|
context "when the document is present" do
|
273
|
-
before { record.pg_search_document.
|
273
|
+
before { expect(record.pg_search_document).to be_present }
|
274
274
|
|
275
275
|
describe "saving the record" do
|
276
276
|
context "when the condition is false" do
|
277
277
|
it "calls save on the pg_search_document" do
|
278
|
-
record.pg_search_document.
|
278
|
+
expect(record.pg_search_document).to receive(:save)
|
279
279
|
record.save!
|
280
280
|
end
|
281
281
|
|
@@ -285,8 +285,8 @@ describe PgSearch::Multisearchable do
|
|
285
285
|
|
286
286
|
context "with multisearch disabled" do
|
287
287
|
before do
|
288
|
-
PgSearch.
|
289
|
-
record.pg_search_document.
|
288
|
+
allow(PgSearch).to receive(:multisearch_enabled?).and_return(false)
|
289
|
+
expect(record.pg_search_document).not_to receive(:save)
|
290
290
|
end
|
291
291
|
|
292
292
|
it "should not create a PgSearch::Document record" do
|
@@ -299,7 +299,7 @@ describe PgSearch::Multisearchable do
|
|
299
299
|
before { record.not_multisearchable = true }
|
300
300
|
|
301
301
|
it "calls destroy on the pg_search_document" do
|
302
|
-
record.pg_search_document.
|
302
|
+
expect(record.pg_search_document).to receive(:destroy)
|
303
303
|
record.save!
|
304
304
|
end
|
305
305
|
|
@@ -332,7 +332,8 @@ describe PgSearch::Multisearchable do
|
|
332
332
|
end
|
333
333
|
|
334
334
|
context "with multisearch disabled" do
|
335
|
-
before { PgSearch.
|
335
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
|
336
|
+
|
336
337
|
it "should not create a PgSearch::Document record" do
|
337
338
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
338
339
|
end
|
@@ -377,7 +378,7 @@ describe PgSearch::Multisearchable do
|
|
377
378
|
end
|
378
379
|
|
379
380
|
context "with multisearch disabled" do
|
380
|
-
before { PgSearch.
|
381
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
|
381
382
|
|
382
383
|
it "should not create a PgSearch::Document record" do
|
383
384
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
@@ -399,12 +400,12 @@ describe PgSearch::Multisearchable do
|
|
399
400
|
let!(:record) { ModelThatIsMultisearchable.create!(:multisearchable => true) }
|
400
401
|
|
401
402
|
context "when the document is present" do
|
402
|
-
before { record.pg_search_document.
|
403
|
+
before { expect(record.pg_search_document).to be_present }
|
403
404
|
|
404
405
|
describe "saving the record" do
|
405
406
|
context "when the condition is true" do
|
406
407
|
it "calls save on the pg_search_document" do
|
407
|
-
record.pg_search_document.
|
408
|
+
expect(record.pg_search_document).to receive(:save)
|
408
409
|
record.save!
|
409
410
|
end
|
410
411
|
|
@@ -414,8 +415,8 @@ describe PgSearch::Multisearchable do
|
|
414
415
|
|
415
416
|
context "with multisearch disabled" do
|
416
417
|
before do
|
417
|
-
PgSearch.
|
418
|
-
record.pg_search_document.
|
418
|
+
allow(PgSearch).to receive(:multisearch_enabled?).and_return(false)
|
419
|
+
expect(record.pg_search_document).not_to receive(:save)
|
419
420
|
end
|
420
421
|
|
421
422
|
it "should not create a PgSearch::Document record" do
|
@@ -428,7 +429,7 @@ describe PgSearch::Multisearchable do
|
|
428
429
|
before { record.multisearchable = false }
|
429
430
|
|
430
431
|
it "calls destroy on the pg_search_document" do
|
431
|
-
record.pg_search_document.
|
432
|
+
expect(record.pg_search_document).to receive(:destroy)
|
432
433
|
record.save!
|
433
434
|
end
|
434
435
|
|
@@ -446,7 +447,7 @@ describe PgSearch::Multisearchable do
|
|
446
447
|
|
447
448
|
describe "saving the record" do
|
448
449
|
context "with multisearch enabled" do
|
449
|
-
before { PgSearch.
|
450
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(true) }
|
450
451
|
|
451
452
|
context "when the condition is true" do
|
452
453
|
it "should create a PgSearch::Document record" do
|
@@ -464,7 +465,7 @@ describe PgSearch::Multisearchable do
|
|
464
465
|
end
|
465
466
|
|
466
467
|
context "with multisearch disabled" do
|
467
|
-
before { PgSearch.
|
468
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
|
468
469
|
|
469
470
|
it "should not create a PgSearch::Document record" do
|
470
471
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
@@ -517,7 +518,7 @@ describe PgSearch::Multisearchable do
|
|
517
518
|
end
|
518
519
|
|
519
520
|
context "with multisearch disabled" do
|
520
|
-
before { PgSearch.
|
521
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
|
521
522
|
|
522
523
|
it "should not create a PgSearch::Document record" do
|
523
524
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
@@ -531,14 +532,14 @@ describe PgSearch::Multisearchable do
|
|
531
532
|
let!(:record) { ModelThatIsMultisearchable.create!(:not_multisearchable => false) }
|
532
533
|
|
533
534
|
context "when the document is present" do
|
534
|
-
before { record.pg_search_document.
|
535
|
+
before { expect(record.pg_search_document).to be_present }
|
535
536
|
|
536
537
|
describe "saving the record" do
|
537
538
|
context "when the condition is true" do
|
538
539
|
before { record.not_multisearchable = true }
|
539
540
|
|
540
541
|
it "calls destroy on the pg_search_document" do
|
541
|
-
record.pg_search_document.
|
542
|
+
expect(record.pg_search_document).to receive(:destroy)
|
542
543
|
record.save!
|
543
544
|
end
|
544
545
|
|
@@ -551,7 +552,7 @@ describe PgSearch::Multisearchable do
|
|
551
552
|
|
552
553
|
context "when the condition is false" do
|
553
554
|
it "calls save on the pg_search_document" do
|
554
|
-
record.pg_search_document.
|
555
|
+
expect(record.pg_search_document).to receive(:save)
|
555
556
|
record.save!
|
556
557
|
end
|
557
558
|
|
@@ -561,8 +562,8 @@ describe PgSearch::Multisearchable do
|
|
561
562
|
|
562
563
|
context "with multisearch disabled" do
|
563
564
|
before do
|
564
|
-
PgSearch.
|
565
|
-
record.pg_search_document.
|
565
|
+
allow(PgSearch).to receive(:multisearch_enabled?).and_return(false)
|
566
|
+
expect(record.pg_search_document).not_to receive(:save)
|
566
567
|
end
|
567
568
|
|
568
569
|
it "should not create a PgSearch::Document record" do
|
@@ -578,7 +579,7 @@ describe PgSearch::Multisearchable do
|
|
578
579
|
|
579
580
|
describe "saving the record" do
|
580
581
|
context "with multisearch enabled" do
|
581
|
-
before { PgSearch.
|
582
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(true) }
|
582
583
|
|
583
584
|
context "when the condition is true" do
|
584
585
|
before { record.not_multisearchable = true }
|
@@ -594,7 +595,7 @@ describe PgSearch::Multisearchable do
|
|
594
595
|
end
|
595
596
|
|
596
597
|
context "with multisearch disabled" do
|
597
|
-
before { PgSearch.
|
598
|
+
before { allow(PgSearch).to receive(:multisearch_enabled?).and_return(false) }
|
598
599
|
|
599
600
|
it "should not create a PgSearch::Document record" do
|
600
601
|
expect { record.save! }.not_to change(PgSearch::Document, :count)
|
@@ -10,18 +10,18 @@ describe PgSearch::Normalizer do
|
|
10
10
|
node = Arel::Nodes::NamedFunction.new("foo", ["bar"])
|
11
11
|
|
12
12
|
normalizer = PgSearch::Normalizer.new(config)
|
13
|
-
normalizer.add_normalization(node).
|
13
|
+
expect(normalizer.add_normalization(node)).to eq("unaccent(foo('bar'))")
|
14
14
|
end
|
15
15
|
|
16
16
|
context "when a custom unaccent function is specified" do
|
17
17
|
it "wraps the expression in that function" do
|
18
|
-
PgSearch.
|
18
|
+
allow(PgSearch).to receive(:unaccent_function).and_return("my_unaccent")
|
19
19
|
node = Arel::Nodes::NamedFunction.new("foo", ["bar"])
|
20
20
|
|
21
21
|
config = double("config", :ignore => [:accents], :postgresql_version => 90000)
|
22
22
|
|
23
23
|
normalizer = PgSearch::Normalizer.new(config)
|
24
|
-
normalizer.add_normalization(node).
|
24
|
+
expect(normalizer.add_normalization(node)).to eq("my_unaccent(foo('bar'))")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -31,17 +31,17 @@ describe PgSearch::Normalizer do
|
|
31
31
|
config = double("config", :ignore => [:accents], :postgresql_version => 90000)
|
32
32
|
|
33
33
|
normalizer = PgSearch::Normalizer.new(config)
|
34
|
-
normalizer.add_normalization("foo").
|
34
|
+
expect(normalizer.add_normalization("foo")).to eq("unaccent(foo)")
|
35
35
|
end
|
36
36
|
|
37
37
|
context "when a custom unaccent function is specified" do
|
38
38
|
it "wraps the expression in that function" do
|
39
|
-
PgSearch.
|
39
|
+
allow(PgSearch).to receive(:unaccent_function).and_return("my_unaccent")
|
40
40
|
|
41
41
|
config = double("config", :ignore => [:accents], :postgresql_version => 90000)
|
42
42
|
|
43
43
|
normalizer = PgSearch::Normalizer.new(config)
|
44
|
-
normalizer.add_normalization("foo").
|
44
|
+
expect(normalizer.add_normalization("foo")).to eq("my_unaccent(foo)")
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -52,7 +52,7 @@ describe PgSearch::Normalizer do
|
|
52
52
|
config = double("config", :ignore => [], :postgresql_version => 90000)
|
53
53
|
|
54
54
|
normalizer = PgSearch::Normalizer.new(config)
|
55
|
-
normalizer.add_normalization("foo").
|
55
|
+
expect(normalizer.add_normalization("foo")).to eq("foo")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -74,7 +74,7 @@ describe PgSearch::Normalizer do
|
|
74
74
|
config = double("config", :ignore => [], :postgresql_version => 90000)
|
75
75
|
|
76
76
|
normalizer = PgSearch::Normalizer.new(config)
|
77
|
-
normalizer.add_normalization("foo").
|
77
|
+
expect(normalizer.add_normalization("foo")).to eq("foo")
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|