0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/plugins/poll/spec/jobs/regular/close_poll_spec.rb
Régis Hanol 72091d161c
FEATURE: Record who closed a poll (#40989)
Previously, there was no way to tell who closed (or reopened) a poll —
neither the staff action log nor the poll itself recorded it, as raised
in [meta](https://meta.discourse.org/t/who-closed-the-poll/405495).

This change logs `poll_closed`/`poll_opened` staff actions (auto-close
attributed to the system user) and stores `closed_by`/`closed_at` on the
poll, surfacing "Closed by @user" in the poll UI and making the closer
queryable.

---

Also includes a small fix: the poll buttons dropdown rendered a
`<dropdown.divider />` after every item, leaving a stray trailing border
below the last option; it now renders dividers only between items.

**Screenshot**

<img width="1400" height="1200" alt="image"
src="https://github.com/user-attachments/assets/fd04353a-eac6-448d-904e-47b8e5f8f14f"
/>
2026-06-29 12:22:43 +02:00

37 lines
1.1 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe Jobs::ClosePoll do
let(:post) { Fabricate(:post, raw: "[poll]\n- A\n- B\n[/poll]") }
describe "missing arguments" do
it "should raise the right error" do
expect do Jobs::ClosePoll.new.execute(post_id: post.id) end.to raise_error(
Discourse::InvalidParameters,
"poll_name",
)
expect do Jobs::ClosePoll.new.execute(poll_name: "poll") end.to raise_error(
Discourse::InvalidParameters,
"post_id",
)
end
end
it "automatically closes a poll" do
expect(post.polls.first.closed?).to eq(false)
Jobs::ClosePoll.new.execute(post_id: post.id, poll_name: "poll")
poll = post.polls.first
expect(poll.closed?).to eq(true)
expect(poll.closed_by_id).to eq(Discourse.system_user.id)
end
it "logs the automatic close as the system user" do
Jobs::ClosePoll.new.execute(post_id: post.id, poll_name: "poll")
log = UserHistory.last
expect(log.custom_type).to eq("poll_closed")
expect(log.acting_user_id).to eq(Discourse.system_user.id)
end
end