Commit beb3b15fdf53fbd43b334b6040bf5604514e8747

Authored by Luke Baker
1 parent c99242f9

test ensures answered_appearances == skips + votes

Add test that checks per question instead of globally
Showing 1 changed file with 27 additions and 0 deletions   Show diff stats
lib/tasks/test_api.rake
... ... @@ -339,6 +339,13 @@ namespace :test_api do
339 339 successes << message
340 340 end
341 341  
  342 + message, error_occurred = answered_appearances_equals_votes_and_skips(question)
  343 + if error_occurred
  344 + errors << message
  345 + else
  346 + successes << message
  347 + end
  348 +
342 349  
343 350 message, error_occurred = check_each_choice_appears_within_n_stddevs(question)
344 351 if error_occurred
... ... @@ -650,6 +657,26 @@ namespace :test_api do
650 657 #end
651 658 return error_message.blank? ? [success_message, false] : [error_message, true]
652 659 end
  660 +
  661 + desc "Ensure that a question has: answered_appearances == votes + skips"
  662 + task :answered_appearances_equals_votes_and_skips => :environment do
  663 + question = Question.find(ENV["question_id"])
  664 + puts answered_appearances_equals_votes_and_skips(question).inspect
  665 + end
  666 +
  667 + def answered_appearances_equals_votes_and_skips(question)
  668 + error_message = ""
  669 + success_message = "All vote and skip objects have an associated appearance object"
  670 + total_answered_appearances = Appearance.count(:conditions => ['answerable_id IS NOT NULL AND question_id = ?', question.id])
  671 + total_votes = question.votes.count
  672 + total_skips = question.skips.count
  673 + if (total_answered_appearances != total_votes + total_skips)
  674 + error_message += "Question #{question.id}: answered_appearances = #{total_answered_appearances}, votes = #{total_votes}, skips = #{total_skips}"
  675 + end
  676 +
  677 +
  678 + return error_message.blank? ? [success_message, false] : [error_message, true]
  679 + end
653 680  
654 681 def ensure_all_votes_and_skips_have_unique_appearance
655 682 error_message = ""
... ...