1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Fix poll options not being stripped of surrounding whitespace on save (#10168)

This commit is contained in:
Eugen Rochko 2019-03-05 03:45:56 +01:00 committed by GitHub
parent cda6ece760
commit 05dfd632c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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}")