Immediately display poll results to poll author (#10187)

* Immediately display poll results to poll author

* Refactor Poll#loaded_options and add Poll#voted? to improve DRYness
This commit is contained in:
Eugen Rochko 2019-03-07 22:53:47 +01:00 committed by GitHub
parent 75cb93676b
commit 054bbb3da2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 24 deletions

View file

@ -4,7 +4,7 @@ class REST::PollSerializer < ActiveModel::Serializer
attributes :id, :expires_at, :expired,
:multiple, :votes_count
has_many :dynamic_options, key: :options
has_many :loaded_options, key: :options
attribute :voted, if: :current_user?
@ -12,20 +12,12 @@ class REST::PollSerializer < ActiveModel::Serializer
object.id.to_s
end
def dynamic_options
if !object.expired? && object.hide_totals?
object.unloaded_options
else
object.loaded_options
end
end
def expired
object.expired?
end
def voted
object.votes.where(account: current_user.account).exists?
object.voted?(current_user.account)
end
def current_user?