DEV: Use `response.parsed_body` in specs (#9615)

DEV: Use response.parsed_body in specs (#9615)

Most of it was autofixed with rubocop-discourse 2.1.1.

diff --git a/plugins/poll/spec/controllers/polls_controller_spec.rb b/plugins/poll/spec/controllers/polls_controller_spec.rb
index 74f1582..9534a5c 100644
--- a/plugins/poll/spec/controllers/polls_controller_spec.rb
+++ b/plugins/poll/spec/controllers/polls_controller_spec.rb
@@ -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
diff --git a/plugins/poll/spec/controllers/posts_controller_spec.rb b/plugins/poll/spec/controllers/posts_controller_spec.rb
index 3cedf90..be26174 100644
--- a/plugins/poll/spec/controllers/posts_controller_spec.rb
+++ b/plugins/poll/spec/controllers/posts_controller_spec.rb
@@ -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)

[... diff too long, it was truncated ...]

GitHub sha: 781e3f5e

1 Like

This commit appears in #9615 which was approved by eviltrout. It was merged by CvX.