Commit a624fb093f1b064b1df0b6220f116f2e498330b9
1 parent
9c85b571
Exists in
master
and in
1 other branch
add fix for votes going down after undecided
Showing
2 changed files
with
7 additions
and
1 deletions
Show diff stats
app/models/question.rb
... | ... | @@ -207,7 +207,7 @@ class Question < ActiveRecord::Base |
207 | 207 | |
208 | 208 | if params[:with_visitor_stats] |
209 | 209 | visitor = current_user.visitors.find_or_create_by_identifier(visitor_identifier) |
210 | - result.merge!(:visitor_votes => visitor.votes.count(:conditions => {:question_id => self.id})) | |
210 | + result.merge!(:visitor_votes => Vote.find_without_default_scope(:all, :conditions => {:voter_id => visitor, :question_id => self.id}).length) | |
211 | 211 | result.merge!(:visitor_ideas => visitor.choices.count) |
212 | 212 | end |
213 | 213 | ... | ... |
app/models/vote.rb
... | ... | @@ -25,6 +25,12 @@ class Vote < ActiveRecord::Base |
25 | 25 | after_create :update_winner_choice, :update_loser_choice |
26 | 26 | after_save :update_cached_values_based_on_flags |
27 | 27 | |
28 | + def self.find_without_default_scope(*args) | |
29 | + with_exclusive_scope() do | |
30 | + find(*args) | |
31 | + end | |
32 | + end | |
33 | + | |
28 | 34 | def update_winner_choice |
29 | 35 | choice.reload # make sure we're using updated counter values |
30 | 36 | choice.compute_score! | ... | ... |