Commit a15523ec585fea7b5274632b204028d6888c3013

Authored by Luke Baker
1 parent 3b0c0ec4

split single test into 3 different ones

Showing 1 changed file with 23 additions and 11 deletions   Show diff stats
lib/tasks/test_api.rake
... ... @@ -171,7 +171,9 @@ namespace :test_api do
171 171 :check_each_choice_appears_within_n_stddevs => "Ensure each choice appears within 6 standard deviations",
172 172 :check_each_choice_equally_likely_to_appear_left_or_right => "Ensure each choice is equally likely to appear on left or right",
173 173 :check_prompt_cache_hit_rate => "Check prompt cache hit rate",
174   - :check_object_counter_cache_values_match_actual_values => "Check that object counter cache values match actual values",
  174 + :check_prompt_counter_cache => "Verify that prompt counter cache is accurate",
  175 + :check_vote_counter_cache => "Verify that vote counter cache is accurate",
  176 + :check_choice_counter_cache => "Verify that choice counter cache is accurate",
175 177 :wins_and_losses_equals_two_times_wins => "Verifies that wins and losses are equal to 2 times the total number of wins",
176 178 :wins_and_losses_is_even => "Verify that sum of wins and losses is even",
177 179 :wins_and_losses_equals_two_times_vote_count => "Verify that sum of wins and losses equals two times the vote count",
... ... @@ -377,35 +379,45 @@ namespace :test_api do
377 379 return error_message.blank? ? [success_message, false] : [error_message, true]
378 380 end
379 381  
380   - def check_object_counter_cache_values_match_actual_values(question)
381   - # FIXME: split up into several tests
  382 + def check_prompt_counter_cache(question)
382 383 error_message = ""
383   - success_message = "All cached object values match actual values within database"
  384 + success_message = "Prompt counter cache equals prompt count in database"
  385 +
384 386 # Checks that counter_cache is working as expected
385 387 cached_prompts_size = question.prompts.size
386 388 actual_prompts_size = question.prompts.count
387 389  
388 390 if cached_prompts_size != actual_prompts_size
389   - error_message += "Error! Question #{question.id} has an inconsistent # of prompts! cached#: #{cached_prompts_size}, actual#: #{actual_prompts_size}\n"
  391 + error_message = "Error! Question #{question.id} has an inconsistent # of prompts! cached#: #{cached_prompts_size}, actual#: #{actual_prompts_size}\n"
390 392 end
  393 + return error_message.blank? ? [success_message, false] : [error_message, true]
  394 + end
391 395  
  396 + def check_vote_counter_cache(question)
  397 + error_message = ""
  398 + success_message = "Vote counter cache equals vote count in database"
  399 +
  400 + # Checks that counter_cache is working as expected
392 401 cached_votes_size = question.votes.size
393 402 actual_votes_size = question.votes.count
394 403  
395 404 if cached_votes_size != actual_votes_size
396   - error_message += "Error! Question #{question.id} has an inconsistent # of votes! cached#: #{cached_votes_size}, actual#: #{actual_votes_size}\n"
  405 + error_message = "Error! Question #{question.id} has an inconsistent # of votes! cached#: #{cached_votes_size}, actual#: #{actual_votes_size}\n"
397 406 end
  407 + return error_message.blank? ? [success_message, false] : [error_message, true]
  408 + end
  409 +
  410 + def check_choice_counter_cache(question)
  411 + error_message = ""
  412 + success_message = "Choice counter cache equals choice count in database"
398 413  
  414 + # Checks that counter_cache is working as expected
399 415 cached_choices_size = question.choices.size
400 416 actual_choices_size = question.choices.count
401 417  
402 418 if cached_choices_size != actual_choices_size
403   - error_message+= "Error! Question #{question.id} has an inconsistent # of choices! cached#: #{cached_choices_size}, actual#: #{actual_choices_size}\n"
  419 + error_message = "Error! Question #{question.id} has an inconsistent # of choices! cached#: #{cached_choices_size}, actual#: #{actual_choices_size}\n"
404 420 end
405   -
406   - #if cached_prompts_size != question.choices.size **2 - question.choices.size
407   - # error_message += "Error! Question #{question.id} has an incorrect number of prompts! Expected #{question.choices.size **2 - question.choices.size}, Actual: #{cached_prompts_size}\n"
408   - #end
409 421 return error_message.blank? ? [success_message, false] : [error_message, true]
410 422 end
411 423 end
... ...