diff --git a/.rubocop.yml b/.rubocop.yml index ef318056fdef..f5ab796a4f67 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -236,10 +236,6 @@ RSpec/DescribeMethod: RSpec/SpecFilePathFormat: IgnoreMethods: true -# Disable deprecated cop -RSpec/FilePath: - Enabled: false - # Prevent "fit" or similar to be committed RSpec/Focus: Enabled: true diff --git a/modules/avatars/spec/controllers/avatars/avatar_controller_spec.rb b/modules/avatars/spec/controllers/avatars/avatar_controller_spec.rb index e4dbd8bdd8aa..0567ee30f8bd 100644 --- a/modules/avatars/spec/controllers/avatars/avatar_controller_spec.rb +++ b/modules/avatars/spec/controllers/avatars/avatar_controller_spec.rb @@ -33,7 +33,7 @@ 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 @@ -41,7 +41,7 @@ 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 @@ -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 diff --git a/modules/avatars/spec/controllers/avatars/my_controller_spec.rb b/modules/avatars/spec/controllers/avatars/my_controller_spec.rb index 636327804265..8359b7a3049e 100644 --- a/modules/avatars/spec/controllers/avatars/my_controller_spec.rb +++ b/modules/avatars/spec/controllers/avatars/my_controller_spec.rb @@ -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 @@ -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 @@ -64,7 +64,7 @@ put :update expect(response).not_to be_successful - expect(response.status).to eq 400 + expect(response).to have_http_status :bad_request end end @@ -72,7 +72,7 @@ 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 diff --git a/modules/avatars/spec/controllers/avatars/users_controller_spec.rb b/modules/avatars/spec/controllers/avatars/users_controller_spec.rb index 387803007d95..065d1f241269 100644 --- a/modules/avatars/spec/controllers/avatars/users_controller_spec.rb +++ b/modules/avatars/spec/controllers/avatars/users_controller_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/modules/avatars/spec/requests/user_avatar_api_spec.rb b/modules/avatars/spec/requests/user_avatar_api_spec.rb index 182d1e32e17e..02f1a165fa5c 100644 --- a/modules/avatars/spec/requests/user_avatar_api_spec.rb +++ b/modules/avatars/spec/requests/user_avatar_api_spec.rb @@ -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 @@ -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 @@ -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" @@ -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 diff --git a/modules/backlogs/spec/api/work_package_resource_spec.rb b/modules/backlogs/spec/api/work_package_resource_spec.rb index d2cc6590f82e..3c8f3b727773 100644 --- a/modules/backlogs/spec/api/work_package_resource_spec.rb +++ b/modules/backlogs/spec/api/work_package_resource_spec.rb @@ -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 diff --git a/modules/backlogs/spec/api/work_packages/form_resource_spec.rb b/modules/backlogs/spec/api/work_packages/form_resource_spec.rb index d779a3628f08..3d00016ea386 100644 --- a/modules/backlogs/spec/api/work_packages/form_resource_spec.rb +++ b/modules/backlogs/spec/api/work_packages/form_resource_spec.rb @@ -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") } diff --git a/modules/backlogs/spec/controllers/backlogs_settings_controller_spec.rb b/modules/backlogs/spec/controllers/backlogs_settings_controller_spec.rb index cd0116e2550f..b253fc6e5ad9 100644 --- a/modules/backlogs/spec/controllers/backlogs_settings_controller_spec.rb +++ b/modules/backlogs/spec/controllers/backlogs_settings_controller_spec.rb @@ -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 @@ -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 diff --git a/modules/bim/spec/requests/api/bcf/v2_1/topics_api_spec.rb b/modules/bim/spec/requests/api/bcf/v2_1/topics_api_spec.rb index 918736f945cf..244145c444e8 100644 --- a/modules/bim/spec/requests/api/bcf/v2_1/topics_api_spec.rb +++ b/modules/bim/spec/requests/api/bcf/v2_1/topics_api_spec.rb @@ -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 @@ -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 diff --git a/modules/bim/spec/requests/ifc_models/set_direct_upload_filename_spec.rb b/modules/bim/spec/requests/ifc_models/set_direct_upload_filename_spec.rb index 99f468207fa0..e86c1cd3650c 100644 --- a/modules/bim/spec/requests/ifc_models/set_direct_upload_filename_spec.rb +++ b/modules/bim/spec/requests/ifc_models/set_direct_upload_filename_spec.rb @@ -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 @@ -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 diff --git a/modules/costs/spec/requests/api/time_entries/create_form_resource_spec.rb b/modules/costs/spec/requests/api/time_entries/create_form_resource_spec.rb index fc326820b9ff..6f29298d3b4b 100644 --- a/modules/costs/spec/requests/api/time_entries/create_form_resource_spec.rb +++ b/modules/costs/spec/requests/api/time_entries/create_form_resource_spec.rb @@ -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 @@ -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 diff --git a/modules/costs/spec/requests/api/time_entries/update_form_resource_spec.rb b/modules/costs/spec/requests/api/time_entries/update_form_resource_spec.rb index 2b5166332a31..123958ce1b08 100644 --- a/modules/costs/spec/requests/api/time_entries/update_form_resource_spec.rb +++ b/modules/costs/spec/requests/api/time_entries/update_form_resource_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/modules/github_integration/spec/requests/extended_root_resource_spec.rb b/modules/github_integration/spec/requests/extended_root_resource_spec.rb index 03422d4e26e7..80fb2cb55132 100644 --- a/modules/github_integration/spec/requests/extended_root_resource_spec.rb +++ b/modules/github_integration/spec/requests/extended_root_resource_spec.rb @@ -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 @@ -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 diff --git a/modules/ldap_groups/spec/controllers/synchronized_groups_controller_spec.rb b/modules/ldap_groups/spec/controllers/synchronized_groups_controller_spec.rb index e6699c875cb3..a600b3218ae0 100644 --- a/modules/ldap_groups/spec/controllers/synchronized_groups_controller_spec.rb +++ b/modules/ldap_groups/spec/controllers/synchronized_groups_controller_spec.rb @@ -17,7 +17,7 @@ let(:logged_in_user) { user } it "does not give access" do - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -38,7 +38,7 @@ it "does not give access" do get :show, params: { ldap_group_id: id } - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -50,7 +50,7 @@ it "renders 404" do get :show, params: { ldap_group_id: id } - expect(response.status).to eq(404) + expect(response).to have_http_status(:not_found) end end @@ -78,7 +78,7 @@ it "does not give access" do get :new - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -106,7 +106,7 @@ let(:params) { {} } it "does not give access" do - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -117,7 +117,7 @@ let(:params) { {} } it "renders 400" do - expect(response.status).to eq(400) + expect(response).to have_http_status(:bad_request) end end @@ -135,7 +135,7 @@ context "and saving fails" do it "renders new page" do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(response).to render_template :new end end @@ -150,7 +150,7 @@ it "does not give access" do get :destroy_info, params: { ldap_group_id: id } - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -162,7 +162,7 @@ it "renders 404" do get :destroy_info, params: { ldap_group_id: id } - expect(response.status).to eq(404) + expect(response).to have_http_status(:not_found) end end @@ -191,7 +191,7 @@ it "does not give access" do delete :destroy, params: { ldap_group_id: id } - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -203,7 +203,7 @@ it "renders 404" do delete :destroy, params: { ldap_group_id: id } - expect(response.status).to eq(404) + expect(response).to have_http_status(:not_found) end end diff --git a/modules/meeting/spec/requests/api/v3/meetings/meetings_resource_spec.rb b/modules/meeting/spec/requests/api/v3/meetings/meetings_resource_spec.rb index ce5637d5989f..5d95cc0309ff 100644 --- a/modules/meeting/spec/requests/api/v3/meetings/meetings_resource_spec.rb +++ b/modules/meeting/spec/requests/api/v3/meetings/meetings_resource_spec.rb @@ -54,7 +54,7 @@ context "when valid id" do it "returns HTTP 200" do - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok end end @@ -62,7 +62,7 @@ let(:permissions) { [:view_work_packages] } it "returns HTTP 404" do - expect(last_response.status).to eq 404 + expect(last_response).to have_http_status :not_found end end diff --git a/modules/recaptcha/spec/controllers/admin_controller_spec.rb b/modules/recaptcha/spec/controllers/admin_controller_spec.rb index b621683c2e76..881057e8945a 100644 --- a/modules/recaptcha/spec/controllers/admin_controller_spec.rb +++ b/modules/recaptcha/spec/controllers/admin_controller_spec.rb @@ -12,10 +12,10 @@ it "does not allow access" do get :show - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden post :update - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end diff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb index 1fa11b3698b7..7b1ad6e7cd6e 100644 --- a/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb +++ b/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb @@ -247,7 +247,7 @@ def disable_module(project, modul) let(:path) { "#{api_v3_paths.file_links(work_package.id)}?filters=#{CGI.escape(filters.to_json)}" } it "return a 400 HTTP error" do - expect(last_response.status).to be 400 + expect(last_response).to have_http_status :bad_request end end end @@ -636,7 +636,7 @@ def disable_module(project, modul) let(:error) { :not_found } it "fails with outbound request failure" do - expect(last_response.status).to be(500) + expect(last_response).to have_http_status(:internal_server_error) body = JSON.parse(last_response.body) expect(body["message"]).to eq(I18n.t("api_v3.errors.code_500_outbound_request_failure", status_code: 404)) diff --git a/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb b/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb index ec601f9c5703..f317c0f07668 100644 --- a/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb +++ b/modules/storages/spec/requests/api/v3/storages/storage_files_api_spec.rb @@ -31,7 +31,6 @@ require "spec_helper" require_module_spec_helper -# rubocop:disable RSpecRails/HaveHttpStatus RSpec.describe "API v3 storage files", :webmock, content_type: :json do include API::V3::Utilities::PathHelper include StorageServerHelpers @@ -137,20 +136,20 @@ context "with authorization failure" do let(:error) { :unauthorized } - it { expect(last_response.status).to be(500) } + it { expect(last_response).to have_http_status(:internal_server_error) } end context "with internal error" do let(:error) { :error } - it { expect(last_response.status).to be(500) } + it { expect(last_response).to have_http_status(:internal_server_error) } end context "with not found" do let(:error) { :not_found } it "fails with outbound request failure" do - expect(last_response.status).to be(500) + expect(last_response).to have_http_status(:internal_server_error) body = JSON.parse(last_response.body) expect(body["message"]).to eq(I18n.t("api_v3.errors.code_500_outbound_request_failure", status_code: 404)) @@ -218,7 +217,7 @@ let(:error) { :forbidden } it "fails with outbound request failure" do - expect(last_response.status).to be(500) + expect(last_response).to have_http_status(:internal_server_error) body = JSON.parse(last_response.body) expect(body["message"]).to eq(I18n.t("api_v3.errors.code_500_outbound_request_failure", status_code: 403)) @@ -229,14 +228,14 @@ context "with internal error" do let(:error) { :error } - it { expect(last_response.status).to be(500) } + it { expect(last_response).to have_http_status(:internal_server_error) } end context "with not found" do let(:error) { :not_found } it "fails with outbound request failure" do - expect(last_response.status).to be(500) + expect(last_response).to have_http_status(:internal_server_error) body = JSON.parse(last_response.body) expect(body["message"]).to eq(I18n.t("api_v3.errors.code_500_outbound_request_failure", status_code: 404)) @@ -288,20 +287,20 @@ describe "due to authorization failure" do let(:error) { :unauthorized } - it { expect(last_response.status).to be(500) } + it { expect(last_response).to have_http_status(:internal_server_error) } end describe "due to internal error" do let(:error) { :error } - it { expect(last_response.status).to be(500) } + it { expect(last_response).to have_http_status(:internal_server_error) } end describe "due to not found" do let(:error) { :not_found } it "fails with outbound request failure" do - expect(last_response.status).to be(500) + expect(last_response).to have_http_status(:internal_server_error) body = JSON.parse(last_response.body) expect(body["message"]).to eq(I18n.t("api_v3.errors.code_500_outbound_request_failure", status_code: 404)) @@ -313,15 +312,13 @@ context "with invalid request body" do let(:body) { { fileNam_: "ape.png", parent: "/Pictures", projectId: project.id }.to_json } - it { expect(last_response.status).to be(400) } + it { expect(last_response).to have_http_status(:bad_request) } end context "without ee token", with_ee: false do let(:storage) { create(:one_drive_storage, creator: current_user) } - it { expect(last_response.status).to be(500) } + it { expect(last_response).to have_http_status(:internal_server_error) } end end end - -# rubocop:enable RSpecRails/HaveHttpStatus diff --git a/modules/storages/spec/requests/project_storages_open_spec.rb b/modules/storages/spec/requests/project_storages_open_spec.rb index 9db041b8c55e..d5f61a9cc25a 100644 --- a/modules/storages/spec/requests/project_storages_open_spec.rb +++ b/modules/storages/spec/requests/project_storages_open_spec.rb @@ -65,7 +65,7 @@ it "redirects to api_v3_projects_storage_open_url" do get route, {}, { "HTTP_ACCEPT" => "text/html" } - expect(last_response.status).to eq (302) + expect(last_response).to have_http_status(:found) expect(last_response.headers["Location"]).to eq(expected_redirect_url) end end @@ -74,7 +74,7 @@ it "renders an appropirate turbo_stream" do get route, {}, { "HTTP_ACCEPT" => "text/vnd.turbo-stream.html" } - expect(last_response.status).to eq (200) + expect(last_response).to have_http_status(:ok) expect(last_response.body).to eq ("\n \n\n\n") end end @@ -99,7 +99,7 @@ it "redirects to ensure_connection url with current request url as a destination_url" do get route, {}, { "HTTP_ACCEPT" => "text/html" } - expect(last_response.status).to eq (302) + expect(last_response).to have_http_status(:found) expect(last_response.headers["Location"]).to eq ( "http://example.org/oauth_clients/#{storage.oauth_client.client_id}/ensure_connection?destination_url=http%3A%2F%2Fexample.org%2Fprojects%2F#{project.identifier}%2Fproject_storages%2F#{project_storage.id}%2Fopen&storage_id=#{storage.id}" ) @@ -110,7 +110,7 @@ it "redirects to project overview page with modal flash set up" do get route, {}, { "HTTP_ACCEPT" => "text/html" } - expect(last_response.status).to eq (302) + expect(last_response).to have_http_status(:found) expect(last_response.headers["Location"]).to eq ("http://example.org/projects/#{project.identifier}") expect(last_request.session["flash"]["flashes"]) .to eq({ @@ -129,7 +129,7 @@ it "responds with 204 no content" do get route, {}, { "HTTP_ACCEPT" => "text/vnd.turbo-stream.html" } - expect(last_response.status).to eq (204) + expect(last_response).to have_http_status(:no_content) expect(last_response.body).to eq ("") end end @@ -141,7 +141,7 @@ it "redirects to project overview page with modal flash set up" do get route, {}, { "HTTP_ACCEPT" => "text/html" } - expect(last_response.status).to eq (302) + expect(last_response).to have_http_status(:found) expect(last_response.headers["Location"]).to eq ("http://example.org/projects/#{project.identifier}") expect(last_request.session["flash"]["flashes"]) .to eq({ @@ -159,7 +159,7 @@ it "responds with 204 no content" do get route, {}, { "HTTP_ACCEPT" => "text/vnd.turbo-stream.html" } - expect(last_response.status).to eq (204) + expect(last_response).to have_http_status(:no_content) expect(last_response.body).to eq ("") end end @@ -170,7 +170,7 @@ it "redirects to storage_open_url" do get route, {}, { "HTTP_ACCEPT" => "text/html" } - expect(last_response.status).to eq (302) + expect(last_response).to have_http_status(:found) expect(last_response.headers["Location"]).to eq (expected_redirect_url) end end @@ -181,7 +181,7 @@ it "responds with 403" do get route, {}, { "HTTP_ACCEPT" => "text/html" } - expect(last_response.status).to eq(403) + expect(last_response).to have_http_status(:forbidden) end end end @@ -189,7 +189,7 @@ context "when user is not logged in" do it "responds with 401" do get route - expect(last_response.status).to eq(401) + expect(last_response).to have_http_status(:unauthorized) end end end diff --git a/modules/storages/spec/requests/storages/project_settings/oauth_access_grant_flow_spec.rb b/modules/storages/spec/requests/storages/project_settings/oauth_access_grant_flow_spec.rb index f925e9a49a11..eb2def019f97 100644 --- a/modules/storages/spec/requests/storages/project_settings/oauth_access_grant_flow_spec.rb +++ b/modules/storages/spec/requests/storages/project_settings/oauth_access_grant_flow_spec.rb @@ -55,7 +55,7 @@ project_id: project_storage.project.id, id: project_storage ) - expect(last_response.status).to eq(401) + expect(last_response).to have_http_status(:unauthorized) end end @@ -78,7 +78,7 @@ project_id: project_storage.project.id, id: project_storage ) - expect(last_response.status).to eq(302) + expect(last_response).to have_http_status(:found) expect(last_response.location).to eq( "#{storage.host}/index.php/apps/oauth2/authorize?client_id=#{storage.oauth_client.client_id}&" \ "redirect_uri=#{redirect_uri}&response_type=code&state=#{nonce}" @@ -104,7 +104,7 @@ ) storage.oauth_client - expect(last_response.status).to eq(302) + expect(last_response).to have_http_status(:found) expect(last_response.location).to eq("http://example.org/projects/#{project.id}/settings/project_storages/external_file_storages") expect(last_response.cookies.keys).to eq(["_open_project_session"]) end diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb index 82208614009b..6edf06bba568 100644 --- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb +++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb @@ -33,7 +33,7 @@ end it "returns a 500" do - expect(response.status).to eq 500 + expect(response).to have_http_status :internal_server_error end end diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb index 2f07ea2454ca..7822efd1f351 100644 --- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb +++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb @@ -48,7 +48,7 @@ context "when logged in, but not enabled" do it "does not give access" do - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end @@ -123,7 +123,7 @@ describe "#get" do it "croaks on missing id" do get :confirm, params: { device_id: 1234 } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end describe "and registered totp device" do @@ -162,7 +162,7 @@ describe "#post" do it "croaks on missing id" do get :confirm, params: { device_id: 1234 } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end describe "and registered totp device" do diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb index 3715283ff620..08560809f191 100644 --- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb +++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb @@ -42,7 +42,7 @@ context "when logged in, but not enabled" do it "does not give access" do - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end @@ -117,7 +117,7 @@ describe "#get" do it "croaks on missing id" do get :confirm, params: { device_id: 1234 } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end describe "and registered totp device" do @@ -156,7 +156,7 @@ describe "#post" do it "croaks on missing id" do get :confirm, params: { device_id: 1234 } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end describe "and registered totp device" do @@ -226,7 +226,7 @@ describe "#destroy" do it "croaks on missing id" do delete :destroy, params: { device_id: "1234" } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end context "assuming password check is valid" do diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/users/two_factor_devices_controller_spec.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/users/two_factor_devices_controller_spec.rb index a3765104c703..a843d38dc376 100644 --- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/users/two_factor_devices_controller_spec.rb +++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/users/two_factor_devices_controller_spec.rb @@ -35,7 +35,7 @@ let(:logged_in_user) { other_user } it "does not give access" do - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -43,7 +43,7 @@ let(:logged_in_user) { user } it "does not give access" do - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -59,7 +59,7 @@ let(:active_strategies) { [] } it "renders a 404 because no strategies enabled" do - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end end @@ -182,7 +182,7 @@ describe "#destroy" do it "croaks on missing id" do delete :destroy, params: { id: user.id, device_id: "1234" } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end context "with existing non-default device" do diff --git a/modules/webhooks/spec/controllers/outgoing/admin_controller_spec.rb b/modules/webhooks/spec/controllers/outgoing/admin_controller_spec.rb index 449c04b3c769..0c57a2576a6a 100644 --- a/modules/webhooks/spec/controllers/outgoing/admin_controller_spec.rb +++ b/modules/webhooks/spec/controllers/outgoing/admin_controller_spec.rb @@ -40,7 +40,7 @@ it "renders 403" do get :index - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -139,7 +139,7 @@ it "renders 404" do get :edit, params: { webhook_id: "1234" } expect(response).not_to be_successful - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end end @@ -157,7 +157,7 @@ it "renders an error" do put :update, params: { webhook_id: "bar" } expect(response).not_to be_successful - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index d836668e2c83..305f4ed5e47b 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -181,7 +181,7 @@ end it "renders 404" do - expect(response.status).to eq(404) + expect(response).to have_http_status(:not_found) end end end @@ -195,7 +195,7 @@ end it "is forbidden" do - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end end diff --git a/spec/controllers/forums_controller_spec.rb b/spec/controllers/forums_controller_spec.rb index b2df0e6b6847..a9304c329e87 100644 --- a/spec/controllers/forums_controller_spec.rb +++ b/spec/controllers/forums_controller_spec.rb @@ -74,7 +74,7 @@ context "when not login_required", with_settings: { login_required: false } do it "renders 404 for not found" do get :index, params: { project_id: "not found" } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end end diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 12857c576280..bd903af6ae8d 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -179,7 +179,7 @@ it "forbids index" do get :index expect(response).not_to be_successful - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end it "shows" do @@ -191,7 +191,7 @@ it "forbids new" do get :new expect(response).not_to be_successful - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end it "forbids create" do @@ -200,14 +200,14 @@ end.not_to(change(Group, :count)) expect(response).not_to be_successful - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end it "forbids edit" do get :edit, params: { id: group.id } expect(response).not_to be_successful - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end end diff --git a/spec/controllers/homescreen_controller_spec.rb b/spec/controllers/homescreen_controller_spec.rb index 2d1b8eabfad0..92c19e4d53b4 100644 --- a/spec/controllers/homescreen_controller_spec.rb +++ b/spec/controllers/homescreen_controller_spec.rb @@ -46,7 +46,7 @@ shared_examples "renders blocks" do it "renders a response" do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end describe "with rendered views" do diff --git a/spec/controllers/my_controller_spec.rb b/spec/controllers/my_controller_spec.rb index 627a500e55a6..3b2fc53d5397 100644 --- a/spec/controllers/my_controller_spec.rb +++ b/spec/controllers/my_controller_spec.rb @@ -212,7 +212,7 @@ let!(:user_session) { Sessions::UserSession.find_by(session_id: "internal_foobar") } let(:params) do - { user: { mail: "foo@example.org"} } + { user: { mail: "foo@example.org" } } end it "clears other sessions and removes tokens" do diff --git a/spec/controllers/placeholder_users/memberships_controller_spec.rb b/spec/controllers/placeholder_users/memberships_controller_spec.rb index b4bf36edf6e6..f8e5e28c4c50 100644 --- a/spec/controllers/placeholder_users/memberships_controller_spec.rb +++ b/spec/controllers/placeholder_users/memberships_controller_spec.rb @@ -70,7 +70,7 @@ } } - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -81,7 +81,7 @@ id: 1234 } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end @@ -92,7 +92,7 @@ id: 1234 } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end end @@ -126,7 +126,7 @@ } } - expect(response.status).to eq 302 + expect(response).to have_http_status :found expect(placeholder_user.reload.memberships).to be_empty end end @@ -142,7 +142,7 @@ id: membership.id } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end @@ -153,7 +153,7 @@ id: membership.id } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end end diff --git a/spec/controllers/placeholder_users_controller_spec.rb b/spec/controllers/placeholder_users_controller_spec.rb index 401464a45a11..f1c371a40a4f 100644 --- a/spec/controllers/placeholder_users_controller_spec.rb +++ b/spec/controllers/placeholder_users_controller_spec.rb @@ -35,7 +35,7 @@ shared_examples "do not allow non-admins" do it "responds with unauthorized status" do expect(response).not_to be_successful - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -348,7 +348,7 @@ it "responds with unauthorized status" do expect(response).not_to be_successful - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -359,7 +359,7 @@ it "responds with unauthorized status" do expect(response).not_to be_successful - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end end diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index ec6ae981a623..db43e15d6b68 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -156,7 +156,7 @@ it "shows an error" do get "copy", params: { id: project.id } - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end end diff --git a/spec/controllers/types_controller_spec.rb b/spec/controllers/types_controller_spec.rb index 88e8a5f7e736..8c8b464ec2c3 100644 --- a/spec/controllers/types_controller_spec.rb +++ b/spec/controllers/types_controller_spec.rb @@ -53,7 +53,7 @@ describe "the access should be restricted" do before { get "index" } - it { expect(response.status).to eq(403) } + it { expect(response).to have_http_status(:forbidden) } end end @@ -61,7 +61,7 @@ describe "the access should be restricted" do before { get "new" } - it { expect(response.status).to eq(403) } + it { expect(response).to have_http_status(:forbidden) } end end @@ -69,7 +69,7 @@ describe "the access should be restricted" do before { get "edit", params: { id: "123" } } - it { expect(response.status).to eq(403) } + it { expect(response).to have_http_status(:forbidden) } end end @@ -77,7 +77,7 @@ describe "the access should be restricted" do before { post "create" } - it { expect(response.status).to eq(403) } + it { expect(response).to have_http_status(:forbidden) } end end @@ -85,7 +85,7 @@ describe "the access should be restricted" do before { delete "destroy", params: { id: "123" } } - it { expect(response.status).to eq(403) } + it { expect(response).to have_http_status(:forbidden) } end end @@ -93,7 +93,7 @@ describe "the access should be restricted" do before { post "update", params: { id: "123" } } - it { expect(response.status).to eq(403) } + it { expect(response).to have_http_status(:forbidden) } end end @@ -101,7 +101,7 @@ describe "the access should be restricted" do before { post "move", params: { id: "123" } } - it { expect(response.status).to eq(403) } + it { expect(response).to have_http_status(:forbidden) } end end end @@ -161,7 +161,7 @@ post :create, params: end - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "shows an error message" do expect(response.body).to have_content("Name can't be blank") diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 9c590f3b7aad..30719976b887 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -194,7 +194,7 @@ end it "returns 403 forbidden" do - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -401,7 +401,7 @@ let(:change_action) { :wtf } it "renders 400" do - expect(response.status).to eq(400) + expect(response).to have_http_status(:bad_request) expect(response).not_to render_template "users/change_status_info" end end diff --git a/spec/controllers/versions_controller_spec.rb b/spec/controllers/versions_controller_spec.rb index 38ae203668d3..9883e8ed6fde 100644 --- a/spec/controllers/versions_controller_spec.rb +++ b/spec/controllers/versions_controller_spec.rb @@ -243,7 +243,7 @@ it "renders correctly" do login_as(user) get :new, params: { project_id: project.id } - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end end diff --git a/spec/controllers/wiki_controller_spec.rb b/spec/controllers/wiki_controller_spec.rb index 9adb49497620..0b0d4822b703 100644 --- a/spec/controllers/wiki_controller_spec.rb +++ b/spec/controllers/wiki_controller_spec.rb @@ -110,7 +110,7 @@ it "renders 404 if used with an unknown page title" do get "new_child", params: { project_id: project, id: "foobar" } - expect(response.status).to eq(404) # not found + expect(response).to have_http_status(:not_found) end end diff --git a/spec/controllers/wiki_menu_authentication_spec.rb b/spec/controllers/wiki_menu_authentication_spec.rb index f67dc5b33bcc..7ec8ec5c3b40 100644 --- a/spec/controllers/wiki_menu_authentication_spec.rb +++ b/spec/controllers/wiki_menu_authentication_spec.rb @@ -62,7 +62,7 @@ get "edit", params: @params - expect(response.status).to eq(403) # forbidden + expect(response).to have_http_status(:forbidden) end end end diff --git a/spec/requests/api/v3/activities_by_work_package_resource_spec.rb b/spec/requests/api/v3/activities_by_work_package_resource_spec.rb index eb8198d6c67c..18ae1c9fd0e0 100644 --- a/spec/requests/api/v3/activities_by_work_package_resource_spec.rb +++ b/spec/requests/api/v3/activities_by_work_package_resource_spec.rb @@ -52,14 +52,14 @@ end it "succeeds" do - expect(last_response.status).to be 200 + expect(last_response).to have_http_status :ok end context "not allowed to see work package" do let(:current_user) { create(:user) } it "fails with HTTP Not Found" do - expect(last_response.status).to be 404 + expect(last_response).to have_http_status :not_found end end end @@ -96,7 +96,7 @@ include_context "create activity" it "responds with error" do - expect(last_response.status).to be 422 + expect(last_response).to have_http_status :unprocessable_entity end it "notes the error" do diff --git a/spec/requests/api/v3/attachments_spec.rb b/spec/requests/api/v3/attachments_spec.rb index 3385e8b8dc9d..6fbd11c32b5a 100644 --- a/spec/requests/api/v3/attachments_spec.rb +++ b/spec/requests/api/v3/attachments_spec.rb @@ -55,7 +55,7 @@ let(:permissions) { [] } it "forbids to prepare attachments" do - expect(last_response.status).to eq 403 + expect(last_response).to have_http_status :forbidden end end @@ -63,7 +63,7 @@ let(:permissions) { [:edit_work_packages] } it "can prepare attachments" do - expect(last_response.status).to eq 201 + expect(last_response).to have_http_status :created end end @@ -71,7 +71,7 @@ let(:permissions) { [:add_work_package_attachments] } it "can prepare attachments" do - expect(last_response.status).to eq 201 + expect(last_response).to have_http_status :created end end end @@ -94,7 +94,7 @@ let(:status) { :uploaded } it "returns 404" do - expect(last_response.status).to eq 404 + expect(last_response).to have_http_status :not_found end end @@ -104,7 +104,7 @@ end it "responds with HTTP OK" do - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok end it "returns the attachment representation" do diff --git a/spec/requests/api/v3/authentication_spec.rb b/spec/requests/api/v3/authentication_spec.rb index 10ee53ab5769..ca642ee1d4c5 100644 --- a/spec/requests/api/v3/authentication_spec.rb +++ b/spec/requests/api/v3/authentication_spec.rb @@ -48,7 +48,7 @@ let(:oauth_access_token) { token.plaintext_token } it "authenticates successfully" do - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok end end @@ -56,7 +56,7 @@ let(:oauth_access_token) { "1337" } it "returns unauthorized" do - expect(last_response.status).to eq 401 + expect(last_response).to have_http_status :unauthorized end end @@ -65,7 +65,7 @@ let(:oauth_access_token) { token.plaintext_token } it "returns unauthorized" do - expect(last_response.status).to eq 401 + expect(last_response).to have_http_status :unauthorized end end end @@ -97,7 +97,7 @@ def set_basic_auth_header(user, password) end it "returns 401 unauthorized" do - expect(last_response.status).to eq 401 + expect(last_response).to have_http_status :unauthorized end end end @@ -109,7 +109,7 @@ def set_basic_auth_header(user, password) end it "returns 401 unauthorized" do - expect(last_response.status).to eq 401 + expect(last_response).to have_http_status :unauthorized end it "returns the correct JSON response" do @@ -131,7 +131,7 @@ def set_basic_auth_header(user, password) end it "returns 401 unauthorized" do - expect(last_response.status).to eq 401 + expect(last_response).to have_http_status :unauthorized end it "returns the correct JSON response" do @@ -156,7 +156,7 @@ def set_basic_auth_header(user, password) end it "returns 401 unauthorized" do - expect(last_response.status).to eq 401 + expect(last_response).to have_http_status :unauthorized end it "returns the correct JSON response" do @@ -183,7 +183,7 @@ def set_basic_auth_header(user, password) end it "returns 401 unauthorized" do - expect(last_response.status).to eq 401 + expect(last_response).to have_http_status :unauthorized end it "returns the correct JSON response" do @@ -207,7 +207,7 @@ def set_basic_auth_header(user, password) end it "returns 200 OK" do - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok end end end @@ -276,7 +276,7 @@ def set_basic_auth_header(user, password) end it "returns 200 OK" do - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok end it '"login"s the anonymous user' do @@ -291,7 +291,7 @@ def set_basic_auth_header(user, password) end it "returns 401 unauthorized" do - expect(last_response.status).to eq 401 + expect(last_response).to have_http_status :unauthorized end end @@ -302,7 +302,7 @@ def set_basic_auth_header(user, password) end it "returns 200 OK" do - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok end end @@ -313,7 +313,7 @@ def set_basic_auth_header(user, password) end it "returns 200 OK" do - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok end end end diff --git a/spec/requests/api/v3/backups/backups_api_spec.rb b/spec/requests/api/v3/backups/backups_api_spec.rb index dc964fc06b5d..190e0dd1df4c 100644 --- a/spec/requests/api/v3/backups/backups_api_spec.rb +++ b/spec/requests/api/v3/backups/backups_api_spec.rb @@ -59,7 +59,7 @@ def create_backup include_context "request" it "results in a bad request error" do - expect(last_response.status).to eq 400 + expect(last_response).to have_http_status :bad_request end end @@ -74,7 +74,7 @@ def create_backup end it "enqueues the backup including attachments" do - expect(last_response.status).to eq 202 + expect(last_response).to have_http_status :accepted end end @@ -91,7 +91,7 @@ def create_backup end it "enqueues a backup not including attachments" do - expect(last_response.status).to eq 202 + expect(last_response).to have_http_status :accepted end end end @@ -103,7 +103,7 @@ def create_backup include_context "request" it "results in a conflict" do - expect(last_response.status).to eq 409 + expect(last_response).to have_http_status :conflict end end @@ -113,7 +113,7 @@ def create_backup include_context "request" it "is forbidden" do - expect(last_response.status).to eq 403 + expect(last_response).to have_http_status :forbidden end end @@ -124,7 +124,7 @@ def create_backup include_context "request" it "is forbidden" do - expect(last_response.status).to eq 403 + expect(last_response).to have_http_status :forbidden end end @@ -132,7 +132,7 @@ def create_backup include_context "request" it "is rate limited" do - expect(last_response.status).to eq 429 + expect(last_response).to have_http_status :too_many_requests end end @@ -142,7 +142,7 @@ def create_backup include_context "request" it "is forbidden" do - expect(last_response.status).to eq 403 + expect(last_response).to have_http_status :forbidden end it "shows the remaining hours until the token is valid" do diff --git a/spec/requests/api/v3/content_type_header_spec.rb b/spec/requests/api/v3/content_type_header_spec.rb index 5bd99118355a..28c40942752f 100644 --- a/spec/requests/api/v3/content_type_header_spec.rb +++ b/spec/requests/api/v3/content_type_header_spec.rb @@ -50,7 +50,7 @@ context "on a GET request" do it "is successful" do get api_v3_paths.work_package(work_package.id) - expect(last_response.status).not_to eq(406) + expect(last_response.status).not_to have_http_status(:not_acceptable) expect(last_response).to be_ok end end @@ -58,7 +58,7 @@ context "on a DELETE request" do it "is successful" do delete api_v3_paths.work_package(work_package.id) - expect(last_response.status).not_to eq(406) + expect(last_response.status).not_to have_http_status(:not_acceptable) expect(last_response).to be_no_content end end @@ -66,7 +66,7 @@ context "on any other HTTP method" do it "responds with a 406 status and a missing Content-Type header message" do patch api_v3_paths.work_package(work_package.id), {} - expect(last_response.status).to eq(406) + expect(last_response).to have_http_status(:not_acceptable) expect(last_response.body).to include("Missing content-type header") end end diff --git a/spec/requests/api/v3/groups/group_resource_spec.rb b/spec/requests/api/v3/groups/group_resource_spec.rb index 4d6619fe9b01..218aa13f056a 100644 --- a/spec/requests/api/v3/groups/group_resource_spec.rb +++ b/spec/requests/api/v3/groups/group_resource_spec.rb @@ -122,7 +122,7 @@ current_user { create(:admin) } it "responds with 201" do - expect(last_response.status).to eq(201) + expect(last_response).to have_http_status(:created) end it "creates the group and sets the members" do @@ -155,7 +155,7 @@ end it "responds with 422 and explains the error" do - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(last_response.body) .to be_json_eql("Name can't be blank.".to_json) @@ -221,7 +221,7 @@ current_user { admin } it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "updates the group" do diff --git a/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb b/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb index 55acc25f70d3..5a56e499fd93 100644 --- a/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb +++ b/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb @@ -86,7 +86,7 @@ end context "valid type id" do - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } end context "invalid type id" do diff --git a/spec/requests/api/v3/membership_resources_spec.rb b/spec/requests/api/v3/membership_resources_spec.rb index 1a64fbfb490e..d2597ca63e40 100644 --- a/spec/requests/api/v3/membership_resources_spec.rb +++ b/spec/requests/api/v3/membership_resources_spec.rb @@ -438,7 +438,7 @@ let(:role) { defined?(expected_role) ? expected_role : other_role } it "responds with 201" do - expect(last_response.status).to eq(201) + expect(last_response).to have_http_status(:created) end it "creates the member" do @@ -675,7 +675,7 @@ context "as a non admin" do it "responds with 422 and explains the error" do - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(last_response.body) .to be_json_eql("Project can't be blank.".to_json) @@ -705,7 +705,7 @@ end it "responds with 422 and explains the error" do - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(last_response.body) .to be_json_eql("User has already been taken.".to_json) @@ -734,7 +734,7 @@ end it "responds with 422 and explains the error" do - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) error_message = "For property 'user' a link like '/api/v3/groups/:id' or " + "'/api/v3/users/:id' or '/api/v3/placeholder_users/:id' is expected, " + @@ -762,7 +762,7 @@ end it "responds with 422 and explains the error" do - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(last_response.body) .to be_json_eql("Roles need to be assigned.".to_json) @@ -862,7 +862,7 @@ context "for a user" do it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "updates the member" do @@ -955,7 +955,7 @@ let(:last_user_member_updated_at) { Member.find_by(principal: users.last).updated_at } it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "updates the member and all inherited members but does not update memberships users have already had" do @@ -1038,7 +1038,7 @@ let(:another_role) { create(:global_role) } it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "updates the member and all inherited members but does not update memberships users have already had" do diff --git a/spec/requests/api/v3/memberships/create_form_resource_spec.rb b/spec/requests/api/v3/memberships/create_form_resource_spec.rb index 20e10935cebd..51e8128ebac4 100644 --- a/spec/requests/api/v3/memberships/create_form_resource_spec.rb +++ b/spec/requests/api/v3/memberships/create_form_resource_spec.rb @@ -53,7 +53,7 @@ describe "#POST /api/v3/memberships/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 @@ -157,7 +157,7 @@ let(:permissions) { [] } it "returns 403 Not Authorized" do - expect(response.status).to eq(403) + expect(response).to have_http_status(:forbidden) end end end diff --git a/spec/requests/api/v3/memberships/update_form_resource_spec.rb b/spec/requests/api/v3/memberships/update_form_resource_spec.rb index fbb950b1ced6..ffcbcf508e3e 100644 --- a/spec/requests/api/v3/memberships/update_form_resource_spec.rb +++ b/spec/requests/api/v3/memberships/update_form_resource_spec.rb @@ -73,7 +73,7 @@ describe "#POST /api/v3/memberships/: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 @@ -217,7 +217,7 @@ let(:permissions) { [:view_members] } it "returns 403 Not Authorized" do - expect(response.status).to eq(403) + expect(response).to have_http_status(:forbidden) end end @@ -225,7 +225,7 @@ let(:permissions) { [] } it "returns 404 Not Found" do - expect(response.status).to eq(404) + expect(response).to have_http_status(:not_found) end end end diff --git a/spec/requests/api/v3/notifications/details_resource_spec.rb b/spec/requests/api/v3/notifications/details_resource_spec.rb index 81a0901514b0..e374c098cabf 100644 --- a/spec/requests/api/v3/notifications/details_resource_spec.rb +++ b/spec/requests/api/v3/notifications/details_resource_spec.rb @@ -77,7 +77,7 @@ it "returns a 404 response" do send_request - expect(last_response.status).to eq(404) + expect(last_response).to have_http_status(:not_found) end end @@ -151,7 +151,7 @@ end it "returns a 404 response" do - expect(last_response.status).to eq(404) + expect(last_response).to have_http_status(:not_found) end end @@ -163,7 +163,7 @@ end it "returns a 404 response" do - expect(last_response.status).to eq(404) + expect(last_response).to have_http_status(:not_found) end end end diff --git a/spec/requests/api/v3/notifications/read_ian_resource_spec.rb b/spec/requests/api/v3/notifications/read_ian_resource_spec.rb index 696cd8eba49f..cd63f2feba7e 100644 --- a/spec/requests/api/v3/notifications/read_ian_resource_spec.rb +++ b/spec/requests/api/v3/notifications/read_ian_resource_spec.rb @@ -64,11 +64,11 @@ it "can read and unread" do send_read - expect(last_response.status).to eq(204) + expect(last_response).to have_http_status(:no_content) expect(notification.reload.read_ian).to be_truthy send_unread - expect(last_response.status).to eq(204) + expect(last_response).to have_http_status(:no_content) expect(notification.reload.read_ian).to be_falsey end end @@ -78,10 +78,10 @@ it "returns a 404 response" do send_read - expect(last_response.status).to eq(404) + expect(last_response).to have_http_status(:not_found) send_unread - expect(last_response.status).to eq(404) + expect(last_response).to have_http_status(:not_found) end end end diff --git a/spec/requests/api/v3/notifications/show_resource_spec.rb b/spec/requests/api/v3/notifications/show_resource_spec.rb index c12bce676fa3..82a8310bfa14 100644 --- a/spec/requests/api/v3/notifications/show_resource_spec.rb +++ b/spec/requests/api/v3/notifications/show_resource_spec.rb @@ -99,7 +99,7 @@ end it "returns a 404 response" do - expect(last_response.status).to eq(404) + expect(last_response).to have_http_status(:not_found) end end @@ -111,7 +111,7 @@ end it "returns a 404 response" do - expect(last_response.status).to eq(404) + expect(last_response).to have_http_status(:not_found) end end end diff --git a/spec/requests/api/v3/placeholder_users/create_resource_spec.rb b/spec/requests/api/v3/placeholder_users/create_resource_spec.rb index faefd36171b8..0360cbe4000e 100644 --- a/spec/requests/api/v3/placeholder_users/create_resource_spec.rb +++ b/spec/requests/api/v3/placeholder_users/create_resource_spec.rb @@ -51,7 +51,7 @@ it "returns an erroneous response" do send_request - expect(last_response.status).to eq(403) + expect(last_response).to have_http_status(:forbidden) end end end diff --git a/spec/requests/api/v3/placeholder_users/create_shared_examples.rb b/spec/requests/api/v3/placeholder_users/create_shared_examples.rb index d0827cd509be..32ed68004b2c 100644 --- a/spec/requests/api/v3/placeholder_users/create_shared_examples.rb +++ b/spec/requests/api/v3/placeholder_users/create_shared_examples.rb @@ -50,7 +50,7 @@ it "returns an erroneous response" do send_request - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(last_response.body) .to be_json_eql("urn:openproject-org:api:v3:errors:PropertyConstraintViolation".to_json) .at_path("errorIdentifier") @@ -63,7 +63,7 @@ it "creates the placeholder when valid" do send_request - expect(last_response.status).to eq(201) + expect(last_response).to have_http_status(:created) placeholder = PlaceholderUser.find_by(name: parameters[:name]) expect(placeholder).to be_present end @@ -74,7 +74,7 @@ it "returns an error" do send_request - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(last_response.body) .to be_json_eql("urn:openproject-org:api:v3:errors:PropertyConstraintViolation".to_json) .at_path("errorIdentifier") @@ -92,7 +92,7 @@ it "adds an error that its only available in EE" do send_request - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(parsed_response["message"]) .to eq("Placeholder Users is only available in the OpenProject Enterprise edition") diff --git a/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb b/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb index 185e6efc7f43..1df31faf3de8 100644 --- a/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb +++ b/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb @@ -27,7 +27,7 @@ RSpec.shared_examples "deletion allowed" do it "responds with 202" do - expect(last_response.status).to eq 202 + expect(last_response).to have_http_status :accepted end it "locks the account and mark for deletion" do @@ -47,7 +47,7 @@ RSpec.shared_examples "deletion is not allowed" do it "responds with 403" do - expect(last_response.status).to eq 403 + expect(last_response).to have_http_status :forbidden end it "does not delete the user" do diff --git a/spec/requests/api/v3/placeholder_users/show_resource_examples.rb b/spec/requests/api/v3/placeholder_users/show_resource_examples.rb index 1a7f451172ec..1d4da78c9c7f 100644 --- a/spec/requests/api/v3/placeholder_users/show_resource_examples.rb +++ b/spec/requests/api/v3/placeholder_users/show_resource_examples.rb @@ -27,7 +27,7 @@ RSpec.shared_examples "represents the placeholder" do it do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) expect(last_response.body) .to(be_json_eql("PlaceholderUser".to_json).at_path("_type")) diff --git a/spec/requests/api/v3/placeholder_users/show_resource_spec.rb b/spec/requests/api/v3/placeholder_users/show_resource_spec.rb index 3a4cd43697cb..2f598b749a02 100644 --- a/spec/requests/api/v3/placeholder_users/show_resource_spec.rb +++ b/spec/requests/api/v3/placeholder_users/show_resource_spec.rb @@ -71,7 +71,7 @@ let(:user) { build(:user) } it "returns a 403 response" do - expect(last_response.status).to eq(403) + expect(last_response).to have_http_status(:forbidden) end end end diff --git a/spec/requests/api/v3/placeholder_users/update_resource_examples.rb b/spec/requests/api/v3/placeholder_users/update_resource_examples.rb index b6feb8996cce..83fcfffb967c 100644 --- a/spec/requests/api/v3/placeholder_users/update_resource_examples.rb +++ b/spec/requests/api/v3/placeholder_users/update_resource_examples.rb @@ -32,7 +32,7 @@ end it "returns an error" do - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(last_response.body) .to be_json_eql("urn:openproject-org:api:v3:errors:PropertyConstraintViolation".to_json) .at_path("errorIdentifier") @@ -51,7 +51,7 @@ end it "updates the placeholder" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) placeholder.reload diff --git a/spec/requests/api/v3/placeholder_users/update_resource_spec.rb b/spec/requests/api/v3/placeholder_users/update_resource_spec.rb index ecd50789329e..356764e5422d 100644 --- a/spec/requests/api/v3/placeholder_users/update_resource_spec.rb +++ b/spec/requests/api/v3/placeholder_users/update_resource_spec.rb @@ -67,7 +67,7 @@ let(:user) { build(:user) } it "returns a 403 response" do - expect(last_response.status).to eq(403) + expect(last_response).to have_http_status(:forbidden) end end end diff --git a/spec/requests/api/v3/projects/copy/copy_form_resource_spec.rb b/spec/requests/api/v3/projects/copy/copy_form_resource_spec.rb index 1f4ccd4df231..d1579e024e67 100644 --- a/spec/requests/api/v3/projects/copy/copy_form_resource_spec.rb +++ b/spec/requests/api/v3/projects/copy/copy_form_resource_spec.rb @@ -66,7 +66,7 @@ subject(:response) { last_response } it "returns 200 FORM response", :aggregate_failures do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(response.body) .to be_json_eql("Form".to_json) @@ -240,7 +240,7 @@ end it "returns 403 Not Authorized" do - expect(response.status).to eq(403) + expect(response).to have_http_status(:forbidden) end end end diff --git a/spec/requests/api/v3/projects/copy/copy_resource_spec.rb b/spec/requests/api/v3/projects/copy/copy_resource_spec.rb index c5b528a3bb15..9ab848034167 100644 --- a/spec/requests/api/v3/projects/copy/copy_resource_spec.rb +++ b/spec/requests/api/v3/projects/copy/copy_resource_spec.rb @@ -71,12 +71,11 @@ subject(:response) { last_response } - # rubocop:disable RSpecRails/HaveHttpStatus # those are mock responses that don't deal well with the rails helpers describe "#POST /api/v3/projects/:id/copy" do describe "with empty params" do it "returns 422", :aggregate_failures do - expect(response.status).to eq(422) + expect(response).to have_http_status(:unprocessable_entity) expect(response.body) .to be_json_eql("Error".to_json) @@ -99,7 +98,7 @@ it "returns with a redirect to job" do aggregate_failures do - expect(response.status).to eq(302) + expect(response).to have_http_status(:found) expect(response).to be_redirect @@ -108,7 +107,7 @@ get response.location - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) expect(last_response.body) .to be_json_eql("in_queue".to_json) @@ -118,7 +117,7 @@ get response.location - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) expect(last_response.body) .to be_json_eql("success".to_json) @@ -199,9 +198,8 @@ end it "returns 403 Not Authorized" do - expect(response.status).to eq(403) + expect(response).to have_http_status(:forbidden) end end end - # rubocop:enable RSpecRails/HaveHttpStatus end diff --git a/spec/requests/api/v3/projects/create_form_resource_spec.rb b/spec/requests/api/v3/projects/create_form_resource_spec.rb index c92041ef0dcd..0654d6e40c3b 100644 --- a/spec/requests/api/v3/projects/create_form_resource_spec.rb +++ b/spec/requests/api/v3/projects/create_form_resource_spec.rb @@ -63,7 +63,7 @@ describe "#POST /api/v3/projects/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 @@ -195,7 +195,7 @@ end it "returns 200 OK" do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end it "returns the schema with a required parent field" do @@ -209,7 +209,7 @@ let(:permissions) { [] } it "returns 403 Not Authorized" do - expect(response.status).to eq(403) + expect(response).to have_http_status(:forbidden) end end end diff --git a/spec/requests/api/v3/projects/create_resource_spec.rb b/spec/requests/api/v3/projects/create_resource_spec.rb index 02106e9baa65..82836ddb59f9 100644 --- a/spec/requests/api/v3/projects/create_resource_spec.rb +++ b/spec/requests/api/v3/projects/create_resource_spec.rb @@ -63,7 +63,7 @@ end it "responds with 201 CREATED" do - expect(last_response.status).to eq(201) + expect(last_response).to have_http_status(:created) end it "creates a project" do @@ -182,7 +182,7 @@ let(:permissions) { [] } it "responds with 403" do - expect(last_response.status).to eq(403) + expect(last_response).to have_http_status(:forbidden) end it "creates no project" do @@ -199,7 +199,7 @@ end it "responds with 422" do - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) end it "creates no project" do @@ -233,7 +233,7 @@ end it "responds with 422" do - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) end it "creates no project" do diff --git a/spec/requests/api/v3/projects/index_resource_spec.rb b/spec/requests/api/v3/projects/index_resource_spec.rb index 7f074ffc8256..1161f999ce02 100644 --- a/spec/requests/api/v3/projects/index_resource_spec.rb +++ b/spec/requests/api/v3/projects/index_resource_spec.rb @@ -320,7 +320,7 @@ current_user { admin } it "responds with 200 OK" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it_behaves_like "API V3 collection response", 1, 1, "Project" do @@ -332,7 +332,7 @@ it_behaves_like "API V3 collection response", 0, 0, "Project" it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end end end diff --git a/spec/requests/api/v3/projects/update_form_resource_spec.rb b/spec/requests/api/v3/projects/update_form_resource_spec.rb index 490af1651edb..e2834bc408cd 100644 --- a/spec/requests/api/v3/projects/update_form_resource_spec.rb +++ b/spec/requests/api/v3/projects/update_form_resource_spec.rb @@ -74,7 +74,7 @@ describe "#POST /api/v3/projects/: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 @@ -262,7 +262,7 @@ let(:permissions) { [] } it "returns 403 Not Authorized" do - expect(response.status).to eq(403) + expect(response).to have_http_status(:forbidden) end end @@ -270,7 +270,7 @@ let(:path) { api_v3_paths.project_form(1) } it "returns 404 Not found" do - expect(response.status).to eq(404) + expect(response).to have_http_status(:not_found) end end end diff --git a/spec/requests/api/v3/projects/update_resource_spec.rb b/spec/requests/api/v3/projects/update_resource_spec.rb index b9aa431487a1..26d72f607cdc 100644 --- a/spec/requests/api/v3/projects/update_resource_spec.rb +++ b/spec/requests/api/v3/projects/update_resource_spec.rb @@ -65,7 +65,7 @@ end it "responds with 200 OK" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "alters the project" do @@ -97,7 +97,7 @@ end it "responds with 200 OK" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "sets the cf value" do @@ -124,7 +124,7 @@ let(:current_user) { create(:admin) } it "responds with 200 OK" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "sets the cf value" do @@ -141,7 +141,7 @@ context "with non-admin permissions" do it "responds with 200 OK" do # TBD: trying to set a not accessible custom field is silently ignored - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "does not set the cf value" do @@ -171,7 +171,7 @@ let(:permissions) { [] } it "responds with 403" do - expect(last_response.status).to eq(403) + expect(last_response).to have_http_status(:forbidden) end it "does not change the project" do @@ -266,7 +266,7 @@ end it "responds with 422" do - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) end it "does not change the project" do @@ -299,7 +299,7 @@ end it "responds with 422" do - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) end it "does not change the project status" do diff --git a/spec/requests/api/v3/queries/create_form_api_spec.rb b/spec/requests/api/v3/queries/create_form_api_spec.rb index 3c08545f59c8..6036ca34397c 100644 --- a/spec/requests/api/v3/queries/create_form_api_spec.rb +++ b/spec/requests/api/v3/queries/create_form_api_spec.rb @@ -100,7 +100,7 @@ end it "returns 200(OK)" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "is of type form" do diff --git a/spec/requests/api/v3/queries/create_query_spec.rb b/spec/requests/api/v3/queries/create_query_spec.rb index ebd7719b3ced..8337d60091d0 100644 --- a/spec/requests/api/v3/queries/create_query_spec.rb +++ b/spec/requests/api/v3/queries/create_query_spec.rb @@ -110,7 +110,7 @@ def json end it "returns 201 (created)" do - expect(last_response.status).to eq(201) + expect(last_response).to have_http_status(:created) end it "renders the created query" do @@ -139,7 +139,7 @@ def json context "without EE", with_ee: false do it "yields a 422 error given a timestamp older than 1 day" do - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity expect(json["message"]).to eq "Timestamps contain forbidden values: #{timestamps.first}" end @@ -147,7 +147,7 @@ def json let(:timestamps) { ["oneDayAgo@12:00+00:00"] } it "returns 201 (created)" do - expect(last_response.status).to eq(201) + expect(last_response).to have_http_status(:created) end it "updates the query timestamps" do @@ -168,7 +168,7 @@ def post! post! - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity expect(json["message"]).to eq "Project not found" end @@ -177,7 +177,7 @@ def post! post! - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity expect(json["message"]).to eq "Status Operator is not set to one of the allowed values." end @@ -186,7 +186,7 @@ def post! post! - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity expect(json["message"]).to eq "Statuz filter does not exist." end end diff --git a/spec/requests/api/v3/queries/order/query_order_api_spec.rb b/spec/requests/api/v3/queries/order/query_order_api_spec.rb index 680d69beffb0..19967d7921a7 100644 --- a/spec/requests/api/v3/queries/order/query_order_api_spec.rb +++ b/spec/requests/api/v3/queries/order/query_order_api_spec.rb @@ -52,7 +52,7 @@ it "returns the order" do get path - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok expect(body).to be_a Hash expect(body).to eq({ wp1.id => 0, wp2.id => 8192 }.stringify_keys) end @@ -70,7 +70,7 @@ it "allows inserting a delta" do patch path, { delta: { wp2.id.to_s => 1234 } }.to_json - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok query.reload expect(body).to eq("t" => timestamp) @@ -79,7 +79,7 @@ it "allows removing an item" do patch path, { delta: { wp1.id.to_s => -1 } }.to_json - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok query.reload expect(body).to eq("t" => timestamp) diff --git a/spec/requests/api/v3/queries/query_resource_spec.rb b/spec/requests/api/v3/queries/query_resource_spec.rb index 1124cdb24ce1..26f7d345928c 100644 --- a/spec/requests/api/v3/queries/query_resource_spec.rb +++ b/spec/requests/api/v3/queries/query_resource_spec.rb @@ -65,7 +65,7 @@ context "user has view_work_packages in a project" do it "succeeds" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end end @@ -73,7 +73,7 @@ let(:permissions) { [:manage_public_queries] } it "succeeds" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end end @@ -89,7 +89,7 @@ include_context "with non-member permissions from non_member_permissions" it "succeeds" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end context "that is not allowed to see queries anywhere" do @@ -247,7 +247,7 @@ end it "responds with HTTP No Content" do - expect(last_response.status).to eq 204 + expect(last_response).to have_http_status :no_content end it "deletes the Query" do @@ -279,7 +279,7 @@ end it "succeeds" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "returns a Collection of projects for which the user has view work packages permission" do @@ -317,7 +317,7 @@ context "when starring an unstarred query" do it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it 'returns the query with "starred" property set to true' do @@ -327,7 +327,7 @@ context "when starring already starred query" do it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it 'returns the query with "starred" property set to true' do @@ -356,7 +356,7 @@ context "starring his own query" do it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it 'returns the query with "starred" property set to true' do @@ -398,7 +398,7 @@ end it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it 'returns the query with "starred" property set to false' do @@ -412,7 +412,7 @@ end it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it 'returns the query with "starred" property set to false' do @@ -453,7 +453,7 @@ context "unstarring his own query" do it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it 'returns the query with "starred" property set to true' do @@ -490,7 +490,7 @@ end it "succeeds" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "returns the form" do diff --git a/spec/requests/api/v3/queries/update_form_api_spec.rb b/spec/requests/api/v3/queries/update_form_api_spec.rb index 6d8fb54c8162..f4d3b1516906 100644 --- a/spec/requests/api/v3/queries/update_form_api_spec.rb +++ b/spec/requests/api/v3/queries/update_form_api_spec.rb @@ -65,7 +65,7 @@ end it "returns 200(OK)" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "is of type form" do diff --git a/spec/requests/api/v3/queries/update_query_spec.rb b/spec/requests/api/v3/queries/update_query_spec.rb index 50a9046d26c5..556549845d3a 100644 --- a/spec/requests/api/v3/queries/update_query_spec.rb +++ b/spec/requests/api/v3/queries/update_query_spec.rb @@ -121,7 +121,7 @@ def json end it "returns 200 (ok)" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "renders the updated query" do @@ -159,7 +159,7 @@ def json context "without EE", with_ee: false do it "yields a 422 error given a timestamp older than 1 day" do - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity expect(json["message"]).to eq "Timestamps contain forbidden values: #{timestamps.first}" end @@ -167,7 +167,7 @@ def json let(:timestamps) { ["oneDayAgo@12:00+00:00"] } it "returns 200 (ok)" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "updates the query timestamps" do @@ -188,7 +188,7 @@ def post! post! - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity expect(json["message"]).to eq "Project not found" end @@ -197,7 +197,7 @@ def post! post! - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity expect(json["message"]).to eq "Status Operator is not set to one of the allowed values." end @@ -206,7 +206,7 @@ def post! post! - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity expect(json["message"]).to eq "Statuz filter does not exist." end end diff --git a/spec/requests/api/v3/relations/relations_api_spec.rb b/spec/requests/api/v3/relations/relations_api_spec.rb index a64fbbb3a4db..3fa1effcc1de 100644 --- a/spec/requests/api/v3/relations/relations_api_spec.rb +++ b/spec/requests/api/v3/relations/relations_api_spec.rb @@ -93,7 +93,7 @@ end it "returns 201 (created)" do - expect(last_response.status).to eq(201) + expect(last_response).to have_http_status(:created) end it "has created a new relation" do @@ -121,7 +121,7 @@ end it "responds with error" do - expect(last_response.status).to be 422 + expect(last_response).to have_http_status :unprocessable_entity end it "states the reason for the error" do @@ -242,7 +242,7 @@ end it "returns 200 (ok)" do - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok end it "updates the relation's description" do @@ -267,7 +267,7 @@ end it "returns 422" do - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity end it "indicates an error with the type attribute" do @@ -291,7 +291,7 @@ end it "returns 422" do - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity end it "indicates an error with the `from` attribute" do @@ -329,7 +329,7 @@ context "with the required permissions" do it "works" do - expect(last_response.status).to eq 201 + expect(last_response).to have_http_status :created end end @@ -337,7 +337,7 @@ let(:permissions) { [:view_work_packages] } it "is forbidden" do - expect(last_response.status).to eq 403 + expect(last_response).to have_http_status :forbidden end end @@ -349,7 +349,7 @@ let!(:to) { create(:work_package) } it "returns 422" do - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity end it "indicates an error with the `to` attribute" do @@ -392,7 +392,7 @@ end it "returns 204 and destroy the relation" do - expect(last_response.status).to eq 204 + expect(last_response).to have_http_status :no_content expect(Relation.exists?(relation.id)).to be_falsey end @@ -400,7 +400,7 @@ let(:permissions) { %i[view_work_packages] } it "returns 403" do - expect(last_response.status).to eq 403 + expect(last_response).to have_http_status :forbidden end it "leaves the relation" do @@ -458,7 +458,7 @@ end it "returns 200" do - expect(last_response.status).to be 200 + expect(last_response).to have_http_status :ok end it "returns the visible relation (and only the visible one) satisfying the filter" do @@ -502,7 +502,7 @@ context "for a relation with visible work packages" do it "returns 200" do - expect(last_response.status).to be 200 + expect(last_response).to have_http_status :ok end it "returns the relation" do @@ -534,7 +534,7 @@ end it "returns 404 NOT FOUND" do - expect(last_response.status).to be 404 + expect(last_response).to have_http_status :not_found end end end diff --git a/spec/requests/api/v3/repositories/revisions_resource_spec.rb b/spec/requests/api/v3/repositories/revisions_resource_spec.rb index e060d753a6c5..31623d87ccf7 100644 --- a/spec/requests/api/v3/repositories/revisions_resource_spec.rb +++ b/spec/requests/api/v3/repositories/revisions_resource_spec.rb @@ -66,7 +66,7 @@ end it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end describe "response body" do diff --git a/spec/requests/api/v3/root_resource_spec.rb b/spec/requests/api/v3/root_resource_spec.rb index d7f6e3ed9aa1..46501b452b6b 100644 --- a/spec/requests/api/v3/root_resource_spec.rb +++ b/spec/requests/api/v3/root_resource_spec.rb @@ -59,7 +59,7 @@ context "when not login_required", with_settings: { login_required: false } do it "responds with 200", :aggregate_failures do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(subject).to have_json_path("instanceName") end end @@ -73,7 +73,7 @@ end it "responds with 200" do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end it "responds with a root representer" do @@ -82,7 +82,7 @@ context "without the X-requested-with header", :skip_xhr_header do it "returns OK because GET requests are allowed" do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(subject).to have_json_path("instanceName") end end diff --git a/spec/requests/api/v3/status_resource_spec.rb b/spec/requests/api/v3/status_resource_spec.rb index b45371050d17..58bbd0bb25fa 100644 --- a/spec/requests/api/v3/status_resource_spec.rb +++ b/spec/requests/api/v3/status_resource_spec.rb @@ -82,7 +82,7 @@ end context "valid status id" do - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } end context "invalid status id" do diff --git a/spec/requests/api/v3/support/api_helper.rb b/spec/requests/api/v3/support/api_helper.rb index a942810ec8b4..46fe6f6f33fe 100644 --- a/spec/requests/api/v3/support/api_helper.rb +++ b/spec/requests/api/v3/support/api_helper.rb @@ -27,7 +27,7 @@ #++ RSpec.shared_examples_for "safeguarded API" do - it { expect(last_response.status).to eq(404) } + it { expect(last_response).to have_http_status(:not_found) } end RSpec.shared_examples_for "valid activity request" do @@ -38,7 +38,7 @@ allow(User).to receive(:current).and_return(admin) end - it { expect(last_response.status).to eq(status_code) } + it { expect(last_response).to have_http_status(status_code) } describe "response body" do subject { last_response.body } @@ -56,5 +56,5 @@ allow(User).to receive(:current).and_return(admin) end - it { expect(last_response.status).to eq(422) } + it { expect(last_response).to have_http_status(:unprocessable_entity) } end diff --git a/spec/requests/api/v3/support/api_v3_collection_response.rb b/spec/requests/api/v3/support/api_v3_collection_response.rb index a3bde3e9c36a..132f949048b5 100644 --- a/spec/requests/api/v3/support/api_v3_collection_response.rb +++ b/spec/requests/api/v3/support/api_v3_collection_response.rb @@ -59,7 +59,7 @@ it "returns a collection successfully" do aggregate_failures do - expect(last_response.status).to eq(expected_status_code) + expect(last_response).to have_http_status(expected_status_code) errors = JSON.parse(subject).dig("_embedded", "errors")&.map { _1["message"] } expect(errors).to eq([]) if errors # make errors visible in console if any end diff --git a/spec/requests/api/v3/support/response_examples.rb b/spec/requests/api/v3/support/response_examples.rb index 2974b634ec78..3302c01a6cac 100644 --- a/spec/requests/api/v3/support/response_examples.rb +++ b/spec/requests/api/v3/support/response_examples.rb @@ -30,7 +30,7 @@ RSpec.shared_examples_for "successful response" do |code = 200| it "has the status code #{code}" do - expect(last_response.status).to eq(code) + expect(last_response).to have_http_status(code) end it "has a HAL+JSON Content-Type" do @@ -42,7 +42,7 @@ RSpec.shared_examples_for "successful no content response" do |code = 204| it "has the status code #{code}" do - expect(last_response.status).to eq(code) + expect(last_response).to have_http_status(code) end end @@ -50,7 +50,7 @@ let(:location) { "" } it "has the status code #{code}" do - expect(last_response.status).to eq(code) + expect(last_response).to have_http_status(code) end it "redirects to expected location" do @@ -64,7 +64,7 @@ end it "has the status code #{code}" do - expect(last_response.status).to eq(code) + expect(last_response).to have_http_status(code) end it "has a HAL+JSON Content-Type" do @@ -182,7 +182,7 @@ subject { JSON.parse(last_response.body) } it "results in a validation error" do - expect(last_response.status).to eq(400) + expect(last_response).to have_http_status(:bad_request) expect(subject["errorIdentifier"]).to eq("urn:openproject-org:api:v3:errors:BadRequest") expect(subject["message"]).to match /Bad request: .+? is invalid/ end diff --git a/spec/requests/api/v3/types/type_resource_spec.rb b/spec/requests/api/v3/types/type_resource_spec.rb index 0a0da5dff3fd..dd21d89a94e2 100644 --- a/spec/requests/api/v3/types/type_resource_spec.rb +++ b/spec/requests/api/v3/types/type_resource_spec.rb @@ -82,7 +82,7 @@ end context "valid type id" do - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } end context "invalid type id" do diff --git a/spec/requests/api/v3/user/create_form_resource_spec.rb b/spec/requests/api/v3/user/create_form_resource_spec.rb index a9cd83532176..6bad65fa8981 100644 --- a/spec/requests/api/v3/user/create_form_resource_spec.rb +++ b/spec/requests/api/v3/user/create_form_resource_spec.rb @@ -55,7 +55,7 @@ it "returns a payload with validation errors", :aggregate_failures, with_settings: { default_language: :es } do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(response.body).to be_json_eql("Form".to_json).at_path("_type") expect(body) @@ -101,7 +101,7 @@ end it "returns a valid payload", :aggregate_failures do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(response.body).to be_json_eql("Form".to_json).at_path("_type") expect(body) @@ -149,7 +149,7 @@ end it "returns a valid form response" do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(response.body).to be_json_eql("Form".to_json).at_path("_type") expect(body) diff --git a/spec/requests/api/v3/user/create_user_common_examples.rb b/spec/requests/api/v3/user/create_user_common_examples.rb index b55219a3786a..1026f3429f72 100644 --- a/spec/requests/api/v3/user/create_user_common_examples.rb +++ b/spec/requests/api/v3/user/create_user_common_examples.rb @@ -29,7 +29,7 @@ it "returns the represented user" do send_request - expect(last_response.status).to eq(201) + expect(last_response).to have_http_status(:created) expect(last_response.body).to have_json_type(Object).at_path("_links") expect(last_response.body) .to be_json_eql("User".to_json) @@ -50,7 +50,7 @@ attr = JSON.parse(last_response.body).dig "_embedded", "details", "attribute" - expect(last_response.status).to eq 422 + expect(last_response).to have_http_status :unprocessable_entity expect(attr).to eq attribute_name end end @@ -64,7 +64,7 @@ it "returns an erroneous response" do send_request - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(errors.count).to eq(5) expect(errors.collect { |el| el["_embedded"]["details"]["attribute"] }) @@ -140,7 +140,7 @@ it "returns an erroneous response" do send_request - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(errors).not_to be_empty expect(last_response.body) diff --git a/spec/requests/api/v3/user/create_user_resource_spec.rb b/spec/requests/api/v3/user/create_user_resource_spec.rb index 61ca8db92182..b873d767933d 100644 --- a/spec/requests/api/v3/user/create_user_resource_spec.rb +++ b/spec/requests/api/v3/user/create_user_resource_spec.rb @@ -114,7 +114,7 @@ def send_request it "returns an error on that attribute" do send_request - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(last_response.body) .to be_json_eql("authSource".to_json) @@ -247,7 +247,7 @@ def send_request it "returns an erroneous response" do send_request - expect(last_response.status).to eq(403) + expect(last_response).to have_http_status(:forbidden) end end end diff --git a/spec/requests/api/v3/user/update_form_resource_spec.rb b/spec/requests/api/v3/user/update_form_resource_spec.rb index 94f5a5a5dff4..53505aaffe7a 100644 --- a/spec/requests/api/v3/user/update_form_resource_spec.rb +++ b/spec/requests/api/v3/user/update_form_resource_spec.rb @@ -67,7 +67,7 @@ describe "empty payload" do it "returns a valid form", :aggregate_failures do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(response.body).to be_json_eql("Form".to_json).at_path("_type") expect(body) @@ -96,7 +96,7 @@ end it "returns a valid response", :aggregate_failures do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(response.body).to be_json_eql("Form".to_json).at_path("_type") expect(subject.body) @@ -121,7 +121,7 @@ end it "returns an invalid form", :aggregate_failures do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(response.body).to be_json_eql("Form".to_json).at_path("_type") expect(body) @@ -156,7 +156,7 @@ let(:path) { api_v3_paths.user_form(12345) } it "returns 404 Not found" do - expect(response.status).to eq(404) + expect(response).to have_http_status(:not_found) end end end diff --git a/spec/requests/api/v3/user/update_user_resource_spec.rb b/spec/requests/api/v3/user/update_user_resource_spec.rb index 272c1185ddd3..9279dc539f92 100644 --- a/spec/requests/api/v3/user/update_user_resource_spec.rb +++ b/spec/requests/api/v3/user/update_user_resource_spec.rb @@ -48,7 +48,7 @@ def send_request it "responds with the represented updated user" do send_request - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) expect(last_response.body).to have_json_type(Object).at_path("_links") expect(last_response.body) .to be_json_eql("User".to_json) @@ -83,7 +83,7 @@ def send_request it "returns an erroneous response" do send_request - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(last_response.body) .to be_json_eql("email".to_json) @@ -107,7 +107,7 @@ def send_request it "updates the users password correctly" do send_request - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) updated_user = User.find(user.id) matches = updated_user.check_password?(password) @@ -121,7 +121,7 @@ def send_request it "responds with 404" do send_request - expect(last_response.status).to be(404) + expect(last_response).to have_http_status(:not_found) end end end @@ -138,7 +138,7 @@ def send_request it "rejects the users password update" do send_request - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(last_response.body) .to be_json_eql("password".to_json) @@ -157,7 +157,7 @@ def send_request it "returns an erroneous response" do send_request - expect(last_response.status).to eq(403) + expect(last_response).to have_http_status(:forbidden) end end end diff --git a/spec/requests/api/v3/version_resource_spec.rb b/spec/requests/api/v3/version_resource_spec.rb index 58bd7dd67f97..fd6881033b12 100644 --- a/spec/requests/api/v3/version_resource_spec.rb +++ b/spec/requests/api/v3/version_resource_spec.rb @@ -55,7 +55,7 @@ shared_examples_for "successful response" do it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "returns the version" do @@ -157,7 +157,7 @@ end it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "updates the version" do @@ -297,7 +297,7 @@ end it "responds with 201" do - expect(last_response.status).to eq(201) + expect(last_response).to have_http_status(:created) end it "creates the version" do diff --git a/spec/requests/api/v3/versions/create_form_resource_spec.rb b/spec/requests/api/v3/versions/create_form_resource_spec.rb index 47fca5b70762..b91997919d98 100644 --- a/spec/requests/api/v3/versions/create_form_resource_spec.rb +++ b/spec/requests/api/v3/versions/create_form_resource_spec.rb @@ -50,7 +50,7 @@ describe "#POST /api/v3/versions/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 @@ -186,7 +186,7 @@ let(:permissions) { [] } it "returns 403 Not Authorized" do - expect(response.status).to eq(403) + expect(response).to have_http_status(:forbidden) end end end diff --git a/spec/requests/api/v3/versions/update_form_resource_spec.rb b/spec/requests/api/v3/versions/update_form_resource_spec.rb index fbc564db2822..12ab7a95e4dc 100644 --- a/spec/requests/api/v3/versions/update_form_resource_spec.rb +++ b/spec/requests/api/v3/versions/update_form_resource_spec.rb @@ -55,7 +55,7 @@ describe "#POST /api/v3/versions/: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 @@ -215,7 +215,7 @@ let(:permissions) { [:view_work_packages] } it "returns 403 Not Authorized" do - expect(response.status).to eq(403) + expect(response).to have_http_status(:forbidden) end end @@ -223,7 +223,7 @@ let(:permissions) { [] } it "returns 404 Not Found" do - expect(response.status).to eq(404) + expect(response).to have_http_status(:not_found) end end end diff --git a/spec/requests/api/v3/views/create_resource_spec.rb b/spec/requests/api/v3/views/create_resource_spec.rb index 8cdae129f461..5a9ebf045317 100644 --- a/spec/requests/api/v3/views/create_resource_spec.rb +++ b/spec/requests/api/v3/views/create_resource_spec.rb @@ -97,7 +97,7 @@ end it "responds with 422 and explains the error" do - expect(last_response.status).to eq(422) + expect(last_response).to have_http_status(:unprocessable_entity) expect(last_response.body) .to be_json_eql("Query does not exist.".to_json) diff --git a/spec/requests/api/v3/views/show_resource_spec.rb b/spec/requests/api/v3/views/show_resource_spec.rb index 606db351cf70..838982eab4c4 100644 --- a/spec/requests/api/v3/views/show_resource_spec.rb +++ b/spec/requests/api/v3/views/show_resource_spec.rb @@ -85,7 +85,7 @@ end it "returns a 404 response" do - expect(last_response.status).to eq(404) + expect(last_response).to have_http_status(:not_found) end end end diff --git a/spec/requests/api/v3/work_packages/by_project_create_resource_spec.rb b/spec/requests/api/v3/work_packages/by_project_create_resource_spec.rb index 7d4706a719b2..0caa698c112c 100644 --- a/spec/requests/api/v3/work_packages/by_project_create_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/by_project_create_resource_spec.rb @@ -99,7 +99,7 @@ end it "returns Created(201)" do - expect(last_response.status).to eq(201) + expect(last_response).to have_http_status(:created) end it "creates a work package" do @@ -114,7 +114,7 @@ let(:current_user) { create(:user) } it "hides the endpoint" do - expect(last_response.status).to eq(404) + expect(last_response).to have_http_status(:not_found) end end @@ -124,7 +124,7 @@ let(:permissions) { [:view_project] } it "points out the missing permission" do - expect(last_response.status).to eq(403) + expect(last_response).to have_http_status(:forbidden) end end diff --git a/spec/requests/api/v3/work_packages/create_form_resource_spec.rb b/spec/requests/api/v3/work_packages/create_form_resource_spec.rb index 030ae7fc5a30..3130bab2aa4e 100644 --- a/spec/requests/api/v3/work_packages/create_form_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/create_form_resource_spec.rb @@ -48,7 +48,7 @@ subject(:response) { last_response } it "returns 200(OK)" do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end it "is of type form" do diff --git a/spec/requests/api/v3/work_packages/create_project_form_resource_spec.rb b/spec/requests/api/v3/work_packages/create_project_form_resource_spec.rb index 3510112baef7..92a2fa5f841a 100644 --- a/spec/requests/api/v3/work_packages/create_project_form_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/create_project_form_resource_spec.rb @@ -44,7 +44,7 @@ subject(:response) { last_response } it "returns 200(OK)" do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end it "is of type form" do diff --git a/spec/requests/api/v3/work_packages/create_resource_spec.rb b/spec/requests/api/v3/work_packages/create_resource_spec.rb index 82026528d9c1..51c183f47bac 100644 --- a/spec/requests/api/v3/work_packages/create_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/create_resource_spec.rb @@ -109,7 +109,7 @@ end it "returns Created(201)" do - expect(last_response.status).to eq(201) + expect(last_response).to have_http_status(:created) end it "creates a work package" do @@ -132,7 +132,7 @@ let(:current_user) { create(:user) } it "hides the endpoint" do - expect(last_response.status).to eq(403) + expect(last_response).to have_http_status(:forbidden) end end @@ -142,7 +142,7 @@ let(:permissions) { [:view_project] } it "points out the missing permission" do - expect(last_response.status).to eq(403) + expect(last_response).to have_http_status(:forbidden) end end diff --git a/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb b/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb index 9726818b86bf..16f042a978fb 100644 --- a/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb @@ -102,7 +102,7 @@ shared_examples_for "valid payload" do subject { last_response.body } - it { expect(last_response.status).to eq(200) } + it { expect(last_response).to have_http_status(:ok) } it { is_expected.to have_json_path("_embedded/payload") } @@ -232,7 +232,7 @@ include_context "with post request" - it { expect(last_response.status).to eq(409) } + it { expect(last_response).to have_http_status(:conflict) } it_behaves_like "update conflict" end @@ -803,7 +803,7 @@ end it "responds with a valid body (Regression OP#37510)" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end end end @@ -825,7 +825,7 @@ subject { last_response.body } shared_examples_for "valid payload" do - it { expect(last_response.status).to eq(200) } + it { expect(last_response).to have_http_status(:ok) } it { is_expected.to have_json_path("_embedded/payload") } diff --git a/spec/requests/api/v3/work_packages/show_resource_spec.rb b/spec/requests/api/v3/work_packages/show_resource_spec.rb index 9fb934c6cb1f..ad4c9f94e6f5 100644 --- a/spec/requests/api/v3/work_packages/show_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/show_resource_spec.rb @@ -69,7 +69,7 @@ end it "responds with 200" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end describe "response body" do @@ -248,7 +248,7 @@ context "with EE", with_ee: %i[baseline_comparison] do it "responds with 200" do - expect(subject && last_response.status).to eq(200) + expect(subject && last_response).to have_http_status(:ok) end it "has the current attributes as attributes" do @@ -502,13 +502,13 @@ context "without EE" do shared_examples "success" do it "responds with 200" do - expect(subject && last_response.status).to eq(200) + expect(subject && last_response).to have_http_status(:ok) end end shared_examples "error" do it "responds with 400" do - expect(subject && last_response.status).to eq(400) + expect(subject && last_response).to have_http_status(:bad_request) end it "has the invalid timestamps message" do diff --git a/spec/requests/api/v3/work_packages/update_resource_spec.rb b/spec/requests/api/v3/work_packages/update_resource_spec.rb index 084aeefc6d1a..9113592e44f9 100644 --- a/spec/requests/api/v3/work_packages/update_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/update_resource_spec.rb @@ -159,7 +159,7 @@ include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "responds with updated work package subject" do expect(subject.body).to be_json_eql("Updated subject".to_json).at_path("subject") @@ -172,7 +172,7 @@ include_context "patch request" - it { expect(response.status).to eq(422) } + it { expect(response).to have_http_status(:unprocessable_entity) } it "has a readonly error" do expect(response.body) @@ -200,7 +200,7 @@ include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it_behaves_like "description updated" end @@ -214,7 +214,7 @@ include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it_behaves_like "description updated" end @@ -226,7 +226,7 @@ include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "updates the scheduling mode" do expect(subject.body).to be_json_eql(schedule_manually.to_json).at_path("scheduleManually") @@ -239,7 +239,7 @@ include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "responds with updated start date" do expect(subject.body).to be_json_eql(date_string.to_json).at_path("startDate") @@ -254,7 +254,7 @@ include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "responds with updated finish date" do expect(subject.body).to be_json_eql(date_string.to_json).at_path("dueDate") @@ -269,7 +269,7 @@ include_context "patch request" - it { expect(response.status).to eq(200) } # rubocop:disable RSpecRails/HaveHttpStatus + it { expect(response).to have_http_status(:ok) } it "responds with updated finish date" do expect(subject.body).to be_json_eql(duration.to_json).at_path("remainingTime") @@ -297,7 +297,7 @@ include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "responds with updated work package status" do expect(subject.body).to be_json_eql(target_status.name.to_json) @@ -349,7 +349,7 @@ include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "responds with updated work package type" do expect(subject.body).to be_json_eql(target_type.name.to_json) @@ -425,7 +425,7 @@ include_context "patch request" it "is successful" do - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end it_behaves_like "lock version updated" @@ -496,7 +496,7 @@ include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it { expect(response.body).to be_json_eql(nil.to_json).at_path(href_path) } @@ -507,7 +507,7 @@ shared_examples_for "valid user assignment" do let(:title) { assigned_user.name.to_s.to_json } - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it { expect(response.body) @@ -614,7 +614,7 @@ context "valid" do include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "responds with the work package assigned to the version" do expect(subject.body) @@ -630,7 +630,7 @@ include_context "patch request" - it { expect(response.status).to eq(422) } + it { expect(response).to have_http_status(:unprocessable_entity) } it "has a readonly error" do expect(response.body) @@ -651,7 +651,7 @@ context "valid" do include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "responds with the work package assigned to the category" do expect(subject.body) @@ -674,7 +674,7 @@ context "valid" do include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "responds with the work package assigned to the priority" do expect(subject.body) @@ -698,7 +698,7 @@ context "valid" do include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "responds with the work package and its new budget" do expect(subject.body).to be_json_eql(target_budget.subject.to_json) @@ -742,7 +742,7 @@ context "valid" do include_context "patch request" - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(:ok) } it "responds with the work package assigned to the new value" do expect(subject.body) diff --git a/spec/requests/api/v3/work_packages/work_packages_schemas_resource_spec.rb b/spec/requests/api/v3/work_packages/work_packages_schemas_resource_spec.rb index 1e7d94f58e82..2aea024f1a05 100644 --- a/spec/requests/api/v3/work_packages/work_packages_schemas_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/work_packages_schemas_resource_spec.rb @@ -59,7 +59,7 @@ context "authorized" do context "valid" do it "returns HTTP 200" do - expect(last_response.status).to be(200) + expect(last_response).to have_http_status(:ok) end it "returns a collection of schemas" do @@ -79,7 +79,7 @@ let(:filter_values) { ["#{0}-#{type.id}"] } it "returns HTTP 200" do - expect(last_response.status).to be(200) + expect(last_response).to have_http_status(:ok) end it "returns an empty collection" do @@ -93,7 +93,7 @@ let(:filter_values) { ["#{project.id}-#{0}"] } it "returns HTTP 200" do - expect(last_response.status).to be(200) + expect(last_response).to have_http_status(:ok) end it "returns an empty collection" do @@ -107,7 +107,7 @@ let(:filter_values) { ["bogus"] } it "returns HTTP 400" do - expect(last_response.status).to be(400) + expect(last_response).to have_http_status(:bad_request) end it "returns an error" do @@ -122,7 +122,7 @@ let(:role) { create(:project_role, permissions: []) } it "returns HTTP 403" do - expect(last_response.status).to be(403) + expect(last_response).to have_http_status(:forbidden) end end end @@ -138,7 +138,7 @@ context "valid schema" do it "returns HTTP 200" do - expect(last_response.status).to be(200) + expect(last_response).to have_http_status(:ok) end it "sets a weak ETag" do @@ -195,7 +195,7 @@ context "valid schema" do it "returns HTTP 200" do - expect(last_response.status).to be(200) + expect(last_response).to have_http_status(:ok) end # Further fields are tested in the representer specs diff --git a/spec/requests/oauth_clients/callback_flow_spec.rb b/spec/requests/oauth_clients/callback_flow_spec.rb index b62d6ce55864..88e5028f5865 100644 --- a/spec/requests/oauth_clients/callback_flow_spec.rb +++ b/spec/requests/oauth_clients/callback_flow_spec.rb @@ -60,7 +60,7 @@ context "when user is not logged in" do it "requires login" do get uri.to_s - expect(last_response.status).to eq(401) + expect(last_response).to have_http_status(:unauthorized) end end @@ -79,24 +79,23 @@ set_cookie "oauth_state_asdf1234=#{state_cookie}" end - # rubocop:disable RSpecRails/HaveHttpStatus shared_examples "with errors and state param with cookie, not being admin" do it "redirects to URI referenced in the state param and held in a cookie" do - expect(response.status).to eq(302) + expect(response).to have_http_status(:found) expect(response.location).to eq redirect_uri end end shared_examples "with errors, being an admin" do it "redirects to admin settings for the storage" do - expect(response.status).to eq(302) + expect(response).to have_http_status(:found) expect(URI(response.location).path).to eq edit_admin_settings_storage_path(oauth_client.integration) end end shared_examples "fallback redirect" do it "redirects to home" do - expect(response.status).to eq(302) + expect(response).to have_http_status(:found) expect(URI(response.location).path).to eq API::V3::Utilities::PathHelper::ApiV3Path::root_path end end @@ -110,7 +109,7 @@ it "redirects to the URL that was referenced by the state param and held by a cookie" do expect(rack_oauth2_client).to have_received(:authorization_code=).with(code) - expect(response.status).to eq 302 + expect(response).to have_http_status :found expect(response.location).to eq redirect_uri expect(OAuthClientToken.count).to eq 1 expect(OAuthClientToken.last.access_token).to eq "xyzaccesstoken" @@ -185,6 +184,5 @@ it_behaves_like "fallback redirect" end - # rubocop:enable RSpecRails/HaveHttpStatus end end diff --git a/spec/requests/oauth_clients/ensure_connection_flow_spec.rb b/spec/requests/oauth_clients/ensure_connection_flow_spec.rb index eced9e187b6e..e2799dfb9df7 100644 --- a/spec/requests/oauth_clients/ensure_connection_flow_spec.rb +++ b/spec/requests/oauth_clients/ensure_connection_flow_spec.rb @@ -45,7 +45,7 @@ context "when user is not logged in" do it "requires login" do get oauth_clients_ensure_connection_url(oauth_client_id: oauth_client.client_id) - expect(last_response.status).to eq(401) + expect(last_response).to have_http_status(:unauthorized) end end @@ -54,7 +54,7 @@ it "responds with 400 when storage_id parameter is absent" do get oauth_clients_ensure_connection_url(oauth_client_id: oauth_client.client_id) - expect(last_response.status).to eq(400) + expect(last_response).to have_http_status(:bad_request) expect(last_response.body).to eq("Required parameter missing: storage_id") end @@ -77,7 +77,7 @@ get oauth_clients_ensure_connection_url(oauth_client_id: oauth_client.client_id, storage_id: storage.id) oauth_client = storage.oauth_client - expect(last_response.status).to eq(302) + expect(last_response).to have_http_status(:found) expect(last_response.location).to eq( "#{storage.host}/index.php/apps/oauth2/authorize?client_id=" \ "#{oauth_client.client_id}&redirect_uri=#{CGI.escape(Rails.application.root_url)}" \ @@ -98,7 +98,7 @@ destination_url: "#{root_url}123") oauth_client = storage.oauth_client - expect(last_response.status).to eq(302) + expect(last_response).to have_http_status(:found) expect(last_response.location).to eq( "#{storage.host}/index.php/apps/oauth2/authorize?client_id=" \ "#{oauth_client.client_id}&redirect_uri=#{CGI.escape(Rails.application.root_url)}" \ @@ -118,7 +118,7 @@ destination_url: "#{storage.host}/index.php") oauth_client = storage.oauth_client - expect(last_response.status).to eq(302) + expect(last_response).to have_http_status(:found) expect(last_response.location).to eq( "#{storage.host}/index.php/apps/oauth2/authorize?client_id=" \ "#{oauth_client.client_id}&redirect_uri=#{CGI.escape(Rails.application.root_url)}" \ @@ -153,7 +153,7 @@ it "redirects to root_url" do get oauth_clients_ensure_connection_url(oauth_client_id: oauth_client.client_id, storage_id: storage.id) - expect(last_response.status).to eq(302) + expect(last_response).to have_http_status(:found) expect(last_response.location).to eq("http://www.example.com/") expect(last_response.cookies.keys).to eq(["_open_project_session"]) end @@ -167,7 +167,7 @@ destination_url: "#{root_url}123") storage.oauth_client - expect(last_response.status).to eq(302) + expect(last_response).to have_http_status(:found) expect(last_response.location).to eq("http://www.example.com/123") expect(last_response.cookies.keys).to eq(["_open_project_session"]) end @@ -180,7 +180,7 @@ destination_url: "#{storage.host}/index.php") storage.oauth_client - expect(last_response.status).to eq(302) + expect(last_response).to have_http_status(:found) expect(last_response.location).to eq("http://www.example.com/") expect(last_response.cookies.keys).to eq(["_open_project_session"]) end diff --git a/spec/requests/openid_google_provider_callback_spec.rb b/spec/requests/openid_google_provider_callback_spec.rb index f43e346ef8b8..43906e46995d 100644 --- a/spec/requests/openid_google_provider_callback_spec.rb +++ b/spec/requests/openid_google_provider_callback_spec.rb @@ -96,7 +96,7 @@ } } do response = get uri.to_s - expect(response.status).to eq(302) + expect(response).to have_http_status(:found) expect(response.location).to eq("http://example.org/two_factor_authentication/request") end end diff --git a/spec/requests/rate_limiting/api_v3_rate_limiting_spec.rb b/spec/requests/rate_limiting/api_v3_rate_limiting_spec.rb index 4e65686b60b3..9ce85ffb6b69 100644 --- a/spec/requests/rate_limiting/api_v3_rate_limiting_spec.rb +++ b/spec/requests/rate_limiting/api_v3_rate_limiting_spec.rb @@ -49,13 +49,13 @@ nil, "CONTENT_TYPE" => "application/json" - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok end post "/api/v3/work_packages/form", nil, "CONTENT_TYPE" => "application/json" - expect(last_response.status).to eq 429 + expect(last_response).to have_http_status :too_many_requests end end @@ -69,7 +69,7 @@ nil, "CONTENT_TYPE" => "application/json" - expect(last_response.status).to eq 200 + expect(last_response).to have_http_status :ok end end end diff --git a/spec/support/have_http_status_with_rack_response.rb b/spec/support/have_http_status_with_rack_response.rb new file mode 100644 index 000000000000..f933d04d1b90 --- /dev/null +++ b/spec/support/have_http_status_with_rack_response.rb @@ -0,0 +1,44 @@ +#-- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2012-2024 the OpenProject GmbH +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +# Copyright (C) 2006-2013 Jean-Philippe Lang +# Copyright (C) 2010-2013 the ChiliProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# See COPYRIGHT and LICENSE files for more details. +#++ + +module HaveHttpStatusWithRackResponse + def as_test_response(obj) + if obj.is_a?(Rack::MockResponse) + # `have_http_status` matcher would fail if the response object is a + # `Rack::MockResponse`. Hack to disguise `Rack::MockResponse` into a + # `ActionDispatch::TestResponse` object. + response = ActionDispatch::Response.new(obj.status, obj.headers, obj.body) + response.request = ActionDispatch::Request.new({}) + ::ActionDispatch::TestResponse.from_response(response) + else + super + end + end +end + +RSpec::Rails::Matchers::HaveHttpStatus.prepend(HaveHttpStatusWithRackResponse) diff --git a/spec/support/queries/shared_get_individual_query_examples.rb b/spec/support/queries/shared_get_individual_query_examples.rb index ad7ee08b3720..0de710dbeced 100644 --- a/spec/support/queries/shared_get_individual_query_examples.rb +++ b/spec/support/queries/shared_get_individual_query_examples.rb @@ -44,7 +44,7 @@ end it "succeeds" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end it "has the right endpoint set for the self reference" do @@ -140,7 +140,7 @@ context "with EE", with_ee: %i[baseline_comparison] do it "succeeds" do - expect(last_response.status).to eq(200) + expect(last_response).to have_http_status(:ok) end end