mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 09:08:10 +08:00
FIX: Post with multiple polls containing votes can not be edited.
https://meta.discourse.org/t/500-internal-server-error-when-editing-specific-poll-in-a-post-with-votes-editing-other-polls-works-fine/59684
This commit is contained in:
@ -79,6 +79,7 @@ module DiscoursePoll
|
|||||||
if previous_option["id"] != option["id"]
|
if previous_option["id"] != option["id"]
|
||||||
if votes_fields = post.custom_fields[DiscoursePoll::VOTES_CUSTOM_FIELD]
|
if votes_fields = post.custom_fields[DiscoursePoll::VOTES_CUSTOM_FIELD]
|
||||||
votes_fields.each do |key, value|
|
votes_fields.each do |key, value|
|
||||||
|
next unless value[poll_name]
|
||||||
index = value[poll_name].index(previous_option["id"])
|
index = value[poll_name].index(previous_option["id"])
|
||||||
votes_fields[key][poll_name][index] = option["id"] if index
|
votes_fields[key][poll_name][index] = option["id"] if index
|
||||||
end
|
end
|
||||||
|
@ -217,6 +217,40 @@ describe DiscoursePoll::PollsUpdater do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should be able to edit multiple polls with votes' do
|
||||||
|
DiscoursePoll::Poll.vote(
|
||||||
|
post_with_two_polls.id,
|
||||||
|
"poll",
|
||||||
|
[two_polls["poll"]["options"].first["id"]],
|
||||||
|
user
|
||||||
|
)
|
||||||
|
|
||||||
|
raw = <<-RAW.strip_heredoc
|
||||||
|
[poll]
|
||||||
|
* 12
|
||||||
|
* 34
|
||||||
|
[/poll]
|
||||||
|
|
||||||
|
[poll name=test]
|
||||||
|
* 12
|
||||||
|
* 34
|
||||||
|
[/poll]
|
||||||
|
RAW
|
||||||
|
|
||||||
|
different_post = Fabricate(:post, raw: raw)
|
||||||
|
different_polls = DiscoursePoll::PollsValidator.new(different_post).validate_polls
|
||||||
|
|
||||||
|
message = MessageBus.track_publish do
|
||||||
|
described_class.update(post_with_two_polls.reload, different_polls)
|
||||||
|
end.first
|
||||||
|
|
||||||
|
expect(post_with_two_polls.reload.custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD])
|
||||||
|
.to eq(different_polls)
|
||||||
|
|
||||||
|
expect(message.data[:post_id]).to eq(post_with_two_polls.id)
|
||||||
|
expect(message.data[:polls]).to eq(different_polls)
|
||||||
|
end
|
||||||
|
|
||||||
describe "when poll edit window has expired" do
|
describe "when poll edit window has expired" do
|
||||||
let(:poll_edit_window_mins) { 6 }
|
let(:poll_edit_window_mins) { 6 }
|
||||||
let(:another_post) { Fabricate(:post, created_at: Time.zone.now - poll_edit_window_mins.minutes) }
|
let(:another_post) { Fabricate(:post, created_at: Time.zone.now - poll_edit_window_mins.minutes) }
|
||||||
|
Reference in New Issue
Block a user