Commit 671f2fd0c7890fc8f85476d927020829222a3aa2

Authored by Luke Baker
1 parent a5557a55

initialize error_message

Showing 1 changed file with 16 additions and 1 deletions   Show diff stats
lib/tasks/test_api.rake
... ... @@ -27,6 +27,7 @@ namespace :test_api do
27 27 end
28 28  
29 29 def verify_losses_equals_losing_votes(choice)
  30 + error_message = ""
30 31 success_message = "Choice losses equals losing votes"
31 32 # votes before 2010-02-17 have null loser_choice_id
32 33 # therefore we want to ignore this test for any question with votes
... ... @@ -40,6 +41,7 @@ namespace :test_api do
40 41 end
41 42  
42 43 def verify_wins_equals_vote_wins(choice)
  44 + error_message = ""
43 45 success_message = "Choice wins equals vote wins"
44 46 choice_votes_count = choice.votes.count
45 47 if (choice.wins != choice_votes_count)
... ... @@ -49,6 +51,7 @@ namespace :test_api do
49 51 end
50 52  
51 53 def verify_cached_score_equals_computed_score(choice)
  54 + error_message = ""
52 55 success_message = "Choice has accurate cached score"
53 56 cached_score = choice.score.to_f
54 57 generated_score = choice.compute_score.to_f
... ... @@ -63,6 +66,7 @@ namespace :test_api do
63 66 end
64 67  
65 68 def verify_valid_cached_score(choice)
  69 + error_message = ""
66 70 success_message = "Choice has valid cached score"
67 71 cached_score = choice.score.to_f
68 72 if cached_score == 0.0 || cached_score == 100.0 || cached_score.nil?
... ... @@ -72,6 +76,7 @@ namespace :test_api do
72 76 end
73 77  
74 78 def verify_cached_prompt_counts(choice)
  79 + error_message = ""
75 80 success_message = "Choice has accurate prompt cache count"
76 81 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
77 82 error_message = "Choice #{choice.id} in Question ##{choice.question_id} has inaccurate prompt count cache"
... ... @@ -80,6 +85,7 @@ namespace :test_api do
80 85 end
81 86  
82 87 def verify_choice_appearances_and_votes(choice)
  88 + error_message = ""
83 89 success_message = "Choice has more appearances than votes and skips"
84 90 return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(choice.question_id)
85 91 all_appearances = choice.appearances_on_the_left.count + choice.appearances_on_the_right.count
... ... @@ -181,6 +187,7 @@ namespace :test_api do
181 187 end
182 188  
183 189 def generated_prompts_on_each_side_are_equal(question)
  190 + error_message = ""
184 191 success_message = "Number of generated prompts on left are equal to number generated on right"
185 192 generated_on_left = Choice.connection.select_one("
186 193 SELECT COUNT(*) AS total FROM prompts
... ... @@ -195,6 +202,7 @@ namespace :test_api do
195 202 end
196 203  
197 204 def check_scores_over_above_fifty(question)
  205 + error_message = ""
198 206 success_message = "Scores are distributed above and below 50"
199 207 return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id)
200 208 totals_lte_fifty = Choice.connection.select_one("
... ... @@ -213,6 +221,7 @@ namespace :test_api do
213 221 end
214 222  
215 223 def wins_and_losses_equals_two_times_vote_count(question)
  224 + error_message = ""
216 225 success_message = "Wins and losses equals 2 times vote count"
217 226 return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id)
218 227 totals = Question.connection.select_one("
... ... @@ -227,6 +236,7 @@ namespace :test_api do
227 236 end
228 237  
229 238 def wins_and_losses_is_even(question)
  239 + error_message = ""
230 240 success_message = "Total Votes is even"
231 241 return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id)
232 242 totals = Question.connection.select_one("
... ... @@ -241,6 +251,7 @@ namespace :test_api do
241 251 end
242 252  
243 253 def wins_and_losses_equals_two_times_wins(question)
  254 + error_message = ""
244 255 success_message = "2 x Total Wins == Total Votes"
245 256 return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id)
246 257 totals = Question.connection.select_one("
... ... @@ -248,13 +259,14 @@ namespace :test_api do
248 259 SUM(wins) AS total_wins,
249 260 SUM(losses) AS total_losses FROM choices
250 261 WHERE question_id = #{question.id}")
251   - if (2*totals["total_wins"] != totals["total"])
  262 + if (2*totals["total_wins"].to_i != totals["total"].to_i)
252 263 error_message = "Error: 2 x Total Wins != Total votes"
253 264 end
254 265 return error_message.blank? ? [success_message, false] : [error_message, true]
255 266 end
256 267  
257 268 def answered_appearances_equals_votes_and_skips(question)
  269 + error_message = ""
258 270 success_message = "All vote and skip objects have an associated appearance object"
259 271 skip_appearances_count = Appearance.count(
260 272 :conditions => ["skips.valid_record = 1 and appearances.question_id = ? AND answerable_id IS NOT NULL AND answerable_type = 'Skip'", question.id],
... ... @@ -273,6 +285,7 @@ namespace :test_api do
273 285 end
274 286  
275 287 def check_each_choice_appears_within_n_stddevs(question)
  288 + error_message = ""
276 289 success_message = "Each choice has appeared n times, where n falls within 6 stddevs of the mean number of appearances for a question " +
277 290 "(Note: this applies only to seed choices (not user submitted) and choices currently marked active)"
278 291  
... ... @@ -310,6 +323,7 @@ namespace :test_api do
310 323 end
311 324  
312 325 def check_each_choice_equally_likely_to_appear_left_or_right(question)
  326 + error_message = ""
313 327 success_message = "All choices have equal probability of appearing on left or right (within error params)"
314 328 question.choices.each do |c|
315 329 left_prompts_ids = c.prompts_on_the_left.ids_only
... ... @@ -430,6 +444,7 @@ namespace :test_api do
430 444  
431 445 def verify_range_of_choices_scores
432 446 bad_choices_count = Choice.count(:conditions => 'score < 0 OR score > 100')
  447 + error_message = ""
433 448 success_message = "All choices have a score within 0-100"
434 449 if bad_choices_count > 0
435 450 error_message = "Some choices have a score less than 0 or greater than 100"
... ...