Skip to content

Commit

Permalink
Fix poll options not being stripped of surrounding whitespace on save (
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored and hiyuki2578 committed Oct 2, 2019
1 parent 8fa5486 commit de27fed
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/poll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ class Poll < ApplicationRecord
scope :attached, -> { where.not(status_id: nil) }
scope :unattached, -> { where(status_id: nil) }

before_validation :prepare_options
before_validation :prepare_votes_count

after_initialize :prepare_cached_tallies

after_commit :reset_parent_cache, on: :update

def loaded_options
Expand Down Expand Up @@ -75,6 +78,10 @@ def prepare_votes_count
self.votes_count = cached_tallies.sum unless cached_tallies.empty?
end

def prepare_options
self.options = options.map(&:strip).reject(&:blank?)
end

def reset_parent_cache
return if status_id.nil?
Rails.cache.delete("statuses/#{status_id}")
Expand Down

0 comments on commit de27fed

Please sign in to comment.