Commit e12b8e28b25603c2422f1edf35cde106f0163b3f
1 parent
c39a3b7a
Exists in
master
and in
1 other branch
add test to verify range of choice scores
Showing
1 changed file
with
20 additions
and
0 deletions
Show diff stats
lib/tasks/test_api.rake
@@ -28,6 +28,20 @@ namespace :test_api do | @@ -28,6 +28,20 @@ namespace :test_api do | ||
28 | 28 | ||
29 | task :all => [:question_vote_consistency,:generate_density_information] | 29 | task :all => [:question_vote_consistency,:generate_density_information] |
30 | 30 | ||
31 | + desc "Ensure that all choices have 0 <= score <= 100" | ||
32 | + task :verify_range_of_choices_scores => :environment do | ||
33 | + puts verify_range_of_choices_scores().inspect | ||
34 | + end | ||
35 | + | ||
36 | + def verify_range_of_choices_scores | ||
37 | + bad_choices_count = Choice.count(:conditions => 'score < 0 OR score > 100') | ||
38 | + success_message = "All choices have a score within 0-100" | ||
39 | + if bad_choices_count > 0 | ||
40 | + error_message = "Some choices have a score less than 0 or greater than 100" | ||
41 | + end | ||
42 | + return error_message.blank? ? [success_message, false] : [error_message, true] | ||
43 | + end | ||
44 | + | ||
31 | desc "Don't run unless you know what you are doing" | 45 | desc "Don't run unless you know what you are doing" |
32 | task(:generate_lots_of_votes => :environment) do | 46 | task(:generate_lots_of_votes => :environment) do |
33 | if Rails.env.production? | 47 | if Rails.env.production? |
@@ -346,6 +360,12 @@ namespace :test_api do | @@ -346,6 +360,12 @@ namespace :test_api do | ||
346 | else | 360 | else |
347 | successes << message | 361 | successes << message |
348 | end | 362 | end |
363 | + message, error_occurred = verify_range_of_choices_scores | ||
364 | + if error_occurred | ||
365 | + errors << message | ||
366 | + else | ||
367 | + successes << message | ||
368 | + end | ||
349 | 369 | ||
350 | email_text = "Conducted the following tests on API data and found the following results\n" + "For each of the #{questions.length} questions in the database: \n" | 370 | email_text = "Conducted the following tests on API data and found the following results\n" + "For each of the #{questions.length} questions in the database: \n" |
351 | errors.each do |e| | 371 | errors.each do |e| |