<commit_before>class SchedulingPollItem < ActiveRecord::Base
  unloadable

  belongs_to :scheduling_poll
  has_many :scheduling_vote, :dependent => :destroy

  validates :scheduling_poll, :presence => true
  validates :text, :presence => true, :allow_blank => false

  def vote_by_user(user)
    self.scheduling_vote.where(:user => user).first
  end
  def users
    self.scheduling_vote.map {|v| v.user }
  end

  def vote(user, value=0)
    v = self.vote_by_user(user)
    unless value == 0
      if v.nil?
        v = self.scheduling_vote.create(:user => user, :value => value, :create_at => Time.now)
      else
        v.update(:value => value, :modify_at => Time.now)
      end
    else # remove vote
      v.destroy unless v.nil?
    end
    v
  end
end<commit_msg>fix a bug that vote cancellation is not executed.<commit_after>class SchedulingPollItem < ActiveRecord::Base
  unloadable

  belongs_to :scheduling_poll
  has_many :scheduling_vote, :dependent => :destroy

  validates :scheduling_poll, :presence => true
  validates :text, :presence => true, :allow_blank => false

  def vote_by_user(user)
    self.scheduling_vote.where(:user => user).first
  end
  def users
    self.scheduling_vote.map {|v| v.user }
  end

  def vote(user, value=0)
    value = value.to_i
    v = self.vote_by_user(user)
    unless value == 0
      if v.nil?
        v = self.scheduling_vote.create(:user => user, :value => value, :create_at => Time.now)
      else
        v.update(:value => value, :modify_at => Time.now)
      end
    else # remove vote
      v.destroy unless v.nil?
    end
    v
  end
end
{'fraction_non_alphanumeric': 0.11180512179887571, 'fraction_numerical': 0.0024984384759525295, 'mean_word_length': 3.065989847715736, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '649896', 'n_tokens_mistral': 564, 'n_tokens_neox': 541, 'n_words': 137}