Commit d0e9f5a930f43d1a5f9085f4aa29d237c8e8a488
1 parent
d1af06d3
Exists in
master
and in
1 other branch
Fixing edge case when prompts are deactivated after being added to queue
Showing
2 changed files
with
14 additions
and
2 deletions
Show diff stats
app/models/question.rb
@@ -413,8 +413,11 @@ class Question < ActiveRecord::Base | @@ -413,8 +413,11 @@ class Question < ActiveRecord::Base | ||
413 | end | 413 | end |
414 | 414 | ||
415 | def pop_prompt_queue | 415 | def pop_prompt_queue |
416 | - prompt_id = $redis.lpop(self.pq_key) | ||
417 | - prompt = prompt_id.nil? ? nil : Prompt.find(prompt_id.to_i) | 416 | + begin |
417 | + prompt_id = $redis.lpop(self.pq_key) | ||
418 | + prompt = prompt_id.nil? ? nil : Prompt.find(prompt_id.to_i) | ||
419 | + end until (prompt.nil? || prompt.active?) | ||
420 | + prompt | ||
418 | end | 421 | end |
419 | 422 | ||
420 | def record_prompt_cache_miss | 423 | def record_prompt_cache_miss |
spec/models/question_spec.rb
@@ -199,6 +199,15 @@ describe Question do | @@ -199,6 +199,15 @@ describe Question do | ||
199 | 199 | ||
200 | @catchup_q.pop_prompt_queue.should == nil | 200 | @catchup_q.pop_prompt_queue.should == nil |
201 | end | 201 | end |
202 | + it "should not return prompts from queue that are deactivated" do | ||
203 | + @catchup_q.clear_prompt_queue | ||
204 | + @catchup_q.pop_prompt_queue.should == nil | ||
205 | + prompt1 = @catchup_q.add_prompt_to_queue | ||
206 | + | ||
207 | + prompt = Prompt.find(prompt1) | ||
208 | + prompt.left_choice.deactivate! | ||
209 | + @catchup_q.choose_prompt.should_not == prompt1 | ||
210 | + end | ||
202 | end | 211 | end |
203 | 212 | ||
204 | context "exporting data" do | 213 | context "exporting data" do |