diff --git a/app/models/question.rb b/app/models/question.rb index 0f85e8d..046bed9 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -413,8 +413,11 @@ class Question < ActiveRecord::Base end def pop_prompt_queue - prompt_id = $redis.lpop(self.pq_key) - prompt = prompt_id.nil? ? nil : Prompt.find(prompt_id.to_i) + begin + prompt_id = $redis.lpop(self.pq_key) + prompt = prompt_id.nil? ? nil : Prompt.find(prompt_id.to_i) + end until (prompt.nil? || prompt.active?) + prompt end def record_prompt_cache_miss diff --git a/spec/models/question_spec.rb b/spec/models/question_spec.rb index 217ae16..b08c43b 100644 --- a/spec/models/question_spec.rb +++ b/spec/models/question_spec.rb @@ -199,6 +199,15 @@ describe Question do @catchup_q.pop_prompt_queue.should == nil end + it "should not return prompts from queue that are deactivated" do + @catchup_q.clear_prompt_queue + @catchup_q.pop_prompt_queue.should == nil + prompt1 = @catchup_q.add_prompt_to_queue + + prompt = Prompt.find(prompt1) + prompt.left_choice.deactivate! + @catchup_q.choose_prompt.should_not == prompt1 + end end context "exporting data" do -- libgit2 0.21.2