mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: must be able to post in a topic in order to vote on a poll
This commit is contained in:
@ -47,6 +47,11 @@ after_initialize do
|
|||||||
raise StandardError.new I18n.t("poll.topic_must_be_open_to_vote")
|
raise StandardError.new I18n.t("poll.topic_must_be_open_to_vote")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# user must be allowed to post in topic
|
||||||
|
unless Guardian.new(user).can_create_post?(post.topic)
|
||||||
|
raise StandardError.new I18n.t("poll.user_cant_post_in_topic")
|
||||||
|
end
|
||||||
|
|
||||||
polls = post.custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD]
|
polls = post.custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD]
|
||||||
|
|
||||||
raise StandardError.new I18n.t("poll.no_polls_associated_with_this_post") if polls.blank?
|
raise StandardError.new I18n.t("poll.no_polls_associated_with_this_post") if polls.blank?
|
||||||
|
@ -55,6 +55,7 @@ describe ::DiscoursePoll::PollsController do
|
|||||||
|
|
||||||
it "works even if topic is closed" do
|
it "works even if topic is closed" do
|
||||||
topic.update_attribute(:closed, true)
|
topic.update_attribute(:closed, true)
|
||||||
|
|
||||||
put :vote, params: {
|
put :vote, params: {
|
||||||
post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"]
|
post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"]
|
||||||
}, format: :json
|
}, format: :json
|
||||||
@ -64,6 +65,7 @@ describe ::DiscoursePoll::PollsController do
|
|||||||
|
|
||||||
it "ensures topic is not archived" do
|
it "ensures topic is not archived" do
|
||||||
topic.update_attribute(:archived, true)
|
topic.update_attribute(:archived, true)
|
||||||
|
|
||||||
put :vote, params: {
|
put :vote, params: {
|
||||||
post_id: poll.id, poll_name: "poll", options: ["A"]
|
post_id: poll.id, poll_name: "poll", options: ["A"]
|
||||||
}, format: :json
|
}, format: :json
|
||||||
@ -75,6 +77,7 @@ describe ::DiscoursePoll::PollsController do
|
|||||||
|
|
||||||
it "ensures post is not trashed" do
|
it "ensures post is not trashed" do
|
||||||
poll.trash!
|
poll.trash!
|
||||||
|
|
||||||
put :vote, params: {
|
put :vote, params: {
|
||||||
post_id: poll.id, poll_name: "poll", options: ["A"]
|
post_id: poll.id, poll_name: "poll", options: ["A"]
|
||||||
}, format: :json
|
}, format: :json
|
||||||
@ -84,6 +87,18 @@ describe ::DiscoursePoll::PollsController do
|
|||||||
expect(json["errors"][0]).to eq(I18n.t("poll.post_is_deleted"))
|
expect(json["errors"][0]).to eq(I18n.t("poll.post_is_deleted"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "ensures user can post in topic" do
|
||||||
|
Guardian.any_instance.expects(:can_create_post?).returns(false)
|
||||||
|
|
||||||
|
put :vote, params: {
|
||||||
|
post_id: poll.id, poll_name: "poll", options: ["A"]
|
||||||
|
}, format: :json
|
||||||
|
|
||||||
|
expect(response).not_to be_success
|
||||||
|
json = ::JSON.parse(response.body)
|
||||||
|
expect(json["errors"][0]).to eq(I18n.t("poll.user_cant_post_in_topic"))
|
||||||
|
end
|
||||||
|
|
||||||
it "ensures polls are associated with the post" do
|
it "ensures polls are associated with the post" do
|
||||||
put :vote, params: {
|
put :vote, params: {
|
||||||
post_id: Fabricate(:post).id, poll_name: "foobar", options: ["A"]
|
post_id: Fabricate(:post).id, poll_name: "foobar", options: ["A"]
|
||||||
|
Reference in New Issue
Block a user