Commit ad18d470c4e242b5351105ef30f3356df630969d
1 parent
b2c46627
Exists in
master
and in
1 other branch
ensure all duplicate answers lack an appearance
Showing
1 changed file
with
28 additions
and
0 deletions
Show diff stats
lib/tasks/test_api.rake
| @@ -193,6 +193,7 @@ namespace :test_api do | @@ -193,6 +193,7 @@ namespace :test_api do | ||
| 193 | :check_scores_over_above_fifty => "Check that there are some scores above fifty and some below", | 193 | :check_scores_over_above_fifty => "Check that there are some scores above fifty and some below", |
| 194 | :generated_prompts_on_each_side_are_equal => "Verify that count of generated prompts on each side is equal", | 194 | :generated_prompts_on_each_side_are_equal => "Verify that count of generated prompts on each side is equal", |
| 195 | :every_answer_has_an_appearances => "Verify that all answers have an appearance", | 195 | :every_answer_has_an_appearances => "Verify that all answers have an appearance", |
| 196 | + :duplicate_answers_have_no_appearance => "Verify that duplicate answers have no appearance", | ||
| 196 | :appearances_have_same_session_as_answer => "Appearances have the same session of their answer" | 197 | :appearances_have_same_session_as_answer => "Appearances have the same session of their answer" |
| 197 | } | 198 | } |
| 198 | 199 | ||
| @@ -209,6 +210,33 @@ namespace :test_api do | @@ -209,6 +210,33 @@ namespace :test_api do | ||
| 209 | end | 210 | end |
| 210 | end | 211 | end |
| 211 | 212 | ||
| 213 | + def duplicate_answers_have_no_appearance(question) | ||
| 214 | + error_message = "" | ||
| 215 | + success_message = "All duplicate answers lack an appearance." | ||
| 216 | + votes_sql = "SELECT votes.id, votes.valid_record, votes.validity_information | ||
| 217 | + FROM votes | ||
| 218 | + LEFT JOIN appearances | ||
| 219 | + ON (votes.question_id = appearances.question_id AND votes.id = appearances.answerable_id AND appearances.answerable_type = 'Vote') | ||
| 220 | + WHERE appearances.id IS NOT NULL | ||
| 221 | + AND votes.validity_information LIKE 'Appearance % already answered' | ||
| 222 | + AND votes.question_id = #{question.id}" | ||
| 223 | + bad_records = Vote.connection.select_all votes_sql | ||
| 224 | + bad_records.each do |record| | ||
| 225 | + error_message += "Vote ##{record["id"]} has an appearance but should not\n" | ||
| 226 | + end | ||
| 227 | + skips_sql = "SELECT skips.id, skips.valid_record, skips.validity_information | ||
| 228 | + FROM skips | ||
| 229 | + LEFT JOIN appearances | ||
| 230 | + ON (skips.question_id = appearances.question_id AND skips.id = appearances.answerable_id AND appearances.answerable_type = 'Skip') | ||
| 231 | + WHERE appearances.id IS NOT NULL | ||
| 232 | + AND skips.validity_information LIKE 'Appearance % already answered' | ||
| 233 | + AND skips.question_id = #{question.id}" | ||
| 234 | + bad_records = Skip.connection.select_all skips_sql | ||
| 235 | + bad_records.each do |record| | ||
| 236 | + error_message += "Skip ##{record["id"]} has an appearance but should not\n" | ||
| 237 | + end | ||
| 238 | + return error_message.blank? ? [success_message, false] : [error_message, true] | ||
| 239 | + end | ||
| 212 | # every answer should have an appearance except for those that are attempts | 240 | # every answer should have an appearance except for those that are attempts |
| 213 | # to answer an already answered appearance. | 241 | # to answer an already answered appearance. |
| 214 | def every_answer_has_an_appearances(question) | 242 | def every_answer_has_an_appearances(question) |