Skip to content

Commit b6920c3

Browse files
committed
If ever comparing multiple search results, ensure that at least 20 results come back in the search. Also, validate one search before making a second search, to fail faster without hitting FA so much.
1 parent 904174d commit b6920c3

1 file changed

Lines changed: 33 additions & 12 deletions

File tree

tests/integration/search_spec.rb

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ def search_with_retry(args)
6969
results1 = search_with_retry({ "q" => "YCH" })
7070
expect(results1).to be_instance_of Array
7171
expect(results1).not_to be_empty
72+
expect(results1.length).to be >= 20
7273
# Get page 2
7374
results2 = search_with_retry({ "q" => "YCH", "page" => "2" })
7475
expect(results2).to be_instance_of Array
7576
expect(results2).not_to be_empty
77+
expect(results2.length).to be >= 20
7678
# Check they're different enough
7779
expect(results1).to be_different_results_to(results2)
7880
end
@@ -121,12 +123,14 @@ def search_with_retry(args)
121123
end
122124

123125
it "defaults to ordering by date desc" do
124-
results = search_with_retry({ "q" => "YCH", "perpage" => "72" })
125-
expect(results).to be_instance_of Array
126-
expect(results).not_to be_empty
127-
results_date = search_with_retry({ "q" => "YCH", "perpage" => "72", "order_by" => "date" })
126+
results = search_with_retry({ "q" => "YCH", "perpage" => "24" })
128127
expect(results).to be_instance_of Array
129128
expect(results).not_to be_empty
129+
expect(results.length).to be >= 20
130+
results_date = search_with_retry({ "q" => "YCH", "perpage" => "24", "order_by" => "date" })
131+
expect(results_date).to be_instance_of Array
132+
expect(results_date).not_to be_empty
133+
expect(results_date.length).to be >= 20
130134

131135
# Check they're similar enough
132136
expect(results).to be_similar_results_to(results_date)
@@ -141,16 +145,21 @@ def search_with_retry(args)
141145

142146
it "can search by relevancy and popularity, which give a different order to date" do
143147
results_date = search_with_retry({ "q" => "YCH", "perpage" => "24", "order_by" => "date" })
148+
expect(results_date.length).to be >= 20
144149
results_rele = search_with_retry({ "q" => "YCH", "perpage" => "24", "order_by" => "relevancy" })
150+
expect(results_rele.length).to be >= 20
145151
results_popu = search_with_retry({ "q" => "YCH", "perpage" => "24", "order_by" => "popularity" })
152+
expect(results_popu.length).to be >= 20
146153
expect(results_date).to be_different_results_to(results_rele)
147154
expect(results_rele).to be_different_results_to(results_popu)
148155
expect(results_popu).to be_different_results_to(results_date)
149156
end
150157

151158
it "can specify order direction as ascending" do
152159
results_asc = search_with_retry({ "q" => "YCH", "perpage" => "24", "order_direction" => "asc" })
160+
expect(results_asc.length).to be >= 20
153161
results_desc = search_with_retry({ "q" => "YCH", "perpage" => "24", "order_direction" => "desc" })
162+
expect(results_desc.length).to be >= 20
154163
expect(results_asc).to be_different_results_to(results_desc)
155164
end
156165

@@ -177,10 +186,14 @@ def search_with_retry(args)
177186
end
178187

179188
it "can specify search mode for the terms in the query" do
180-
extended_or_results = search_with_retry({ "q" => "deer | lion", "perpage" => 72 })
181-
extended_and_results = search_with_retry({ "q" => "deer & lion", "perpage" => 72 })
182-
or_results = search_with_retry({ "q" => "deer lion", "perpage" => 72, "mode" => "any" })
183-
and_results = search_with_retry({ "q" => "deer lion", "perpage" => 72, "mode" => "all" })
189+
extended_or_results = search_with_retry({ "q" => "deer | lion", "perpage" => 24 })
190+
expect(extended_or_results.length).to be >= 20
191+
extended_and_results = search_with_retry({ "q" => "deer & lion", "perpage" => 24 })
192+
expect(extended_and_results.length).to be >= 20
193+
or_results = search_with_retry({ "q" => "deer lion", "perpage" => 24, "mode" => "any" })
194+
expect(or_results.length).to be >= 20
195+
and_results = search_with_retry({ "q" => "deer lion", "perpage" => 24, "mode" => "all" })
196+
expect(and_results.length).to be >= 20
184197

185198
expect(extended_and_results).to be_different_results_to(extended_or_results)
186199
expect(and_results).to be_different_results_to(or_results)
@@ -191,7 +204,9 @@ def search_with_retry(args)
191204

192205
it "can specify ratings to display, and honours that selection" do
193206
only_adult = search_with_retry({ "q" => "ych", "perpage" => 24, "rating" => "adult" })
207+
expect(only_adult.length).to be >= 20
194208
only_sfw_or_mature = search_with_retry({ "q" => "ych", "perpage" => 24, "rating" => "mature,general" })
209+
expect(only_sfw_or_mature.length).to be >= 20
195210

196211
expect(only_adult).to be_different_results_to(only_sfw_or_mature)
197212

@@ -229,14 +244,20 @@ def search_with_retry(args)
229244
end
230245

231246
it "can specify a content type for results, only returns that content type" do
232-
results_poem = search_with_retry({ "q" => "deer", "perpage" => 72, "type" => "poetry" })
233-
results_photo = search_with_retry({ "q" => "deer", "perpage" => 72, "type" => "photo" })
247+
results_poem = search_with_retry({ "q" => "deer", "perpage" => 24, "type" => "poetry" })
248+
expect(results_poem.length).to be >= 20
249+
results_photo = search_with_retry({ "q" => "deer", "perpage" => 24, "type" => "photo" })
250+
expect(results_photo.length).to be >= 20
251+
234252
expect(results_photo).to be_different_results_to(results_poem)
235253
end
236254

237255
it "can specify multiple content types for results, and only displays those types" do
238-
results_image = search_with_retry({ "q" => "deer", "perpage" => 72, "type" => "photo,art" })
239-
results_swf_music = search_with_retry({ "q" => "deer", "perpage" => 72, "type" => "flash,music" })
256+
results_image = search_with_retry({ "q" => "deer", "perpage" => 24, "type" => "photo,art" })
257+
expect(results_image.length).to be >= 20
258+
results_swf_music = search_with_retry({ "q" => "deer", "perpage" => 24, "type" => "flash,music" })
259+
expect(results_swf_music.length).to be >= 20
260+
240261
expect(results_image).to be_different_results_to(results_swf_music)
241262
end
242263

0 commit comments

Comments
 (0)