Commit 7b87ed14 authored by Peter Leitzen's avatar Peter Leitzen Committed by Grzegorz Bizon

Cleanup usages of `JSON.parse` in specs

Prefer `json_response` where applicable.
parent e38a3bba
...@@ -41,7 +41,7 @@ describe Admin::ApplicationSettingsController do ...@@ -41,7 +41,7 @@ describe Admin::ApplicationSettingsController do
it 'returns JSON data' do it 'returns JSON data' do
get :usage_data, format: :json get :usage_data, format: :json
body = JSON.parse(response.body) body = json_response
expect(body["version"]).to eq(Gitlab::VERSION) expect(body["version"]).to eq(Gitlab::VERSION)
expect(body).to include('counts') expect(body).to include('counts')
expect(response.status).to eq(200) expect(response.status).to eq(200)
......
...@@ -63,8 +63,6 @@ describe ApplicationController do ...@@ -63,8 +63,6 @@ describe ApplicationController do
sign_in user sign_in user
end end
let(:json_response) { JSON.parse(response.body) }
controller(described_class) do controller(described_class) do
def index def index
render json: Gon.all_variables render json: Gon.all_variables
......
...@@ -52,10 +52,8 @@ describe Boards::IssuesController do ...@@ -52,10 +52,8 @@ describe Boards::IssuesController do
list_issues user: user, board: board, list: list2 list_issues user: user, board: board, list: list2
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('entities/issue_boards') expect(response).to match_response_schema('entities/issue_boards')
expect(parsed_response['issues'].length).to eq 2 expect(json_response['issues'].length).to eq 2
expect(development.issues.map(&:relative_position)).not_to include(nil) expect(development.issues.map(&:relative_position)).not_to include(nil)
end end
...@@ -123,10 +121,8 @@ describe Boards::IssuesController do ...@@ -123,10 +121,8 @@ describe Boards::IssuesController do
list_issues user: user, board: board list_issues user: user, board: board
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('entities/issue_boards') expect(response).to match_response_schema('entities/issue_boards')
expect(parsed_response['issues'].length).to eq 2 expect(json_response['issues'].length).to eq 2
end end
end end
......
...@@ -26,10 +26,8 @@ describe Boards::ListsController do ...@@ -26,10 +26,8 @@ describe Boards::ListsController do
read_board_list user: user, board: board read_board_list user: user, board: board
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('lists') expect(response).to match_response_schema('lists')
expect(parsed_response.length).to eq 3 expect(json_response.length).to eq 3
end end
context 'with unauthorized user' do context 'with unauthorized user' do
......
...@@ -63,10 +63,8 @@ describe Groups::BoardsController do ...@@ -63,10 +63,8 @@ describe Groups::BoardsController do
list_boards format: :json list_boards format: :json
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('boards') expect(response).to match_response_schema('boards')
expect(parsed_response.length).to eq 1 expect(json_response.length).to eq 1
end end
context 'with unauthorized user' do context 'with unauthorized user' do
......
...@@ -73,7 +73,7 @@ describe Groups::MilestonesController do ...@@ -73,7 +73,7 @@ describe Groups::MilestonesController do
it 'lists legacy group milestones and group milestones' do it 'lists legacy group milestones and group milestones' do
get :index, params: { group_id: group.to_param }, format: :json get :index, params: { group_id: group.to_param }, format: :json
milestones = JSON.parse(response.body) milestones = json_response
expect(milestones.count).to eq(2) expect(milestones.count).to eq(2)
expect(milestones.first["title"]).to eq("group milestone") expect(milestones.first["title"]).to eq("group milestone")
......
...@@ -5,7 +5,6 @@ require 'spec_helper' ...@@ -5,7 +5,6 @@ require 'spec_helper'
describe HealthCheckController do describe HealthCheckController do
include StubENV include StubENV
let(:json_response) { JSON.parse(response.body) }
let(:xml_response) { Hash.from_xml(response.body)['hash'] } let(:xml_response) { Hash.from_xml(response.body)['hash'] }
let(:token) { Gitlab::CurrentSettings.health_check_access_token } let(:token) { Gitlab::CurrentSettings.health_check_access_token }
let(:whitelisted_ip) { '127.0.0.1' } let(:whitelisted_ip) { '127.0.0.1' }
......
...@@ -5,7 +5,6 @@ require 'spec_helper' ...@@ -5,7 +5,6 @@ require 'spec_helper'
describe HealthController do describe HealthController do
include StubENV include StubENV
let(:json_response) { JSON.parse(response.body) }
let(:token) { Gitlab::CurrentSettings.health_check_access_token } let(:token) { Gitlab::CurrentSettings.health_check_access_token }
let(:whitelisted_ip) { '127.0.0.1' } let(:whitelisted_ip) { '127.0.0.1' }
let(:not_whitelisted_ip) { '127.0.0.2' } let(:not_whitelisted_ip) { '127.0.0.2' }
......
...@@ -5,7 +5,6 @@ require 'spec_helper' ...@@ -5,7 +5,6 @@ require 'spec_helper'
describe MetricsController do describe MetricsController do
include StubENV include StubENV
let(:json_response) { JSON.parse(response.body) }
let(:metrics_multiproc_dir) { Dir.mktmpdir } let(:metrics_multiproc_dir) { Dir.mktmpdir }
let(:whitelisted_ip) { '127.0.0.1' } let(:whitelisted_ip) { '127.0.0.1' }
let(:whitelisted_ip_range) { '10.0.0.0/24' } let(:whitelisted_ip_range) { '10.0.0.0/24' }
......
...@@ -160,7 +160,7 @@ describe Projects::BlobController do ...@@ -160,7 +160,7 @@ describe Projects::BlobController do
it 'renders diff context lines Gitlab::Diff::Line array' do it 'renders diff context lines Gitlab::Diff::Line array' do
do_get(since: 1, to: 2, offset: 0, from_merge_request: true) do_get(since: 1, to: 2, offset: 0, from_merge_request: true)
lines = JSON.parse(response.body) lines = json_response
expect(lines.size).to eq(diff_lines.size) expect(lines.size).to eq(diff_lines.size)
lines.each do |line| lines.each do |line|
...@@ -173,7 +173,7 @@ describe Projects::BlobController do ...@@ -173,7 +173,7 @@ describe Projects::BlobController do
it 'handles full being true' do it 'handles full being true' do
do_get(full: true, from_merge_request: true) do_get(full: true, from_merge_request: true)
lines = JSON.parse(response.body) lines = json_response
expect(lines.size).to eq(diff_lines.size) expect(lines.size).to eq(diff_lines.size)
end end
......
...@@ -69,10 +69,8 @@ describe Projects::BoardsController do ...@@ -69,10 +69,8 @@ describe Projects::BoardsController do
list_boards format: :json list_boards format: :json
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('boards') expect(response).to match_response_schema('boards')
expect(parsed_response.length).to eq 2 expect(json_response.length).to eq 2
end end
context 'with unauthorized user' do context 'with unauthorized user' do
......
...@@ -495,10 +495,8 @@ describe Projects::BranchesController do ...@@ -495,10 +495,8 @@ describe Projects::BranchesController do
search: 'master' search: 'master'
} }
parsed_response = JSON.parse(response.body) expect(json_response.length).to eq 1
expect(json_response.first).to eq 'master'
expect(parsed_response.length).to eq 1
expect(parsed_response.first).to eq 'master'
end end
end end
...@@ -591,8 +589,7 @@ describe Projects::BranchesController do ...@@ -591,8 +589,7 @@ describe Projects::BranchesController do
end end
it 'returns the commit counts behind and ahead of default branch' do it 'returns the commit counts behind and ahead of default branch' do
parsed_response = JSON.parse(response.body) expect(json_response).to eq(
expect(parsed_response).to eq(
"fix" => { "behind" => 29, "ahead" => 2 }, "fix" => { "behind" => 29, "ahead" => 2 },
"branch-merged" => { "behind" => 1, "ahead" => 0 }, "branch-merged" => { "behind" => 1, "ahead" => 0 },
"add-pdf-file" => { "behind" => 0, "ahead" => 3 } "add-pdf-file" => { "behind" => 0, "ahead" => 3 }
......
...@@ -378,8 +378,8 @@ describe Projects::CommitController do ...@@ -378,8 +378,8 @@ describe Projects::CommitController do
get_pipelines(id: commit.id, format: :json) get_pipelines(id: commit.id, format: :json)
expect(response).to be_ok expect(response).to be_ok
expect(JSON.parse(response.body)['pipelines']).not_to be_empty expect(json_response['pipelines']).not_to be_empty
expect(JSON.parse(response.body)['count']['all']).to eq 1 expect(json_response['count']['all']).to eq 1
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
end end
end end
......
...@@ -302,8 +302,7 @@ describe Projects::CompareController do ...@@ -302,8 +302,7 @@ describe Projects::CompareController do
signatures_request signatures_request
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
parsed_body = JSON.parse(response.body) signatures = json_response['signatures']
signatures = parsed_body['signatures']
expect(signatures.size).to eq(1) expect(signatures.size).to eq(1)
expect(signatures.first['commit_sha']).to eq(signature_commit.sha) expect(signatures.first['commit_sha']).to eq(signature_commit.sha)
...@@ -332,8 +331,7 @@ describe Projects::CompareController do ...@@ -332,8 +331,7 @@ describe Projects::CompareController do
signatures_request signatures_request
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
parsed_body = JSON.parse(response.body) expect(json_response['signatures']).to be_empty
expect(parsed_body['signatures']).to be_empty
end end
end end
...@@ -345,8 +343,7 @@ describe Projects::CompareController do ...@@ -345,8 +343,7 @@ describe Projects::CompareController do
signatures_request signatures_request
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
parsed_body = JSON.parse(response.body) expect(json_response['signatures']).to be_empty
expect(parsed_body['signatures']).to be_empty
end end
end end
end end
......
...@@ -52,12 +52,10 @@ describe Projects::DeployKeysController do ...@@ -52,12 +52,10 @@ describe Projects::DeployKeysController do
it 'returns json in a correct format' do it 'returns json in a correct format' do
get :index, params: params.merge(format: :json) get :index, params: params.merge(format: :json)
json = JSON.parse(response.body) expect(json_response.keys).to match_array(%w(enabled_keys available_project_keys public_keys))
expect(json_response['enabled_keys'].count).to eq(1)
expect(json.keys).to match_array(%w(enabled_keys available_project_keys public_keys)) expect(json_response['available_project_keys'].count).to eq(1)
expect(json['enabled_keys'].count).to eq(1) expect(json_response['public_keys'].count).to eq(1)
expect(json['available_project_keys'].count).to eq(1)
expect(json['public_keys'].count).to eq(1)
end end
end end
end end
......
...@@ -112,7 +112,7 @@ describe Projects::DiscussionsController do ...@@ -112,7 +112,7 @@ describe Projects::DiscussionsController do
it "returns the name of the resolving user" do it "returns the name of the resolving user" do
post :resolve, params: request_params post :resolve, params: request_params
expect(JSON.parse(response.body)['resolved_by']['name']).to eq(user.name) expect(json_response['resolved_by']['name']).to eq(user.name)
end end
it "returns status 200" do it "returns status 200" do
...@@ -135,7 +135,7 @@ describe Projects::DiscussionsController do ...@@ -135,7 +135,7 @@ describe Projects::DiscussionsController do
it "returns truncated diff lines" do it "returns truncated diff lines" do
post :resolve, params: request_params post :resolve, params: request_params
expect(JSON.parse(response.body)['truncated_diff_lines']).to be_present expect(json_response['truncated_diff_lines']).to be_present
end end
end end
end end
......
...@@ -53,10 +53,9 @@ describe Projects::FindFileController do ...@@ -53,10 +53,9 @@ describe Projects::FindFileController do
it 'returns an array of file path list' do it 'returns an array of file path list' do
go go
json = JSON.parse(response.body)
is_expected.to respond_with(:success) is_expected.to respond_with(:success)
expect(json).not_to eq(nil) expect(json_response).not_to eq(nil)
expect(json.length).to be >= 0 expect(json_response.length).to be >= 0
end end
end end
......
...@@ -444,7 +444,7 @@ describe Projects::IssuesController do ...@@ -444,7 +444,7 @@ describe Projects::IssuesController do
it 'renders json with recaptcha_html' do it 'renders json with recaptcha_html' do
subject subject
expect(JSON.parse(response.body)).to have_key('recaptcha_html') expect(json_response).to have_key('recaptcha_html')
end end
end end
end end
...@@ -484,10 +484,8 @@ describe Projects::IssuesController do ...@@ -484,10 +484,8 @@ describe Projects::IssuesController do
it 'returns last edited time' do it 'returns last edited time' do
go(id: issue.iid) go(id: issue.iid)
data = JSON.parse(response.body) expect(json_response).to include('updated_at')
expect(json_response['updated_at']).to eq(issue.last_edited_at.to_time.iso8601)
expect(data).to include('updated_at')
expect(data['updated_at']).to eq(issue.last_edited_at.to_time.iso8601)
end end
end end
...@@ -520,10 +518,8 @@ describe Projects::IssuesController do ...@@ -520,10 +518,8 @@ describe Projects::IssuesController do
it 'returns the necessary data' do it 'returns the necessary data' do
go(id: issue.iid) go(id: issue.iid)
data = JSON.parse(response.body) expect(json_response).to include('title_text', 'description', 'description_text')
expect(json_response).to include('task_status', 'lock_version')
expect(data).to include('title_text', 'description', 'description_text')
expect(data).to include('task_status', 'lock_version')
end end
end end
end end
...@@ -692,9 +688,7 @@ describe Projects::IssuesController do ...@@ -692,9 +688,7 @@ describe Projects::IssuesController do
update_issue(issue_params: { assignee_ids: [assignee.id] }) update_issue(issue_params: { assignee_ids: [assignee.id] })
body = JSON.parse(response.body) expect(json_response['assignees'].first.keys)
expect(body['assignees'].first.keys)
.to match_array(%w(id name username avatar_url state web_url)) .to match_array(%w(id name username avatar_url state web_url))
end end
end end
...@@ -1314,7 +1308,7 @@ describe Projects::IssuesController do ...@@ -1314,7 +1308,7 @@ describe Projects::IssuesController do
it 'filters notes that the user should not see' do it 'filters notes that the user should not see' do
get :discussions, params: { namespace_id: project.namespace, project_id: project, id: issue.iid } get :discussions, params: { namespace_id: project.namespace, project_id: project, id: issue.iid }
expect(JSON.parse(response.body).count).to eq(1) expect(json_response.count).to eq(1)
end end
it 'does not result in N+1 queries' do it 'does not result in N+1 queries' do
......
...@@ -112,7 +112,7 @@ describe Projects::MergeRequests::DiffsController do ...@@ -112,7 +112,7 @@ describe Projects::MergeRequests::DiffsController do
it 'only renders the diffs for the path given' do it 'only renders the diffs for the path given' do
diff_for_path(old_path: existing_path, new_path: existing_path) diff_for_path(old_path: existing_path, new_path: existing_path)
paths = JSON.parse(response.body)["diff_files"].map { |file| file['new_path'] } paths = json_response["diff_files"].map { |file| file['new_path'] }
expect(paths).to include(existing_path) expect(paths).to include(existing_path)
end end
......
...@@ -242,9 +242,7 @@ describe Projects::MergeRequestsController do ...@@ -242,9 +242,7 @@ describe Projects::MergeRequestsController do
update_merge_request({ assignee_ids: [assignee.id] }, format: :json) update_merge_request({ assignee_ids: [assignee.id] }, format: :json)
body = JSON.parse(response.body) expect(json_response['assignees']).to all(include(*%w(name username avatar_url id state web_url)))
expect(body['assignees']).to all(include(*%w(name username avatar_url id state web_url)))
end end
end end
......
...@@ -29,7 +29,7 @@ describe Projects::NotesController do ...@@ -29,7 +29,7 @@ describe Projects::NotesController do
} }
end end
let(:parsed_response) { JSON.parse(response.body).with_indifferent_access } let(:parsed_response) { json_response.with_indifferent_access }
let(:note_json) { parsed_response[:notes].first } let(:note_json) { parsed_response[:notes].first }
before do before do
...@@ -614,7 +614,7 @@ describe Projects::NotesController do ...@@ -614,7 +614,7 @@ describe Projects::NotesController do
it "returns the name of the resolving user" do it "returns the name of the resolving user" do
post :resolve, params: request_params.merge(html: true) post :resolve, params: request_params.merge(html: true)
expect(JSON.parse(response.body)["resolved_by"]).to eq(user.name) expect(json_response["resolved_by"]).to eq(user.name)
end end
it "returns status 200" do it "returns status 200" do
......
...@@ -7,7 +7,6 @@ describe Projects::TemplatesController do ...@@ -7,7 +7,6 @@ describe Projects::TemplatesController do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:file_path_1) { '.gitlab/issue_templates/issue_template.md' } let(:file_path_1) { '.gitlab/issue_templates/issue_template.md' }
let(:file_path_2) { '.gitlab/merge_request_templates/merge_request_template.md' } let(:file_path_2) { '.gitlab/merge_request_templates/merge_request_template.md' }
let(:body) { JSON.parse(response.body) }
let!(:file_1) { project.repository.create_file(user, file_path_1, 'issue content', message: 'message', branch_name: 'master') } let!(:file_1) { project.repository.create_file(user, file_path_1, 'issue content', message: 'message', branch_name: 'master') }
let!(:file_2) { project.repository.create_file(user, file_path_2, 'merge request content', message: 'message', branch_name: 'master') } let!(:file_2) { project.repository.create_file(user, file_path_2, 'merge request content', message: 'message', branch_name: 'master') }
...@@ -17,8 +16,8 @@ describe Projects::TemplatesController do ...@@ -17,8 +16,8 @@ describe Projects::TemplatesController do
get(:show, params: { namespace_id: project.namespace, template_type: 'issue', key: 'issue_template', project_id: project }, format: :json) get(:show, params: { namespace_id: project.namespace, template_type: 'issue', key: 'issue_template', project_id: project }, format: :json)
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(body['name']).to eq('issue_template') expect(json_response['name']).to eq('issue_template')
expect(body['content']).to eq('issue content') expect(json_response['content']).to eq('issue content')
end end
end end
...@@ -27,8 +26,8 @@ describe Projects::TemplatesController do ...@@ -27,8 +26,8 @@ describe Projects::TemplatesController do
get(:show, params: { namespace_id: project.namespace, template_type: 'merge_request', key: 'merge_request_template', project_id: project }, format: :json) get(:show, params: { namespace_id: project.namespace, template_type: 'merge_request', key: 'merge_request_template', project_id: project }, format: :json)
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(body['name']).to eq('merge_request_template') expect(json_response['name']).to eq('merge_request_template')
expect(body['content']).to eq('merge request content') expect(json_response['content']).to eq('merge request content')
end end
end end
......
...@@ -103,7 +103,7 @@ describe Projects::WikisController do ...@@ -103,7 +103,7 @@ describe Projects::WikisController do
it 'renders json in a correct format' do it 'renders json in a correct format' do
post :preview_markdown, params: { namespace_id: project.namespace, project_id: project, id: 'page/path', text: '*Markdown* text' } post :preview_markdown, params: { namespace_id: project.namespace, project_id: project, id: 'page/path', text: '*Markdown* text' }
expect(JSON.parse(response.body).keys).to match_array(%w(body references)) expect(json_response.keys).to match_array(%w(body references))
end end
end end
......
...@@ -740,20 +740,18 @@ describe ProjectsController do ...@@ -740,20 +740,18 @@ describe ProjectsController do
it 'gets a list of branches and tags' do it 'gets a list of branches and tags' do
get :refs, params: { namespace_id: project.namespace, id: project, sort: 'updated_desc' } get :refs, params: { namespace_id: project.namespace, id: project, sort: 'updated_desc' }
parsed_body = JSON.parse(response.body) expect(json_response['Branches']).to include('master')
expect(parsed_body['Branches']).to include('master') expect(json_response['Tags'].first).to eq('v1.1.0')
expect(parsed_body['Tags'].first).to eq('v1.1.0') expect(json_response['Tags'].last).to eq('v1.0.0')
expect(parsed_body['Tags'].last).to eq('v1.0.0') expect(json_response['Commits']).to be_nil
expect(parsed_body['Commits']).to be_nil
end end
it "gets a list of branches, tags and commits" do it "gets a list of branches, tags and commits" do
get :refs, params: { namespace_id: project.namespace, id: project, ref: "123456" } get :refs, params: { namespace_id: project.namespace, id: project, ref: "123456" }
parsed_body = JSON.parse(response.body) expect(json_response["Branches"]).to include("master")
expect(parsed_body["Branches"]).to include("master") expect(json_response["Tags"]).to include("v1.0.0")
expect(parsed_body["Tags"]).to include("v1.0.0") expect(json_response["Commits"]).to include("123456")
expect(parsed_body["Commits"]).to include("123456")
end end
context "when preferred language is Japanese" do context "when preferred language is Japanese" do
...@@ -765,10 +763,9 @@ describe ProjectsController do ...@@ -765,10 +763,9 @@ describe ProjectsController do
it "gets a list of branches, tags and commits" do it "gets a list of branches, tags and commits" do
get :refs, params: { namespace_id: project.namespace, id: project, ref: "123456" } get :refs, params: { namespace_id: project.namespace, id: project, ref: "123456" }
parsed_body = JSON.parse(response.body) expect(json_response["Branches"]).to include("master")
expect(parsed_body["Branches"]).to include("master") expect(json_response["Tags"]).to include("v1.0.0")
expect(parsed_body["Tags"]).to include("v1.0.0") expect(json_response["Commits"]).to include("123456")
expect(parsed_body["Commits"]).to include("123456")
end end
end end
...@@ -797,7 +794,7 @@ describe ProjectsController do ...@@ -797,7 +794,7 @@ describe ProjectsController do
it 'renders json in a correct format' do it 'renders json in a correct format' do
post :preview_markdown, params: { namespace_id: public_project.namespace, id: public_project, text: '*Markdown* text' } post :preview_markdown, params: { namespace_id: public_project.namespace, id: public_project, text: '*Markdown* text' }
expect(JSON.parse(response.body).keys).to match_array(%w(body references)) expect(json_response.keys).to match_array(%w(body references))
end end
context 'when not authorized' do context 'when not authorized' do
...@@ -821,8 +818,6 @@ describe ProjectsController do ...@@ -821,8 +818,6 @@ describe ProjectsController do
text: issue.to_reference text: issue.to_reference
} }
json_response = JSON.parse(response.body)
expect(json_response['body']).to match(/\##{issue.iid} \(closed\)/) expect(json_response['body']).to match(/\##{issue.iid} \(closed\)/)
end end
...@@ -833,8 +828,6 @@ describe ProjectsController do ...@@ -833,8 +828,6 @@ describe ProjectsController do
text: merge_request.to_reference text: merge_request.to_reference
} }
json_response = JSON.parse(response.body)
expect(json_response['body']).to match(/\!#{merge_request.iid} \(closed\)/) expect(json_response['body']).to match(/\!#{merge_request.iid} \(closed\)/)
end end
end end
......
...@@ -26,7 +26,7 @@ describe Snippets::NotesController do ...@@ -26,7 +26,7 @@ describe Snippets::NotesController do
end end
it "returns not empty array of notes" do it "returns not empty array of notes" do
expect(JSON.parse(response.body)["notes"].empty?).to be_falsey expect(json_response["notes"].empty?).to be_falsey
end end
end end
...@@ -97,7 +97,7 @@ describe Snippets::NotesController do ...@@ -97,7 +97,7 @@ describe Snippets::NotesController do
it "returns 1 note" do it "returns 1 note" do
get :index, params: { snippet_id: private_snippet } get :index, params: { snippet_id: private_snippet }
expect(JSON.parse(response.body)['notes'].count).to eq(1) expect(json_response['notes'].count).to eq(1)
end end
end end
end end
...@@ -114,7 +114,7 @@ describe Snippets::NotesController do ...@@ -114,7 +114,7 @@ describe Snippets::NotesController do
it "does not return any note" do it "does not return any note" do
get :index, params: { snippet_id: public_snippet } get :index, params: { snippet_id: public_snippet }
expect(JSON.parse(response.body)['notes'].count).to eq(0) expect(json_response['notes'].count).to eq(0)
end end
end end
end end
......
...@@ -622,7 +622,7 @@ describe SnippetsController do ...@@ -622,7 +622,7 @@ describe SnippetsController do
post :preview_markdown, params: { id: snippet, text: '*Markdown* text' } post :preview_markdown, params: { id: snippet, text: '*Markdown* text' }
expect(JSON.parse(response.body).keys).to match_array(%w(body references)) expect(json_response.keys).to match_array(%w(body references))
end end
end end
end end
...@@ -291,7 +291,7 @@ describe UsersController do ...@@ -291,7 +291,7 @@ describe UsersController do
it 'response with snippets json data' do it 'response with snippets json data' do
get :snippets, params: { username: user.username }, format: :json get :snippets, params: { username: user.username }, format: :json
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(JSON.parse(response.body)).to have_key('html') expect(json_response).to have_key('html')
end end
end end
......
...@@ -89,7 +89,7 @@ describe API::Search do ...@@ -89,7 +89,7 @@ describe API::Search do
it 'returns empty array' do it 'returns empty array' do
get api('/search', user), params: { scope: 'milestones', search: 'awesome' } get api('/search', user), params: { scope: 'milestones', search: 'awesome' }
milestones = JSON.parse(response.body) milestones = json_response
expect(milestones).to be_empty expect(milestones).to be_empty
end end
...@@ -356,7 +356,7 @@ describe API::Search do ...@@ -356,7 +356,7 @@ describe API::Search do
it 'returns empty array' do it 'returns empty array' do
get api("/projects/#{project.id}/search", user), params: { scope: 'milestones', search: 'awesome' } get api("/projects/#{project.id}/search", user), params: { scope: 'milestones', search: 'awesome' }
milestones = JSON.parse(response.body) milestones = json_response
expect(milestones).to be_empty expect(milestones).to be_empty
end end
......
...@@ -1439,8 +1439,4 @@ describe 'Git LFS API and storage' do ...@@ -1439,8 +1439,4 @@ describe 'Git LFS API and storage' do
post(url, params: params, headers: headers) post(url, params: params, headers: headers)
end end
def json_response
@json_response ||= JSON.parse(response.body)
end
end end
...@@ -163,8 +163,4 @@ describe 'Git LFS File Locking API' do ...@@ -163,8 +163,4 @@ describe 'Git LFS File Locking API' do
def do_get(url, params = nil, headers = nil) def do_get(url, params = nil, headers = nil)
get(url, params: (params || {}), headers: (headers || {}).merge('Content-Type' => LfsRequest::CONTENT_TYPE)) get(url, params: (params || {}), headers: (headers || {}).merge('Content-Type' => LfsRequest::CONTENT_TYPE))
end end
def json_response
@json_response ||= JSON.parse(response.body)
end
end end
RSpec.configure do |config| RSpec.configure do |config|
config.include_context 'JSON response' config.include_context 'JSON response', type: :controller
config.include_context 'JSON response', type: :request config.include_context 'JSON response', type: :request
config.include_context 'JSON response', :api config.include_context 'JSON response', :api
end end
...@@ -46,7 +46,7 @@ shared_examples 'issuable notes filter' do ...@@ -46,7 +46,7 @@ shared_examples 'issuable notes filter' do
user.set_notes_filter(UserPreference::NOTES_FILTERS[:only_comments], issuable) user.set_notes_filter(UserPreference::NOTES_FILTERS[:only_comments], issuable)
get :discussions, params: params get :discussions, params: params
discussions = JSON.parse(response.body) discussions = json_response
expect(discussions.count).to eq(1) expect(discussions.count).to eq(1)
expect(discussions.first["notes"].first["system"]).to be(false) expect(discussions.first["notes"].first["system"]).to be(false)
...@@ -56,7 +56,7 @@ shared_examples 'issuable notes filter' do ...@@ -56,7 +56,7 @@ shared_examples 'issuable notes filter' do
user.set_notes_filter(UserPreference::NOTES_FILTERS[:only_activity], issuable) user.set_notes_filter(UserPreference::NOTES_FILTERS[:only_activity], issuable)
get :discussions, params: params get :discussions, params: params
discussions = JSON.parse(response.body) discussions = json_response
expect(discussions.count).to eq(1) expect(discussions.count).to eq(1)
expect(discussions.first["notes"].first["system"]).to be(true) expect(discussions.first["notes"].first["system"]).to be(true)
......
...@@ -38,7 +38,7 @@ shared_examples 'update invalid issuable' do |klass| ...@@ -38,7 +38,7 @@ shared_examples 'update invalid issuable' do |klass|
put :update, params: params put :update, params: params
expect(response.status).to eq(409) expect(response.status).to eq(409)
expect(JSON.parse(response.body)).to have_key('errors') expect(json_response).to have_key('errors')
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment