Skip to content

Commit

Permalink
Conform to RSpecRails/HaveHttpStatus cop
Browse files Browse the repository at this point in the history
With a hack to get `have_http_status` to work with `Rack::MockResponse`.
  • Loading branch information
cbliard committed Jun 24, 2024
1 parent 6684a95 commit a885fef
Show file tree
Hide file tree
Showing 102 changed files with 410 additions and 372 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
let(:target_user) { user_with_avatar }

it "renders the send file" do
expect(response.status).to eq 200
expect(response).to have_http_status :ok
end
end

context "when user has no avatar" do
let(:target_user) { user_without_avatar }

it "renders 404" do
expect(response.status).to eq 404
expect(response).to have_http_status :not_found
end
end
end
Expand All @@ -51,7 +51,7 @@
let(:target_user) { user_with_avatar }

it "renders a 404" do
expect(response.status).to eq 404
expect(response).to have_http_status :not_found
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions modules/avatars/spec/controllers/avatars/my_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@

it "renders 404" do
post :update
expect(response.status).to eq 404
expect(response).to have_http_status :not_found
end
end

it "returns invalid method for post request" do
post :update
expect(response).not_to be_successful
expect(response.status).to eq 405
expect(response).to have_http_status :method_not_allowed
end

it "calls the service for put" do
Expand All @@ -54,7 +54,7 @@

put :update
expect(response).to be_successful
expect(response.status).to eq 200
expect(response).to have_http_status :ok
end

it "calls the service for put" do
Expand All @@ -64,15 +64,15 @@

put :update
expect(response).not_to be_successful
expect(response.status).to eq 400
expect(response).to have_http_status :bad_request
end
end

describe "#delete" do
it "returns invalid method for post request" do
post :destroy
expect(response).not_to be_successful
expect(response.status).to eq 405
expect(response).to have_http_status :method_not_allowed
end

it "calls the service for delete" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
end

it "renders 403" do
expect(response.status).to eq 403
expect(response).to have_http_status :forbidden
end
end
end
Expand All @@ -55,14 +55,14 @@

it "renders 404" do
put :update, params: { id: target_user.id }
expect(response.status).to eq 404
expect(response).to have_http_status :not_found
end
end

it "returns invalid method for post request" do
post :update, params: { id: target_user.id }
expect(response).not_to be_successful
expect(response.status).to eq 405
expect(response).to have_http_status :method_not_allowed
end

it "calls the service for put" do
Expand All @@ -72,7 +72,7 @@

put :update, params: { id: target_user.id }
expect(response).to be_successful
expect(response.status).to eq 200
expect(response).to have_http_status :ok
end

it "calls the service for put" do
Expand All @@ -82,7 +82,7 @@

put :update, params: { id: target_user.id }
expect(response).not_to be_successful
expect(response.status).to eq 400
expect(response).to have_http_status :bad_request
end
end

Expand All @@ -101,7 +101,7 @@
it "returns invalid method for post request" do
post :destroy, params: { id: target_user.id }
expect(response).not_to be_successful
expect(response.status).to eq 405
expect(response).to have_http_status :method_not_allowed
end

it "calls the service for delete" do
Expand Down
8 changes: 4 additions & 4 deletions modules/avatars/spec/requests/user_avatar_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
let(:local_avatars) { false }

it "renders a 404" do
expect(response.status).to eq 404
expect(response).to have_http_status :not_found
end
end

Expand All @@ -80,7 +80,7 @@
let(:local_avatars) { false }

it "redirects to gravatar" do
expect(response.status).to eq 302
expect(response).to have_http_status :found
expect(response.location).to match /gravatar\.com/
end

Expand All @@ -98,7 +98,7 @@
end

it "serves the attachment file" do
expect(response.status).to eq 200
expect(response).to have_http_status :ok
end

it_behaves_like "cache headers set to 24 hours"
Expand All @@ -117,7 +117,7 @@
# so here we just make sue it's called accordingly when the external
# storage is configured
it "redirects to temporary external URL" do
expect(response.status).to eq 302
expect(response).to have_http_status :found
expect(response.location).to eq "external URL"
end
end
Expand Down
2 changes: 1 addition & 1 deletion modules/backlogs/spec/api/work_package_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

include_context "query work package"

it { expect(last_response.status).to be 200 }
it { expect(last_response).to have_http_status :ok }

it { is_expected.not_to have_json_path("storyPoints") }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
shared_examples_for "valid payload" do
subject { response.body }

it { expect(response.status).to eq(200) }
it { expect(response).to have_http_status(:ok) }

it { is_expected.to have_json_path("_embedded/payload") }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

it "fails" do
get :show
expect(response.status).to eq 403
expect(response).to have_http_status :forbidden
end
end
end
Expand Down Expand Up @@ -102,7 +102,7 @@
subject

expect(response).not_to be_successful
expect(response.status).to eq 403
expect(response).to have_http_status :forbidden
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions modules/bim/spec/requests/api/bcf/v2_1/topics_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def expected_body_for_bcf_issue(
end

it "responds with a not authorized error" do
expect(response.status).to eq 403
expect(response).to have_http_status :forbidden
expect(response.body).to include "You are not authorized to access this resource."
end
end
Expand All @@ -707,7 +707,7 @@ def expected_body_for_bcf_issue(
end

it "responds with a not authorized error" do
expect(response.status).to eq 404
expect(response).to have_http_status :not_found
expect(response.body).to include "The requested resource could not be found."
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
context "when user is not logged in" do
it "requires login" do
post set_direct_upload_file_name_bcf_project_ifc_models_path(project_id: project.id)
expect(last_response.status).to eq(406) # rubocop:disable RSpecRails/HaveHttpStatus
expect(last_response).to have_http_status(:not_acceptable)
end
end

Expand All @@ -47,7 +47,7 @@
it "returns a 422" do
post set_direct_upload_file_name_bcf_project_ifc_models_path(project_id: project.id),
{ title: "Test.ifc", isDefault: "0", filesize: "113328073" }
expect(last_response.status).to eq(422) # rubocop:disable RSpecRails/HaveHttpStatus
expect(last_response).to have_http_status(:unprocessable_entity)
expect(parse_json(last_response.body)).to eq({ "error" => "is too large (maximum size is 1024 Bytes)." })
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

describe "#POST /api/v3/time_entries/form" do
it "returns 200 OK" do
expect(response.status).to eq(200)
expect(response).to have_http_status(:ok)
end

it "returns a form" do
Expand Down Expand Up @@ -190,7 +190,7 @@
let(:permissions) { [] }

it "returns 403 Not Authorized" do
expect(response.status).to eq(403)
expect(response).to have_http_status(:forbidden)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

describe "#POST /api/v3/time_entries/:id/form" do
it "returns 200 OK" do
expect(response.status).to eq(200)
expect(response).to have_http_status(:ok)
end

it "returns a form" do
Expand Down Expand Up @@ -205,13 +205,13 @@
end

it "returns 200 OK" do
expect(response.status).to eq(200)
expect(response).to have_http_status(:ok)
end
end

context "with the time_entry being of a different user" do
it "returns 403 Not Authorized" do
expect(response.status).to eq(403)
expect(response).to have_http_status(:forbidden)
end
end
end
Expand All @@ -220,7 +220,7 @@
let(:permissions) { %i[view_time_entries] }

it "returns 403 Not Authorized" do
expect(response.status).to eq(403)
expect(response).to have_http_status(:forbidden)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
end

it "responds with 200" do
expect(response.status).to eq(200) # rubocop:disable RSpecRails/HaveHttpStatus
expect(response).to have_http_status(:ok)
end

it "does not include the core SHA in the res" do
Expand All @@ -79,7 +79,7 @@
end

it "responds with 200" do
expect(response.status).to eq(200) # rubocop:disable RSpecRails/HaveHttpStatus
expect(response).to have_http_status(:ok)
end

it "does includes the core SHA in the response" do
Expand Down
Loading

0 comments on commit a885fef

Please sign in to comment.