FIX: Add a blank poll options validation (#8652)

Before, saving a post with a blank poll option resulted in error 500.
This commit is contained in:
Jarek Radosz
2020-01-03 15:09:36 +01:00
committed by GitHub
parent fac71da605
commit 9e3fc1111d
3 changed files with 48 additions and 0 deletions

View File

@@ -124,6 +124,36 @@ describe ::DiscoursePoll::PollsValidator do
)
end
it "ensures that polls do not have any blank options" do
raw = <<~RAW
[poll]
* 1
*
[/poll]
RAW
post.raw = raw
expect(post.valid?).to eq(false)
expect(post.errors[:base]).to include(
I18n.t("poll.default_poll_must_not_have_any_empty_options")
)
raw = <<~RAW
[poll name=test]
*
* 1
[/poll]
RAW
post.raw = raw
expect(post.valid?).to eq(false)
expect(post.errors[:base]).to include(
I18n.t("poll.named_poll_must_not_have_any_empty_options", name: "test")
)
end
it "ensure that polls have at least 2 options" do
raw = <<~RAW
[poll]