2015-10-11 05:41:23 -04:00
|
|
|
|
require "rails_helper"
|
2016-04-15 17:26:18 -04:00
|
|
|
|
require_relative "../helpers"
|
2015-04-23 13:33:29 -04:00
|
|
|
|
|
|
|
|
|
describe PostsController do
|
|
|
|
|
let!(:user) { log_in }
|
|
|
|
|
let!(:title) { "Testing Poll Plugin" }
|
|
|
|
|
|
2015-08-04 22:39:38 -04:00
|
|
|
|
before do
|
|
|
|
|
SiteSetting.min_first_post_typing_time = 0
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
describe "polls" do
|
|
|
|
|
|
|
|
|
|
it "works" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["cooked"]).to match("data-poll-")
|
|
|
|
|
expect(json["polls"]["poll"]).to be
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "works on any post" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post_1 = Fabricate(:post)
|
|
|
|
|
|
|
|
|
|
post :create, params: {
|
|
|
|
|
topic_id: post_1.topic.id, raw: "[poll]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["cooked"]).to match("data-poll-")
|
|
|
|
|
expect(json["polls"]["poll"]).to be
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "should have different options" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll]\n- A\n- A\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
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
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll]\n- A\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
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
|
|
|
|
|
|
2015-05-01 10:44:51 -04:00
|
|
|
|
it "should have at most 'SiteSetting.poll_maximum_options' options" do
|
2017-07-18 14:31:22 -04:00
|
|
|
|
raw = "[poll]\n"
|
2015-05-01 10:44:51 -04:00
|
|
|
|
(SiteSetting.poll_maximum_options + 1).times { |n| raw << "\n- #{n}" }
|
2017-07-18 14:31:22 -04:00
|
|
|
|
raw << "\n[/poll]"
|
2015-05-01 10:44:51 -04:00
|
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: raw
|
|
|
|
|
}, format: :json
|
2015-05-01 10:44:51 -04:00
|
|
|
|
|
|
|
|
|
expect(response).not_to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
2015-09-27 15:36:57 -04:00
|
|
|
|
expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_less_options", count: SiteSetting.poll_maximum_options))
|
2015-05-01 10:44:51 -04:00
|
|
|
|
end
|
|
|
|
|
|
2015-06-01 13:28:05 -04:00
|
|
|
|
it "should have valid parameters" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll type=multiple min=5]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-06-01 13:28:05 -04:00
|
|
|
|
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"))
|
|
|
|
|
end
|
|
|
|
|
|
2015-05-11 14:09:17 -04:00
|
|
|
|
it "prevents self-xss" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll name=<script>alert('xss')</script>]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-05-11 14:09:17 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["cooked"]).to match("data-poll-")
|
2017-07-18 14:31:22 -04:00
|
|
|
|
expect(json["cooked"]).to include("<script>")
|
|
|
|
|
expect(json["polls"]["<script>alert('xss')</script>"]).to be
|
2015-05-11 14:09:17 -04:00
|
|
|
|
end
|
|
|
|
|
|
2015-05-13 11:50:25 -04:00
|
|
|
|
it "also works whe there is a link starting with '[poll'" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[Polls are awesome](/foobar)\n[poll]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-05-13 11:50:25 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["cooked"]).to match("data-poll-")
|
|
|
|
|
expect(json["polls"]).to be
|
|
|
|
|
end
|
|
|
|
|
|
2015-05-13 17:12:53 -04:00
|
|
|
|
it "prevents pollception" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll name=1]\n- A\n[poll name=2]\n- B\n- C\n[/poll]\n- D\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-05-13 17:12:53 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["cooked"]).to match("data-poll-")
|
|
|
|
|
expect(json["polls"]["1"]).to_not be
|
|
|
|
|
expect(json["polls"]["2"]).to be
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
describe "edit window" do
|
|
|
|
|
|
|
|
|
|
describe "within the first 5 minutes" do
|
|
|
|
|
|
|
|
|
|
let(:post_id) do
|
2017-07-24 09:17:42 -04:00
|
|
|
|
freeze_time(4.minutes.ago) do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
::JSON.parse(response.body)["id"]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "can be changed" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
put :update, params: {
|
|
|
|
|
id: post_id, post: { raw: "[poll]\n- A\n- B\n- C\n[/poll]" }
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["post"]["polls"]["poll"]["options"][2]["html"]).to eq("C")
|
|
|
|
|
end
|
|
|
|
|
|
2015-05-06 12:52:09 -04:00
|
|
|
|
it "resets the votes" do
|
2016-07-29 02:47:23 -04:00
|
|
|
|
DiscoursePoll::Poll.vote(post_id, "poll", ["5c24fc1df56d764b550ceae1b9319125"], user)
|
2017-08-31 00:06:56 -04:00
|
|
|
|
|
|
|
|
|
put :update, params: {
|
|
|
|
|
id: post_id, post: { raw: "[poll]\n- A\n- B\n- C\n[/poll]" }
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-05-06 12:52:09 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["post"]["polls_votes"]).to_not be
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
end
|
|
|
|
|
|
2016-08-10 03:15:29 -04:00
|
|
|
|
describe "after the poll edit window has expired" do
|
2015-04-23 13:33:29 -04:00
|
|
|
|
|
2017-07-18 14:31:22 -04:00
|
|
|
|
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" }
|
2015-09-14 13:27:54 -04:00
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
let(:post_id) do
|
2017-07-24 09:17:42 -04:00
|
|
|
|
freeze_time(6.minutes.ago) do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: poll
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
::JSON.parse(response.body)["id"]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-08-10 03:15:29 -04:00
|
|
|
|
let(:poll_edit_window_mins) { 6 }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
SiteSetting.poll_edit_window_mins = poll_edit_window_mins
|
|
|
|
|
end
|
|
|
|
|
|
2015-09-25 12:54:15 -04:00
|
|
|
|
describe "with no vote" do
|
2015-04-23 13:33:29 -04:00
|
|
|
|
|
2015-09-25 12:54:15 -04:00
|
|
|
|
it "OP can change the options" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
put :update, params: {
|
|
|
|
|
id: post_id, post: { raw: new_option }
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-09-25 12:54:15 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["post"]["polls"]["poll"]["options"][1]["html"]).to eq("C")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "staff can change the options" do
|
|
|
|
|
log_in_user(Fabricate(:moderator))
|
2017-08-31 00:06:56 -04:00
|
|
|
|
|
|
|
|
|
put :update, params: {
|
|
|
|
|
id: post_id, post: { raw: new_option }
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-09-25 12:54:15 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["post"]["polls"]["poll"]["options"][1]["html"]).to eq("C")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "support changes on the post" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
put :update, params: { id: post_id, post: { raw: updated } }, format: :json
|
2015-09-25 12:54:15 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["post"]["cooked"]).to match("before")
|
|
|
|
|
end
|
2015-04-23 13:33:29 -04:00
|
|
|
|
|
2015-09-14 13:27:54 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "with at least one vote" do
|
|
|
|
|
|
|
|
|
|
before do
|
2016-07-29 02:47:23 -04:00
|
|
|
|
DiscoursePoll::Poll.vote(post_id, "poll", ["5c24fc1df56d764b550ceae1b9319125"], user)
|
2015-09-14 13:27:54 -04:00
|
|
|
|
end
|
|
|
|
|
|
2015-09-25 12:54:15 -04:00
|
|
|
|
it "OP cannot change the options" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
put :update, params: {
|
|
|
|
|
id: post_id, post: { raw: new_option }
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-09-25 12:54:15 -04:00
|
|
|
|
expect(response).not_to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
2016-08-10 03:15:29 -04:00
|
|
|
|
expect(json["errors"][0]).to eq(I18n.t(
|
|
|
|
|
"poll.edit_window_expired.op_cannot_edit_options",
|
|
|
|
|
minutes: poll_edit_window_mins
|
|
|
|
|
))
|
2015-09-25 12:54:15 -04:00
|
|
|
|
end
|
|
|
|
|
|
2016-04-15 17:26:18 -04:00
|
|
|
|
it "staff can change the options and votes are merged" do
|
|
|
|
|
log_in_user(Fabricate(:moderator))
|
2017-08-31 00:06:56 -04:00
|
|
|
|
|
|
|
|
|
put :update, params: {
|
|
|
|
|
id: post_id, post: { raw: new_option }
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2016-04-15 17:26:18 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["post"]["polls"]["poll"]["options"][1]["html"]).to eq("C")
|
|
|
|
|
expect(json["post"]["polls"]["poll"]["voters"]).to eq(1)
|
|
|
|
|
expect(json["post"]["polls"]["poll"]["options"][0]["votes"]).to eq(1)
|
|
|
|
|
expect(json["post"]["polls"]["poll"]["options"][1]["votes"]).to eq(0)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "staff can change the options and anonymous votes are merged" do
|
|
|
|
|
post = Post.find_by(id: post_id)
|
|
|
|
|
default_poll = post.custom_fields["polls"]["poll"]
|
2017-07-27 21:20:09 -04:00
|
|
|
|
add_anonymous_votes(post, default_poll, 7, "5c24fc1df56d764b550ceae1b9319125" => 7)
|
2016-04-15 17:26:18 -04:00
|
|
|
|
|
2015-09-25 12:54:15 -04:00
|
|
|
|
log_in_user(Fabricate(:moderator))
|
2017-08-31 00:06:56 -04:00
|
|
|
|
|
|
|
|
|
put :update, params: {
|
|
|
|
|
id: post_id, post: { raw: new_option }
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-09-25 12:54:15 -04:00
|
|
|
|
expect(response).to be_success
|
2016-04-15 17:26:18 -04:00
|
|
|
|
|
2015-09-25 12:54:15 -04:00
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["post"]["polls"]["poll"]["options"][1]["html"]).to eq("C")
|
2016-04-15 17:26:18 -04:00
|
|
|
|
expect(json["post"]["polls"]["poll"]["voters"]).to eq(8)
|
|
|
|
|
expect(json["post"]["polls"]["poll"]["options"][0]["votes"]).to eq(8)
|
|
|
|
|
expect(json["post"]["polls"]["poll"]["options"][1]["votes"]).to eq(0)
|
2015-09-25 12:54:15 -04:00
|
|
|
|
end
|
|
|
|
|
|
2015-09-14 13:27:54 -04:00
|
|
|
|
it "support changes on the post" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
put :update, params: { id: post_id, post: { raw: updated } }, format: :json
|
2015-09-14 13:27:54 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["post"]["cooked"]).to match("before")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "named polls" do
|
|
|
|
|
|
|
|
|
|
it "should have different options" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll name=""foo""]\n- A\n- A\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
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
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll name='foo']\n- A\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
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"))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "multiple polls" do
|
|
|
|
|
|
|
|
|
|
it "works" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll]\n- A\n- B\n[/poll]\n[poll name=foo]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["cooked"]).to match("data-poll-")
|
|
|
|
|
expect(json["polls"]["poll"]).to be
|
|
|
|
|
expect(json["polls"]["foo"]).to be
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "should have a name" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll]\n- A\n- B\n[/poll]\n[poll]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
expect(response).not_to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["errors"][0]).to eq(I18n.t("poll.multiple_polls_without_name"))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "should have unique name" do
|
2017-08-31 00:06:56 -04:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll name=foo]\n- A\n- B\n[/poll]\n[poll name=foo]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
2015-04-23 13:33:29 -04:00
|
|
|
|
expect(response).not_to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["errors"][0]).to eq(I18n.t("poll.multiple_polls_with_same_name", name: "foo"))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-04 08:47:11 -05:00
|
|
|
|
describe "disabled polls" do
|
|
|
|
|
before do
|
|
|
|
|
SiteSetting.poll_enabled = false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "doesn’t cook the poll" do
|
2017-12-04 18:03:56 -05:00
|
|
|
|
log_in_user(Fabricate(:user, admin: true, trust_level: 4))
|
|
|
|
|
|
2017-12-04 08:47:11 -05:00
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["cooked"]).to eq("<p>[poll]</p>\n<ul>\n<li>A</li>\n<li>B<br>\n[/poll]</li>\n</ul>")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-04 12:12:17 -05:00
|
|
|
|
describe "regular user with insufficient trust level" do
|
2017-12-04 08:47:11 -05:00
|
|
|
|
before do
|
|
|
|
|
SiteSetting.poll_minimum_trust_level_to_create = 2
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "invalidates the post" do
|
|
|
|
|
log_in_user(Fabricate(:user, trust_level: 1))
|
|
|
|
|
|
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
|
|
|
|
expect(response).not_to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
2017-12-04 12:12:17 -05:00
|
|
|
|
expect(json["errors"][0]).to eq(I18n.t("poll.insufficient_rights_to_create"))
|
2017-12-04 08:47:11 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-04 12:12:17 -05:00
|
|
|
|
describe "regular user with equal trust level" do
|
2017-12-04 08:47:11 -05:00
|
|
|
|
before do
|
|
|
|
|
SiteSetting.poll_minimum_trust_level_to_create = 2
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "validates the post" do
|
|
|
|
|
log_in_user(Fabricate(:user, trust_level: 2))
|
|
|
|
|
|
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["cooked"]).to match("data-poll-")
|
|
|
|
|
expect(json["polls"]["poll"]).to be
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-04 12:12:17 -05:00
|
|
|
|
describe "regular user with superior trust level" do
|
2017-12-04 08:47:11 -05:00
|
|
|
|
before do
|
|
|
|
|
SiteSetting.poll_minimum_trust_level_to_create = 2
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "validates the post" do
|
|
|
|
|
log_in_user(Fabricate(:user, trust_level: 3))
|
|
|
|
|
|
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["cooked"]).to match("data-poll-")
|
|
|
|
|
expect(json["polls"]["poll"]).to be
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-04 18:03:56 -05:00
|
|
|
|
describe "staff with insufficient trust level" do
|
2017-12-04 08:47:11 -05:00
|
|
|
|
before do
|
|
|
|
|
SiteSetting.poll_minimum_trust_level_to_create = 2
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "validates the post" do
|
2017-12-04 18:03:56 -05:00
|
|
|
|
log_in_user(Fabricate(:user, moderator: true, trust_level: 1))
|
2017-12-04 08:47:11 -05:00
|
|
|
|
|
|
|
|
|
post :create, params: {
|
|
|
|
|
title: title, raw: "[poll]\n- A\n- B\n[/poll]"
|
|
|
|
|
}, format: :json
|
|
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
expect(json["cooked"]).to match("data-poll-")
|
|
|
|
|
expect(json["polls"]["poll"]).to be
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-04-23 13:33:29 -04:00
|
|
|
|
end
|