Skip to content

A platform for community discussion. Free, open, simple.

FIX: Copy old status to new poll. (#6788)

Bianca Nenciuc928386c3ec6
diff --git a/plugins/poll/lib/polls_updater.rb b/plugins/poll/lib/polls_updater.rb
index d90c6625f58..26acdf14bd1 100644
--- a/plugins/poll/lib/polls_updater.rb
+++ b/plugins/poll/lib/polls_updater.rb
@@ -37,6 +37,7 @@ module DiscoursePoll
attributes = new_poll.slice(*POLL_ATTRIBUTES)
attributes["visibility"] = new_poll["public"] == "true" ? "everyone" : "secret"
attributes["close_at"] = Time.zone.parse(new_poll["close"]) rescue nil
+ attributes["status"] = old_poll["status"]
poll = ::Poll.new(attributes)
if is_different?(old_poll, poll, new_poll_options)
diff --git a/plugins/poll/spec/lib/polls_updater_spec.rb b/plugins/poll/spec/lib/polls_updater_spec.rb
index 461f68839ec..43b32840f84 100644
--- a/plugins/poll/spec/lib/polls_updater_spec.rb
+++ b/plugins/poll/spec/lib/polls_updater_spec.rb
@@ -59,6 +59,34 @@ describe DiscoursePoll::PollsUpdater do
expect(message).to be(nil)
end
+ describe "when editing" do
+
+ let(:raw) do
+ <<~RAW
+ This is a new poll with three options.
+
+ [poll type=multiple results=always min=1 max=2]
+ * first
+ * second
+ * third
+ [/poll]
+ RAW
+ end
+
+ let(:post) { Fabricate(:post, raw: raw) }
+
+ it "works if poll is closed and unmodified" do
+ DiscoursePoll::Poll.vote(post.id, "poll", ["e55de753c08b93d04d677ce05e942d3c"], post.user)
+ DiscoursePoll::Poll.toggle_status(post.id, "poll", "closed", post.user)
+
+ freeze_time (SiteSetting.poll_edit_window_mins + 1).minutes.from_now
+ update(post, DiscoursePoll::PollsValidator.new(post).validate_polls)
+
+ expect(post.errors[:base].size).to equal(0)
+ end
+
+ end
+
describe "deletes polls" do
it "that were removed" do