diff --git a/lib/tasks/test_api.rake b/lib/tasks/test_api.rake index 71ebdbd..0d7b8ec 100644 --- a/lib/tasks/test_api.rake +++ b/lib/tasks/test_api.rake @@ -42,6 +42,26 @@ namespace :test_api do return error_message.blank? ? [success_message, false] : [error_message, true] end + desc "Ensure that an idea: appearances on left + appearances on right >= (wins + losses + skips)" + task :verify_choice_appearances_and_votes => :environment do + choice = Choice.find(ENV["choice_id"]) + puts verify_choice_appearances_and_votes(choice).inspect + end + + def verify_choice_appearances_and_votes(choice) + success_message = "Choice has more appearances than votes and skips" + prompts_on_left = choice.prompts_on_the_left { |p| p.id } + prompts_on_right = choice.prompts_on_the_right { |p| p.id } + all_prompt_ids = prompts_on_left + prompts_on_right + all_appearances = Appearance.count(:conditions => { :prompt_id => all_prompt_ids}) + skips = Skip.count(:conditions => {:prompt_id => all_prompt_ids}) + + if all_appearances < choice.wins + choice.losses + skips + error_message = "Choice #{choice.id} in Question ##{choice.question_id} has fewer appearances than wins + losses + skips" + end + return error_message.blank? ? [success_message, false] : [error_message, true] + end + desc "Don't run unless you know what you are doing" task(:generate_lots_of_votes => :environment) do if Rails.env.production? @@ -439,6 +459,11 @@ namespace :test_api do print "Either 0 or 100 This score is wrong! #{choice.id} , Question ID: #{question.id}, #{cached_score}, #{generated_score}, updated: #{choice.updated_at}\n" end + message, error_occurred = verify_choice_appearances_and_votes(choice) + if error_occurred + error_message += message + end + if cached_score >= 50 total_scores_gte_fifty +=1 -- libgit2 0.21.2