Commit 21e15e238943270000c8e69184fe42ee7d53b996
1 parent
a7431d97
Exists in
master
and in
1 other branch
change orphaned prompts to Bounce / Stopped_Voting
Showing
1 changed file
with
7 additions
and
5 deletions
Show diff stats
app/models/question.rb
| ... | ... | @@ -579,11 +579,9 @@ class Question < ActiveRecord::Base |
| 579 | 579 | end |
| 580 | 580 | when 'non_votes' |
| 581 | 581 | |
| 582 | - self.appearances.find_each(:include => [:answerable, :voter]) do |a| | |
| 583 | - # we only display skips and orphaned appearances in this csv file | |
| 584 | - next if a.answerable.class == Vote | |
| 582 | + self.appearances.find_each(:include => [:voter], :conditions => ['answerable_type <> ? OR answerable_type IS NULL', 'Vote']) do |a| | |
| 585 | 583 | |
| 586 | - if a.answerable.class == Skip | |
| 584 | + if a.answerable_type == 'Skip' | |
| 587 | 585 | # If this appearance belongs to a skip, show information on the skip instead |
| 588 | 586 | s = a.answerable |
| 589 | 587 | valid = s.valid_record ? 'TRUE' : 'FALSE' |
| ... | ... | @@ -594,7 +592,11 @@ class Question < ActiveRecord::Base |
| 594 | 592 | else |
| 595 | 593 | # If no skip and no vote, this is an orphaned appearance |
| 596 | 594 | prompt = a.prompt |
| 597 | - csv << [ "Orphaned Appearance", a.id, a.voter_id, a.question_id, a.prompt.left_choice.id, a.prompt.left_choice.data.strip, a.prompt.right_choice.id, a.prompt.right_choice.data.strip, a.prompt_id, 'NA', a.created_at, a.updated_at, 'NA', '', a.voter.identifier, 'TRUE'] | |
| 595 | + action_appearances = Appearance.count(:conditions => | |
| 596 | + ["voter_id = ? AND question_id = ? AND answerable_type IS NOT ?", | |
| 597 | + a.voter_id, a.question_id, nil]) | |
| 598 | + appearance_type = (action_appearances > 0) ? 'Stopped_Voting' : 'Bounce' | |
| 599 | + csv << [ appearance_type, a.id, a.voter_id, a.question_id, a.prompt.left_choice.id, a.prompt.left_choice.data.strip, a.prompt.right_choice.id, a.prompt.right_choice.data.strip, a.prompt_id, 'NA', a.created_at, a.updated_at, 'NA', '', a.voter.identifier, 'TRUE'] | |
| 598 | 600 | end |
| 599 | 601 | end |
| 600 | 602 | end | ... | ... |