2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-24 00:42:57 +08:00
|
|
|
require "rails_helper"
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Jobs::ClosePoll do
|
2018-12-13 16:39:36 +08:00
|
|
|
let(:post) { Fabricate(:post, raw: "[poll]\n- A\n- B\n[/poll]") }
|
2018-11-24 00:42:57 +08:00
|
|
|
|
2018-12-13 16:39:36 +08:00
|
|
|
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",
|
|
|
|
)
|
2023-01-07 04:42:16 +08:00
|
|
|
|
2018-12-13 16:39:36 +08:00
|
|
|
expect do Jobs::ClosePoll.new.execute(poll_name: "poll") end.to raise_error(
|
|
|
|
Discourse::InvalidParameters,
|
|
|
|
"post_id",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2018-11-24 00:42:57 +08:00
|
|
|
|
2018-12-13 16:39:36 +08:00
|
|
|
it "automatically closes a poll" do
|
2018-11-24 00:42:57 +08:00
|
|
|
expect(post.polls.first.closed?).to eq(false)
|
|
|
|
|
|
|
|
Jobs::ClosePoll.new.execute(post_id: post.id, poll_name: "poll")
|
|
|
|
|
|
|
|
expect(post.polls.first.closed?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|