mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
correct poll specs
This commit is contained in:
@ -29,23 +29,23 @@ describe PostsController do
|
||||
end
|
||||
|
||||
it "should have different options" do
|
||||
xhr :post, :create, { title: title, raw: "[poll]\n- A\n- A[/poll]" }
|
||||
xhr :post, :create, { title: title, raw: "[poll]\n- A\n- A\n[/poll]" }
|
||||
expect(response).not_to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_different_options"))
|
||||
end
|
||||
|
||||
it "should have at least 2 options" do
|
||||
xhr :post, :create, { title: title, raw: "[poll]\n- A[/poll]" }
|
||||
xhr :post, :create, { title: title, raw: "[poll]\n- A\n[/poll]" }
|
||||
expect(response).not_to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_at_least_2_options"))
|
||||
end
|
||||
|
||||
it "should have at most 'SiteSetting.poll_maximum_options' options" do
|
||||
raw = "[poll]"
|
||||
raw = "[poll]\n"
|
||||
(SiteSetting.poll_maximum_options + 1).times { |n| raw << "\n- #{n}" }
|
||||
raw << "[/poll]"
|
||||
raw << "\n[/poll]"
|
||||
|
||||
xhr :post, :create, { title: title, raw: raw }
|
||||
|
||||
@ -55,7 +55,7 @@ describe PostsController do
|
||||
end
|
||||
|
||||
it "should have valid parameters" do
|
||||
xhr :post, :create, { title: title, raw: "[poll type=multiple min=5]\n- A\n- B[/poll]" }
|
||||
xhr :post, :create, { title: title, raw: "[poll type=multiple min=5]\n- A\n- B\n[/poll]" }
|
||||
expect(response).not_to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_with_multiple_choices_has_invalid_parameters"))
|
||||
@ -66,7 +66,8 @@ describe PostsController do
|
||||
expect(response).to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json["cooked"]).to match("data-poll-")
|
||||
expect(json["polls"]["<script>alert(xss)</script>"]).to be
|
||||
expect(json["cooked"]).to include("<script>")
|
||||
expect(json["polls"]["<script>alert('xss')</script>"]).to be
|
||||
end
|
||||
|
||||
it "also works whe there is a link starting with '[poll'" do
|
||||
@ -116,9 +117,9 @@ describe PostsController do
|
||||
|
||||
describe "after the poll edit window has expired" do
|
||||
|
||||
let(:poll) { "[poll]\n- A\n- B[/poll]" }
|
||||
let(:new_option) { "[poll]\n- A\n- C[/poll]" }
|
||||
let(:updated) { "before\n\n[poll]\n- A\n- B[/poll]\n\nafter" }
|
||||
let(:poll) { "[poll]\n- A\n- B\n[/poll]" }
|
||||
let(:new_option) { "[poll]\n- A\n- C\n[/poll]" }
|
||||
let(:updated) { "before\n\n[poll]\n- A\n- B\n[/poll]\n\nafter" }
|
||||
|
||||
let(:post_id) do
|
||||
Timecop.freeze(6.minutes.ago) do
|
||||
@ -220,14 +221,14 @@ describe PostsController do
|
||||
describe "named polls" do
|
||||
|
||||
it "should have different options" do
|
||||
xhr :post, :create, { title: title, raw: "[poll name=""foo""]\n- A\n- A[/poll]" }
|
||||
xhr :post, :create, { title: title, raw: "[poll name=""foo""]\n- A\n- A\n[/poll]" }
|
||||
expect(response).not_to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.named_poll_must_have_different_options", name: "foo"))
|
||||
end
|
||||
|
||||
it "should have at least 2 options" do
|
||||
xhr :post, :create, { title: title, raw: "[poll name='foo']\n- A[/poll]" }
|
||||
xhr :post, :create, { title: title, raw: "[poll name='foo']\n- A\n[/poll]" }
|
||||
expect(response).not_to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.named_poll_must_have_at_least_2_options", name: "foo"))
|
||||
|
Reference in New Issue
Block a user