Commit e691b72dd0a973603c48999f00860dccead48f46

Authored by Luke Baker
1 parent fd5da224

add active_loser scope for votes

irregular appearances test was using the active scope which was
ensuring the winner was active, but we want to examine all losing
choices that are active
Showing 2 changed files with 4 additions and 1 deletions   Show diff stats
app/models/vote.rb
@@ -17,6 +17,7 @@ class Vote < ActiveRecord::Base @@ -17,6 +17,7 @@ class Vote < ActiveRecord::Base
17 named_scope :with_question, lambda { |*args| {:conditions => {:question_id => args.first }} } 17 named_scope :with_question, lambda { |*args| {:conditions => {:question_id => args.first }} }
18 named_scope :with_voter_ids, lambda { |*args| {:conditions => {:voter_id=> args.first }} } 18 named_scope :with_voter_ids, lambda { |*args| {:conditions => {:voter_id=> args.first }} }
19 named_scope :active, :include => :choice, :conditions => { 'choices.active' => true } 19 named_scope :active, :include => :choice, :conditions => { 'choices.active' => true }
  20 + named_scope :active_loser, :include => :loser_choice, :conditions => { 'choices.active' => true }
20 21
21 default_scope :conditions => "#{table_name}.valid_record = 1" 22 default_scope :conditions => "#{table_name}.valid_record = 1"
22 23
lib/tasks/test_api.rake
@@ -545,13 +545,14 @@ namespace :test_api do @@ -545,13 +545,14 @@ namespace :test_api do
545 end 545 end
546 return error_message.blank? ? [success_message, false] : [error_message, true] 546 return error_message.blank? ? [success_message, false] : [error_message, true]
547 end 547 end
  548 +
548 def check_each_choice_appears_within_n_stddevs(question) 549 def check_each_choice_appears_within_n_stddevs(question)
549 error_message ="" 550 error_message =""
550 success_message = "Each choice has appeared n times, where n falls within 6 stddevs of the mean number of appearances for a question " + 551 success_message = "Each choice has appeared n times, where n falls within 6 stddevs of the mean number of appearances for a question " +
551 "(Note: this applies only to seed choices (not user submitted) and choices currently marked active)" 552 "(Note: this applies only to seed choices (not user submitted) and choices currently marked active)"
552 553
553 wins_by_choice_id = question.votes.active.count(:group => :choice_id) 554 wins_by_choice_id = question.votes.active.count(:group => :choice_id)
554 - losses_by_choice_id= question.votes.active.count(:conditions => "loser_choice_id IS NOT NULL", :group => :loser_choice_id) 555 + losses_by_choice_id= question.votes.active_loser.count(:group => :loser_choice_id)
555 556
556 #Rails returns an ordered hash, which doesn't allow for blocks to change merging logic. 557 #Rails returns an ordered hash, which doesn't allow for blocks to change merging logic.
557 #A little hack to create a normal hash 558 #A little hack to create a normal hash
@@ -579,6 +580,7 @@ namespace :test_api do @@ -579,6 +580,7 @@ namespace :test_api do
579 580
580 return error_message.blank? ? [success_message, false] : [error_message, true] 581 return error_message.blank? ? [success_message, false] : [error_message, true]
581 end 582 end
  583 +
582 def check_each_choice_equally_likely_to_appear_left_or_right(question) 584 def check_each_choice_equally_likely_to_appear_left_or_right(question)
583 error_message = "" 585 error_message = ""
584 success_message = "All choices have equal probability of appearing on left or right (within error params)" 586 success_message = "All choices have equal probability of appearing on left or right (within error params)"