Commit bacbab7df4150342ef885563fd4c60c174e6c352

Authored by Luke Baker
1 parent 7c480be5

add new test for appearances count and votes+skips

Showing 1 changed file with 25 additions and 0 deletions   Show diff stats
lib/tasks/test_api.rake
... ... @@ -42,6 +42,26 @@ namespace :test_api do
42 42 return error_message.blank? ? [success_message, false] : [error_message, true]
43 43 end
44 44  
  45 + desc "Ensure that an idea: appearances on left + appearances on right >= (wins + losses + skips)"
  46 + task :verify_choice_appearances_and_votes => :environment do
  47 + choice = Choice.find(ENV["choice_id"])
  48 + puts verify_choice_appearances_and_votes(choice).inspect
  49 + end
  50 +
  51 + def verify_choice_appearances_and_votes(choice)
  52 + success_message = "Choice has more appearances than votes and skips"
  53 + prompts_on_left = choice.prompts_on_the_left { |p| p.id }
  54 + prompts_on_right = choice.prompts_on_the_right { |p| p.id }
  55 + all_prompt_ids = prompts_on_left + prompts_on_right
  56 + all_appearances = Appearance.count(:conditions => { :prompt_id => all_prompt_ids})
  57 + skips = Skip.count(:conditions => {:prompt_id => all_prompt_ids})
  58 +
  59 + if all_appearances < choice.wins + choice.losses + skips
  60 + error_message = "Choice #{choice.id} in Question ##{choice.question_id} has fewer appearances than wins + losses + skips"
  61 + end
  62 + return error_message.blank? ? [success_message, false] : [error_message, true]
  63 + end
  64 +
45 65 desc "Don't run unless you know what you are doing"
46 66 task(:generate_lots_of_votes => :environment) do
47 67 if Rails.env.production?
... ... @@ -439,6 +459,11 @@ namespace :test_api do
439 459 print "Either 0 or 100 This score is wrong! #{choice.id} , Question ID: #{question.id}, #{cached_score}, #{generated_score}, updated: #{choice.updated_at}\n"
440 460 end
441 461  
  462 + message, error_occurred = verify_choice_appearances_and_votes(choice)
  463 + if error_occurred
  464 + error_message += message
  465 + end
  466 +
442 467  
443 468 if cached_score >= 50
444 469 total_scores_gte_fifty +=1
... ...