Commit 9cbb9a377d85ca0ca4473fba6d053b751883fd3a
1 parent
842b177c
Exists in
master
and in
1 other branch
add test to check for prompt_id mismatch
check for prompt_id mismatch between appearances and their related votes
Showing
1 changed file
with
25 additions
and
0 deletions
Show diff stats
lib/tasks/test_api.rake
@@ -3,6 +3,25 @@ namespace :test_api do | @@ -3,6 +3,25 @@ namespace :test_api do | ||
3 | desc "Run all API tests" | 3 | desc "Run all API tests" |
4 | task :all => [:question_vote_consistency,:generate_density_information] | 4 | task :all => [:question_vote_consistency,:generate_density_information] |
5 | 5 | ||
6 | + desc "Ensure all appearance and votes have matching prompt_ids" | ||
7 | + task :verify_appearance_vote_prompt_ids => :environment do | ||
8 | + puts verify_appearance_vote_prompt_ids().inspect | ||
9 | + end | ||
10 | + def verify_appearance_vote_prompt_ids | ||
11 | + bad_records = Vote.connection.select_all " | ||
12 | + SELECT votes.id | ||
13 | + FROM votes LEFT JOIN appearances | ||
14 | + ON (votes.id = appearances.answerable_id | ||
15 | + AND appearances.answerable_type = 'Vote') | ||
16 | + WHERE votes.prompt_id <> appearances.prompt_id" | ||
17 | + success_message = "Appearance and vote prompt_ids match" | ||
18 | + error_message = bad_records.map do |record| | ||
19 | + "Vote ##{record["id"]} has a different prompt_id than its appearance." | ||
20 | + end | ||
21 | + error_message.join "\n" | ||
22 | + return error_message.blank? ? [success_message, false] : [error_message, true] | ||
23 | + end | ||
24 | + | ||
6 | desc "Ensure that all choices have 0 <= score <= 100" | 25 | desc "Ensure that all choices have 0 <= score <= 100" |
7 | task :verify_range_of_choices_scores => :environment do | 26 | task :verify_range_of_choices_scores => :environment do |
8 | puts verify_range_of_choices_scores().inspect | 27 | puts verify_range_of_choices_scores().inspect |
@@ -365,6 +384,12 @@ namespace :test_api do | @@ -365,6 +384,12 @@ namespace :test_api do | ||
365 | else | 384 | else |
366 | successes << message | 385 | successes << message |
367 | end | 386 | end |
387 | + message, error_occurred = verify_appearance_vote_prompt_ids | ||
388 | + if error_occurred | ||
389 | + errors << message | ||
390 | + else | ||
391 | + successes << message | ||
392 | + end | ||
368 | 393 | ||
369 | 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" | 394 | 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 | errors.each do |e| | 395 | errors.each do |e| |