Commit 408763a62696b6a12700ba9829a161ee167efabc
1 parent
d7606f19
Exists in
master
and in
1 other branch
add test to verify cached prompt count on choices
also update rake tasks to not use environment variables
Showing
1 changed file
with
24 additions
and
4 deletions
Show diff stats
lib/tasks/test_api.rake
| @@ -7,6 +7,7 @@ namespace :test_api do | @@ -7,6 +7,7 @@ namespace :test_api do | ||
| 7 | task :verify_appearance_vote_prompt_ids => :environment do | 7 | task :verify_appearance_vote_prompt_ids => :environment do |
| 8 | puts verify_appearance_vote_prompt_ids().inspect | 8 | puts verify_appearance_vote_prompt_ids().inspect |
| 9 | end | 9 | end |
| 10 | + | ||
| 10 | def verify_appearance_vote_prompt_ids | 11 | def verify_appearance_vote_prompt_ids |
| 11 | bad_records = Vote.connection.select_all " | 12 | bad_records = Vote.connection.select_all " |
| 12 | SELECT votes.id | 13 | SELECT votes.id |
| @@ -36,9 +37,23 @@ namespace :test_api do | @@ -36,9 +37,23 @@ namespace :test_api do | ||
| 36 | return error_message.blank? ? [success_message, false] : [error_message, true] | 37 | return error_message.blank? ? [success_message, false] : [error_message, true] |
| 37 | end | 38 | end |
| 38 | 39 | ||
| 40 | + desc "Ensure that cached prompt counts are valid for a choice" | ||
| 41 | + task :verify_cached_prompt_counts, [:choice_id] => :environment do |t, args| | ||
| 42 | + choice = Choice.find(args[:choice_id]) | ||
| 43 | + puts verify_cached_prompt_counts(choice).inspect | ||
| 44 | + end | ||
| 45 | + | ||
| 46 | + def verify_cached_prompt_counts(choice) | ||
| 47 | + success_message = "Choice has accurate prompt cache count" | ||
| 48 | + if choice.prompts_on_the_left.count != choice.prompts_on_the_left_count || choice.prompts_on_the_right.count != choice.prompts_on_the_right_count | ||
| 49 | + error_message = "Choice #{choice.id} in Question ##{choice.question_id} has inaccurate prompt count cache" | ||
| 50 | + end | ||
| 51 | + return error_message.blank? ? [success_message, false] : [error_message, true] | ||
| 52 | + end | ||
| 53 | + | ||
| 39 | desc "Ensure that an idea: appearances on left + appearances on right >= (wins + losses + skips)" | 54 | desc "Ensure that an idea: appearances on left + appearances on right >= (wins + losses + skips)" |
| 40 | - task :verify_choice_appearances_and_votes => :environment do | ||
| 41 | - choice = Choice.find(ENV["choice_id"]) | 55 | + task :verify_choice_appearances_and_votes, [:choice_id] => :environment do |t, args| |
| 56 | + choice = Choice.find(args[:choice_id]) | ||
| 42 | puts verify_choice_appearances_and_votes(choice).inspect | 57 | puts verify_choice_appearances_and_votes(choice).inspect |
| 43 | end | 58 | end |
| 44 | 59 | ||
| @@ -462,6 +477,11 @@ namespace :test_api do | @@ -462,6 +477,11 @@ namespace :test_api do | ||
| 462 | end | 477 | end |
| 463 | end | 478 | end |
| 464 | 479 | ||
| 480 | + message, error_occurred = verify_cached_prompt_counts(choice) | ||
| 481 | + if error_occurred | ||
| 482 | + error_message += message + "\n" | ||
| 483 | + end | ||
| 484 | + | ||
| 465 | 485 | ||
| 466 | if cached_score >= 50 | 486 | if cached_score >= 50 |
| 467 | total_scores_gte_fifty +=1 | 487 | total_scores_gte_fifty +=1 |
| @@ -642,8 +662,8 @@ namespace :test_api do | @@ -642,8 +662,8 @@ namespace :test_api do | ||
| 642 | end | 662 | end |
| 643 | 663 | ||
| 644 | desc "Ensure that a question has: answered_appearances == votes + skips" | 664 | desc "Ensure that a question has: answered_appearances == votes + skips" |
| 645 | - task :answered_appearances_equals_votes_and_skips => :environment do | ||
| 646 | - question = Question.find(ENV["question_id"]) | 665 | + task :answered_appearances_equals_votes_and_skips, [:question_id] => :environment do |t, args| |
| 666 | + question = Question.find(args[:question_id]) | ||
| 647 | puts answered_appearances_equals_votes_and_skips(question).inspect | 667 | puts answered_appearances_equals_votes_and_skips(question).inspect |
| 648 | end | 668 | end |
| 649 | 669 |