about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-03-05 03:45:56 +0100
committerGitHub <noreply@github.com>2019-03-05 03:45:56 +0100
commit05dfd632c73b605232a77f27ff8d5b888efe5b00 (patch)
tree6ce8587e8b3ba3ba26ec192683362c75c1fd694d /app/models
parentcda6ece760f08974e6118887641e6cc8c0f8c9e0 (diff)
Fix poll options not being stripped of surrounding whitespace on save (#10168)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/poll.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/poll.rb b/app/models/poll.rb
index ba0b17f91..ab7236d45 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -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
@@ -75,6 +78,10 @@ class Poll < ApplicationRecord
     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}")