mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
DEV: Use response.parsed_body
in specs (#9615)
Most of it was autofixed with rubocop-discourse 2.1.1.
This commit is contained in:
@ -25,7 +25,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["poll"]["name"]).to eq("poll")
|
||||
expect(json["poll"]["voters"]).to eq(1)
|
||||
expect(json["vote"]).to eq(["5c24fc1df56d764b550ceae1b9319125"])
|
||||
@ -53,7 +53,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["poll"]["name"]).to eq("poll")
|
||||
expect(json["poll"]["voters"]).to eq(1)
|
||||
expect(json["vote"]).to eq(["5c24fc1df56d764b550ceae1b9319125"])
|
||||
@ -80,7 +80,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["poll"]["name"]).to eq("poll")
|
||||
expect(json["poll"]["voters"]).to eq(1)
|
||||
expect(json["vote"]).to eq(["5c24fc1df56d764b550ceae1b9319125"])
|
||||
@ -96,7 +96,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).not_to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.requires_at_least_1_valid_option"))
|
||||
end
|
||||
|
||||
@ -112,7 +112,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["poll"]["voters"]).to eq(1)
|
||||
expect(json["poll"]["options"][0]["votes"]).to eq(0)
|
||||
expect(json["poll"]["options"][1]["votes"]).to eq(1)
|
||||
@ -136,7 +136,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).not_to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.topic_must_be_open_to_vote"))
|
||||
end
|
||||
|
||||
@ -148,7 +148,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).not_to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.post_is_deleted"))
|
||||
end
|
||||
|
||||
@ -160,7 +160,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).not_to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.user_cant_post_in_topic"))
|
||||
end
|
||||
|
||||
@ -170,7 +170,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).not_to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.no_poll_with_this_name", name: "foobar"))
|
||||
end
|
||||
|
||||
@ -182,7 +182,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).not_to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.poll_must_be_open_to_vote"))
|
||||
end
|
||||
|
||||
@ -194,7 +194,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).not_to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("js.poll.results.groups.title", groups: poll.polls.first.groups))
|
||||
end
|
||||
|
||||
@ -210,7 +210,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["poll"]["voters"]).to eq(18)
|
||||
expect(json["poll"]["options"][0]["votes"]).to eq(12)
|
||||
expect(json["poll"]["options"][1]["votes"]).to eq(6)
|
||||
@ -230,7 +230,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
expect(response.status).to eq(200)
|
||||
end.first
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["poll"]["status"]).to eq("closed")
|
||||
expect(message.channel).to eq(channel)
|
||||
end
|
||||
@ -248,7 +248,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
expect(response.status).to eq(200)
|
||||
end.first
|
||||
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["poll"]["status"]).to eq("closed")
|
||||
expect(message.channel).to eq(channel)
|
||||
end
|
||||
@ -261,7 +261,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).not_to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.post_is_deleted"))
|
||||
end
|
||||
|
||||
@ -303,7 +303,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
|
||||
# no user3 cause voter_limit is 2
|
||||
expect(json["voters"][first].map { |h| h["id"] }).to contain_exactly(user1.id, user2.id)
|
||||
@ -323,7 +323,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
|
||||
expect(json["voters"][first].size).to eq(1)
|
||||
|
||||
@ -347,7 +347,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
|
||||
expect(json["voters"][first].size).to eq(1)
|
||||
expect(json["voters"][second].size).to eq(1)
|
||||
@ -378,7 +378,7 @@ describe ::DiscoursePoll::PollsController do
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
|
||||
expect(json["voters"][first].size).to eq(1)
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["cooked"]).to match("data-poll-")
|
||||
expect(Poll.exists?(post_id: json["id"])).to eq(true)
|
||||
end
|
||||
@ -30,7 +30,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["cooked"]).to match("data-poll-")
|
||||
expect(Poll.exists?(post_id: json["id"])).to eq(true)
|
||||
end
|
||||
@ -49,7 +49,7 @@ describe PostsController do
|
||||
change { Poll.count }.by(1)
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
post_id = json["id"]
|
||||
|
||||
expect(Poll.find_by(post_id: post_id).close_at).to eq_time(close_date)
|
||||
@ -67,7 +67,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_successful
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_different_options"))
|
||||
end
|
||||
|
||||
@ -77,7 +77,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_successful
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_at_least_1_option"))
|
||||
end
|
||||
|
||||
@ -91,7 +91,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_successful
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_less_options", count: SiteSetting.poll_maximum_options))
|
||||
end
|
||||
|
||||
@ -101,7 +101,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_successful
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_with_multiple_choices_has_invalid_parameters"))
|
||||
end
|
||||
|
||||
@ -111,7 +111,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["cooked"]).to match("data-poll-")
|
||||
expect(json["cooked"]).to include("<script>")
|
||||
expect(Poll.find_by(post_id: json["id"]).name).to eq("<script>alert('xss')</script>")
|
||||
@ -123,7 +123,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["cooked"]).to match("data-poll-")
|
||||
expect(Poll.exists?(post_id: json["id"])).to eq(true)
|
||||
end
|
||||
@ -134,7 +134,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["cooked"]).to match("data-poll-")
|
||||
expect(Poll.where(post_id: json["id"]).count).to eq(1)
|
||||
end
|
||||
@ -149,7 +149,7 @@ describe PostsController do
|
||||
title: title, raw: "[poll]\n- A\n- B\n[/poll]"
|
||||
}, format: :json
|
||||
|
||||
::JSON.parse(response.body)["id"]
|
||||
response.parsed_body["id"]
|
||||
end
|
||||
end
|
||||
|
||||
@ -159,7 +159,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["post"]["polls"][0]["options"][2]["html"]).to eq("C")
|
||||
end
|
||||
|
||||
@ -171,7 +171,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["post"]["polls_votes"]).to_not be
|
||||
end
|
||||
|
||||
@ -189,7 +189,7 @@ describe PostsController do
|
||||
title: title, raw: poll
|
||||
}, format: :json
|
||||
|
||||
::JSON.parse(response.body)["id"]
|
||||
response.parsed_body["id"]
|
||||
end
|
||||
end
|
||||
|
||||
@ -207,14 +207,14 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["post"]["polls"][0]["options"][1]["html"]).to eq("C")
|
||||
end
|
||||
|
||||
it "support changes on the post" do
|
||||
put :update, params: { id: post_id, post: { raw: updated } }, format: :json
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["post"]["cooked"]).to match("before")
|
||||
end
|
||||
|
||||
@ -232,7 +232,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_successful
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t(
|
||||
"poll.edit_window_expired.cannot_edit_default_poll_with_votes",
|
||||
minutes: poll_edit_window_mins
|
||||
@ -242,7 +242,7 @@ describe PostsController do
|
||||
it "support changes on the post" do
|
||||
put :update, params: { id: post_id, post: { raw: updated } }, format: :json
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["post"]["cooked"]).to match("before")
|
||||
end
|
||||
|
||||
@ -262,7 +262,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_successful
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.named_poll_must_have_different_options", name: "foo"))
|
||||
end
|
||||
|
||||
@ -272,7 +272,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_successful
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.named_poll_must_have_at_least_1_option", name: "foo"))
|
||||
end
|
||||
|
||||
@ -286,7 +286,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["cooked"]).to match("data-poll-")
|
||||
expect(Poll.where(post_id: json["id"]).count).to eq(2)
|
||||
end
|
||||
@ -297,7 +297,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_successful
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.multiple_polls_without_name"))
|
||||
end
|
||||
|
||||
@ -307,7 +307,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_successful
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.multiple_polls_with_same_name", name: "foo"))
|
||||
end
|
||||
|
||||
@ -326,7 +326,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_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
|
||||
@ -344,7 +344,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response).not_to be_successful
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["errors"][0]).to eq(I18n.t("poll.insufficient_rights_to_create"))
|
||||
end
|
||||
|
||||
@ -362,7 +362,7 @@ describe PostsController do
|
||||
topic_id: topic.id, raw: "[poll]\n- A\n- B\n[/poll]"
|
||||
}, format: :json
|
||||
|
||||
expect(::JSON.parse(response.body)["errors"]).to eq(nil)
|
||||
expect(response.parsed_body["errors"]).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
@ -379,7 +379,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["cooked"]).to match("data-poll-")
|
||||
expect(Poll.exists?(post_id: json["id"])).to eq(true)
|
||||
end
|
||||
@ -398,7 +398,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["cooked"]).to match("data-poll-")
|
||||
expect(Poll.exists?(post_id: json["id"])).to eq(true)
|
||||
end
|
||||
@ -417,7 +417,7 @@ describe PostsController do
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
json = response.parsed_body
|
||||
expect(json["cooked"]).to match("data-poll-")
|
||||
expect(Poll.exists?(post_id: json["id"])).to eq(true)
|
||||
end
|
||||
|
Reference in New Issue
Block a user