Add rubocop to our build. (#5004)

This commit is contained in:
Guo Xiang Tan
2017-07-28 10:20:09 +09:00
committed by GitHub
parent ff4e295c4f
commit 5012d46cbd
871 changed files with 5480 additions and 6056 deletions

View File

@ -12,7 +12,7 @@ describe PostsController do
describe "polls" do
it "works" do
xhr :post, :create, { title: title, raw: "[poll]\n- A\n- B\n[/poll]" }
xhr :post, :create, title: title, raw: "[poll]\n- A\n- B\n[/poll]"
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["cooked"]).to match("data-poll-")
@ -21,7 +21,7 @@ describe PostsController do
it "works on any post" do
post = Fabricate(:post)
xhr :post, :create, { topic_id: post.topic.id, raw: "[poll]\n- A\n- B\n[/poll]" }
xhr :post, :create, topic_id: post.topic.id, raw: "[poll]\n- A\n- B\n[/poll]"
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["cooked"]).to match("data-poll-")
@ -29,14 +29,14 @@ describe PostsController do
end
it "should have different options" do
xhr :post, :create, { title: title, raw: "[poll]\n- A\n- A\n[/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\n[/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"))
@ -47,7 +47,7 @@ describe PostsController do
(SiteSetting.poll_maximum_options + 1).times { |n| raw << "\n- #{n}" }
raw << "\n[/poll]"
xhr :post, :create, { title: title, raw: raw }
xhr :post, :create, title: title, raw: raw
expect(response).not_to be_success
json = ::JSON.parse(response.body)
@ -55,14 +55,14 @@ 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\n[/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"))
end
it "prevents self-xss" do
xhr :post, :create, { title: title, raw: "[poll name=<script>alert('xss')</script>]\n- A\n- B\n[/poll]" }
xhr :post, :create, title: title, raw: "[poll name=<script>alert('xss')</script>]\n- A\n- B\n[/poll]"
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["cooked"]).to match("data-poll-")
@ -71,7 +71,7 @@ describe PostsController do
end
it "also works whe there is a link starting with '[poll'" do
xhr :post, :create, { title: title, raw: "[Polls are awesome](/foobar)\n[poll]\n- A\n- B\n[/poll]" }
xhr :post, :create, title: title, raw: "[Polls are awesome](/foobar)\n[poll]\n- A\n- B\n[/poll]"
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["cooked"]).to match("data-poll-")
@ -79,7 +79,7 @@ describe PostsController do
end
it "prevents pollception" do
xhr :post, :create, { title: title, raw: "[poll name=1]\n- A\n[poll name=2]\n- B\n- C\n[/poll]\n- D\n[/poll]" }
xhr :post, :create, title: title, raw: "[poll name=1]\n- A\n[poll name=2]\n- B\n- C\n[/poll]\n- D\n[/poll]"
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["cooked"]).to match("data-poll-")
@ -93,13 +93,13 @@ describe PostsController do
let(:post_id) do
freeze_time(4.minutes.ago) do
xhr :post, :create, { title: title, raw: "[poll]\n- A\n- B\n[/poll]" }
xhr :post, :create, title: title, raw: "[poll]\n- A\n- B\n[/poll]"
::JSON.parse(response.body)["id"]
end
end
it "can be changed" do
xhr :put, :update, { id: post_id, post: { raw: "[poll]\n- A\n- B\n- C\n[/poll]" } }
xhr :put, :update, id: post_id, post: { raw: "[poll]\n- A\n- B\n- C\n[/poll]" }
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["post"]["polls"]["poll"]["options"][2]["html"]).to eq("C")
@ -107,7 +107,7 @@ describe PostsController do
it "resets the votes" do
DiscoursePoll::Poll.vote(post_id, "poll", ["5c24fc1df56d764b550ceae1b9319125"], user)
xhr :put, :update, { id: post_id, post: { raw: "[poll]\n- A\n- B\n- C\n[/poll]" } }
xhr :put, :update, id: post_id, post: { raw: "[poll]\n- A\n- B\n- C\n[/poll]" }
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["post"]["polls_votes"]).to_not be
@ -123,7 +123,7 @@ describe PostsController do
let(:post_id) do
freeze_time(6.minutes.ago) do
xhr :post, :create, { title: title, raw: poll }
xhr :post, :create, title: title, raw: poll
::JSON.parse(response.body)["id"]
end
end
@ -137,7 +137,7 @@ describe PostsController do
describe "with no vote" do
it "OP can change the options" do
xhr :put, :update, { id: post_id, post: { raw: new_option } }
xhr :put, :update, id: post_id, post: { raw: new_option }
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["post"]["polls"]["poll"]["options"][1]["html"]).to eq("C")
@ -145,14 +145,14 @@ describe PostsController do
it "staff can change the options" do
log_in_user(Fabricate(:moderator))
xhr :put, :update, { id: post_id, post: { raw: new_option } }
xhr :put, :update, id: post_id, post: { raw: new_option }
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
xhr :put, :update, { id: post_id, post: { raw: updated } }
xhr :put, :update, id: post_id, post: { raw: updated }
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["post"]["cooked"]).to match("before")
@ -167,7 +167,7 @@ describe PostsController do
end
it "OP cannot change the options" do
xhr :put, :update, { id: post_id, post: { raw: new_option } }
xhr :put, :update, id: post_id, post: { raw: new_option }
expect(response).not_to be_success
json = ::JSON.parse(response.body)
expect(json["errors"][0]).to eq(I18n.t(
@ -178,7 +178,7 @@ describe PostsController do
it "staff can change the options and votes are merged" do
log_in_user(Fabricate(:moderator))
xhr :put, :update, { id: post_id, post: { raw: new_option } }
xhr :put, :update, id: post_id, post: { raw: new_option }
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["post"]["polls"]["poll"]["options"][1]["html"]).to eq("C")
@ -190,10 +190,10 @@ describe PostsController do
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"]
add_anonymous_votes(post, default_poll, 7, {"5c24fc1df56d764b550ceae1b9319125" => 7})
add_anonymous_votes(post, default_poll, 7, "5c24fc1df56d764b550ceae1b9319125" => 7)
log_in_user(Fabricate(:moderator))
xhr :put, :update, { id: post_id, post: { raw: new_option } }
xhr :put, :update, id: post_id, post: { raw: new_option }
expect(response).to be_success
json = ::JSON.parse(response.body)
@ -204,7 +204,7 @@ describe PostsController do
end
it "support changes on the post" do
xhr :put, :update, { id: post_id, post: { raw: updated } }
xhr :put, :update, id: post_id, post: { raw: updated }
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["post"]["cooked"]).to match("before")
@ -221,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\n[/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\n[/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"))
@ -239,7 +239,7 @@ describe PostsController do
describe "multiple polls" do
it "works" do
xhr :post, :create, { title: title, raw: "[poll]\n- A\n- B\n[/poll]\n[poll name=foo]\n- A\n- B\n[/poll]" }
xhr :post, :create, title: title, raw: "[poll]\n- A\n- B\n[/poll]\n[poll name=foo]\n- A\n- B\n[/poll]"
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["cooked"]).to match("data-poll-")
@ -248,14 +248,14 @@ describe PostsController do
end
it "should have a name" do
xhr :post, :create, { title: title, raw: "[poll]\n- A\n- B\n[/poll]\n[poll]\n- A\n- B\n[/poll]" }
xhr :post, :create, title: title, raw: "[poll]\n- A\n- B\n[/poll]\n[poll]\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.multiple_polls_without_name"))
end
it "should have unique name" do
xhr :post, :create, { title: title, raw: "[poll name=foo]\n- A\n- B\n[/poll]\n[poll name=foo]\n- A\n- B\n[/poll]" }
xhr :post, :create, title: title, raw: "[poll name=foo]\n- A\n- B\n[/poll]\n[poll name=foo]\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.multiple_polls_with_same_name", name: "foo"))