Commit 1d4cbec7908009fcbe1adf9d064adb204e0a875b
1 parent
5b655c2e
Exists in
master
and in
1 other branch
add test to ensure every answer has an appearance
Showing
1 changed file
with
31 additions
and
0 deletions
Show diff stats
lib/tasks/test_api.rake
@@ -192,6 +192,7 @@ namespace :test_api do | @@ -192,6 +192,7 @@ namespace :test_api do | ||
192 | :wins_and_losses_equals_two_times_vote_count => "Verify that sum of wins and losses equals two times the vote count", | 192 | :wins_and_losses_equals_two_times_vote_count => "Verify that sum of wins and losses equals two times the vote count", |
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 | :appearances_have_same_session_as_answer => "Appearances have the same session of their answer" | 196 | :appearances_have_same_session_as_answer => "Appearances have the same session of their answer" |
196 | } | 197 | } |
197 | 198 | ||
@@ -208,6 +209,36 @@ namespace :test_api do | @@ -208,6 +209,36 @@ namespace :test_api do | ||
208 | end | 209 | end |
209 | end | 210 | end |
210 | 211 | ||
212 | + # every answer should have an appearance except for those that are attempts | ||
213 | + # to answer an already answered appearance. | ||
214 | + def every_answer_has_an_appearances(question) | ||
215 | + error_message = "" | ||
216 | + success_message = "All valid answers have an appearance." | ||
217 | + votes_sql = "SELECT votes.id, votes.valid_record, votes.validity_information | ||
218 | + FROM votes | ||
219 | + LEFT JOIN appearances | ||
220 | + ON (votes.question_id = appearances.question_id AND votes.id = appearances.answerable_id AND appearances.answerable_type = 'Vote') | ||
221 | + WHERE appearances.id IS NULL | ||
222 | + AND (votes.validity_information IS NULL OR votes.validity_information NOT LIKE 'Appearance %') | ||
223 | + AND votes.question_id = #{question.id}" | ||
224 | + bad_records = Vote.connection.select_all votes_sql | ||
225 | + bad_records.each do |record| | ||
226 | + error_message += "Vote ##{record["id"]} does not have an appearance\n" | ||
227 | + end | ||
228 | + skips_sql = "SELECT skips.id, skips.valid_record, skips.validity_information | ||
229 | + FROM skips | ||
230 | + LEFT JOIN appearances | ||
231 | + ON (skips.question_id = appearances.question_id AND skips.id = appearances.answerable_id AND appearances.answerable_type = 'Skip') | ||
232 | + WHERE appearances.id IS NULL | ||
233 | + AND (skips.validity_information IS NULL OR skips.validity_information NOT LIKE 'Appearance %') | ||
234 | + AND skips.question_id = #{question.id}" | ||
235 | + bad_records = Skip.connection.select_all skips_sql | ||
236 | + bad_records.each do |record| | ||
237 | + error_message += "Skip ##{record["id"]} does not have an appearance\n" | ||
238 | + end | ||
239 | + return error_message.blank? ? [success_message, false] : [error_message, true] | ||
240 | + end | ||
241 | + | ||
211 | def appearances_have_same_session_as_answer(question) | 242 | def appearances_have_same_session_as_answer(question) |
212 | error_message = "" | 243 | error_message = "" |
213 | success_message = "All appearances have the same session as their respective answer" | 244 | success_message = "All appearances have the same session as their respective answer" |