Commit 580db1c8bdb6b787faca389f3909fefcd95195ce
1 parent
6bc7324e
Exists in
master
and in
1 other branch
add tests to ensure we only process active choices when using the
catchup algorithm
Showing
2 changed files
with
20 additions
and
3 deletions
Show diff stats
spec/factories.rb
| @@ -20,6 +20,12 @@ Factory.define(:aoi_question, :parent => :question) do |f| | @@ -20,6 +20,12 @@ Factory.define(:aoi_question, :parent => :question) do |f| | ||
| 20 | :creator => question.creator, | 20 | :creator => question.creator, |
| 21 | :active => true) | 21 | :active => true) |
| 22 | end | 22 | end |
| 23 | + 2.times do | ||
| 24 | + result << Factory.build(:choice, | ||
| 25 | + :question => question.result, | ||
| 26 | + :creator => question.creator, | ||
| 27 | + :active => false) | ||
| 28 | + end | ||
| 23 | result | 29 | result |
| 24 | end | 30 | end |
| 25 | f.prompts do |question| | 31 | f.prompts do |question| |
spec/models/question_spec.rb
| @@ -47,7 +47,7 @@ describe Question do | @@ -47,7 +47,7 @@ describe Question do | ||
| 47 | end | 47 | end |
| 48 | 48 | ||
| 49 | it "should raise runtime exception if there is no possible prompt to choose" do | 49 | it "should raise runtime exception if there is no possible prompt to choose" do |
| 50 | - @question.choices.first.deactivate! | 50 | + @question.choices.active.each{|c| c.deactivate!} |
| 51 | @question.reload | 51 | @question.reload |
| 52 | lambda { @question.choose_prompt}.should raise_error(RuntimeError) | 52 | lambda { @question.choose_prompt}.should raise_error(RuntimeError) |
| 53 | 53 | ||
| @@ -211,8 +211,8 @@ describe Question do | @@ -211,8 +211,8 @@ describe Question do | ||
| 211 | @catchup_q.uses_catchup = true | 211 | @catchup_q.uses_catchup = true |
| 212 | @catchup_q.save! | 212 | @catchup_q.save! |
| 213 | 213 | ||
| 214 | - # 2 ideas already exist, so this will make an even hundred | ||
| 215 | - 98.times.each do |num| | 214 | + # 4 ideas already exist, so this will make an even hundred |
| 215 | + 96.times.each do |num| | ||
| 216 | @catchup_q.site.create_choice("visitor identifier", @catchup_q, {:data => num.to_s, :local_identifier => "exmaple"}) | 216 | @catchup_q.site.create_choice("visitor identifier", @catchup_q, {:data => num.to_s, :local_identifier => "exmaple"}) |
| 217 | end | 217 | end |
| 218 | @catchup_q.reload | 218 | @catchup_q.reload |
| @@ -241,6 +241,17 @@ describe Question do | @@ -241,6 +241,17 @@ describe Question do | ||
| 241 | (sum - 1.0).abs.should < 0.000001 | 241 | (sum - 1.0).abs.should < 0.000001 |
| 242 | end | 242 | end |
| 243 | 243 | ||
| 244 | + it "should not have any inactive choices in the the vector of weights" do | ||
| 245 | + weights = @catchup_q.catchup_prompts_weights | ||
| 246 | + weights.each do |items, value| | ||
| 247 | + left_choice_id, right_choice_id = items.split(", ") | ||
| 248 | + cl = Choice.find(left_choice_id) | ||
| 249 | + cr = Choice.find(right_choice_id) | ||
| 250 | + cl.active?.should == true | ||
| 251 | + cr.active?.should == true | ||
| 252 | + end | ||
| 253 | + end | ||
| 254 | + | ||
| 244 | it "should allow the prompt queue to be cleared" do | 255 | it "should allow the prompt queue to be cleared" do |
| 245 | @catchup_q.add_prompt_to_queue | 256 | @catchup_q.add_prompt_to_queue |
| 246 | @catchup_q.clear_prompt_queue | 257 | @catchup_q.clear_prompt_queue |