From 00d0844667245c4fa100b8ce440fa5a70ff0fc7c Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Sat, 4 Mar 2017 14:23:30 +0100 Subject: More fixes --- lib/api/v3/builds.rb | 2 +- lib/api/v3/entities.rb | 2 +- lib/api/v3/project_hooks.rb | 20 +++++++------- lib/api/v3/projects.rb | 1 + spec/requests/api/v3/project_hooks_spec.rb | 43 +++++++++++++++--------------- 5 files changed, 35 insertions(+), 33 deletions(-) diff --git a/lib/api/v3/builds.rb b/lib/api/v3/builds.rb index 0218477803b..77be6e35249 100644 --- a/lib/api/v3/builds.rb +++ b/lib/api/v3/builds.rb @@ -12,7 +12,7 @@ module API helpers do params :optional_scope do optional :scope, types: [String, Array[String]], desc: 'The scope of builds to show', - values: ['pending', 'running', 'failed', 'success', 'canceled'], + values: ['pending', 'running', 'failed', 'success', 'canceled', 'skipped'], coerce_with: ->(scope) { if scope.is_a?(String) [scope] diff --git a/lib/api/v3/entities.rb b/lib/api/v3/entities.rb index bad12f106a6..f382b52aee4 100644 --- a/lib/api/v3/entities.rb +++ b/lib/api/v3/entities.rb @@ -81,7 +81,7 @@ module API expose :request_access_enabled expose :only_allow_merge_if_all_discussions_are_resolved - expose :statistics, using: 'API::Entities::ProjectStatistics', if: :statistics + expose :statistics, using: ::API::V3::Entities::ProjectStatistics, if: :statistics end class ProjectWithAccess < Project diff --git a/lib/api/v3/project_hooks.rb b/lib/api/v3/project_hooks.rb index cd9be62776f..861b991b8e1 100644 --- a/lib/api/v3/project_hooks.rb +++ b/lib/api/v3/project_hooks.rb @@ -27,7 +27,7 @@ module API end resource :projects do desc 'Get project hooks' do - success Entities::ProjectHook + success ::API::V3::Entities::ProjectHook end params do use :pagination @@ -35,22 +35,22 @@ module API get ":id/hooks" do hooks = paginate user_project.hooks - present hooks, with: Entities::ProjectHook + present hooks, with: ::API::V3::Entities::ProjectHook end desc 'Get a project hook' do - success Entities::ProjectHook + success ::API::V3::Entities::ProjectHook end params do requires :hook_id, type: Integer, desc: 'The ID of a project hook' end get ":id/hooks/:hook_id" do hook = user_project.hooks.find(params[:hook_id]) - present hook, with: Entities::ProjectHook + present hook, with: ::API::V3::Entities::ProjectHook end desc 'Add hook to project' do - success Entities::ProjectHook + success ::API::V3::Entities::ProjectHook end params do use :project_hook_properties @@ -59,7 +59,7 @@ module API hook = user_project.hooks.new(declared_params(include_missing: false)) if hook.save - present hook, with: Entities::ProjectHook + present hook, with: ::API::V3::Entities::ProjectHook else error!("Invalid url given", 422) if hook.errors[:url].present? @@ -68,7 +68,7 @@ module API end desc 'Update an existing project hook' do - success Entities::ProjectHook + success ::API::V3::Entities::ProjectHook end params do requires :hook_id, type: Integer, desc: "The ID of the hook to update" @@ -78,7 +78,7 @@ module API hook = user_project.hooks.find(params.delete(:hook_id)) if hook.update_attributes(declared_params(include_missing: false)) - present hook, with: Entities::ProjectHook + present hook, with: ::API::V3::Entities::ProjectHook else error!("Invalid url given", 422) if hook.errors[:url].present? @@ -87,14 +87,14 @@ module API end desc 'Deletes project hook' do - success Entities::ProjectHook + success ::API::V3::Entities::ProjectHook end params do requires :hook_id, type: Integer, desc: 'The ID of the hook to delete' end delete ":id/hooks/:hook_id" do begin - present user_project.hooks.destroy(params[:hook_id]), with: Entities::ProjectHook + present user_project.hooks.destroy(params[:hook_id]), with: ::API::V3::Entities::ProjectHook rescue # ProjectHook can raise Error if hook_id not found not_found!("Error deleting hook #{params[:hook_id]}") diff --git a/lib/api/v3/projects.rb b/lib/api/v3/projects.rb index 47bfc12035a..188fb3144da 100644 --- a/lib/api/v3/projects.rb +++ b/lib/api/v3/projects.rb @@ -91,6 +91,7 @@ module API simple: params[:simple], ) + byebug projects = filter_projects(projects) projects = projects.with_statistics if options[:statistics] options[:with] = ::API::Entities::BasicProjectDetails if options[:simple] diff --git a/spec/requests/api/v3/project_hooks_spec.rb b/spec/requests/api/v3/project_hooks_spec.rb index 36fbcf088e7..a981119dc5a 100644 --- a/spec/requests/api/v3/project_hooks_spec.rb +++ b/spec/requests/api/v3/project_hooks_spec.rb @@ -21,9 +21,9 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do describe "GET /projects/:id/hooks" do context "authorized user" do it "returns project hooks" do - get api("/projects/#{project.id}/hooks", user) - expect(response).to have_http_status(200) + get v3_api("/projects/#{project.id}/hooks", user) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.count).to eq(1) expect(json_response.first['url']).to eq("http://example.com") @@ -41,7 +41,8 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do context "unauthorized user" do it "does not access project hooks" do - get api("/projects/#{project.id}/hooks", user3) + get v3_api("/projects/#{project.id}/hooks", user3) + expect(response).to have_http_status(403) end end @@ -50,7 +51,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do describe "GET /projects/:id/hooks/:hook_id" do context "authorized user" do it "returns a project hook" do - get api("/projects/#{project.id}/hooks/#{hook.id}", user) + get v3_api("/projects/#{project.id}/hooks/#{hook.id}", user) expect(response).to have_http_status(200) expect(json_response['url']).to eq(hook.url) expect(json_response['issues_events']).to eq(hook.issues_events) @@ -65,20 +66,20 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do end it "returns a 404 error if hook id is not available" do - get api("/projects/#{project.id}/hooks/1234", user) + get v3_api("/projects/#{project.id}/hooks/1234", user) expect(response).to have_http_status(404) end end context "unauthorized user" do it "does not access an existing hook" do - get api("/projects/#{project.id}/hooks/#{hook.id}", user3) + get v3_api("/projects/#{project.id}/hooks/#{hook.id}", user3) expect(response).to have_http_status(403) end end it "returns a 404 error if hook id is not available" do - get api("/projects/#{project.id}/hooks/1234", user) + get v3_api("/projects/#{project.id}/hooks/1234", user) expect(response).to have_http_status(404) end end @@ -86,7 +87,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do describe "POST /projects/:id/hooks" do it "adds hook to project" do expect do - post api("/projects/#{project.id}/hooks", user), + post v3_api("/projects/#{project.id}/hooks", user), url: "http://example.com", issues_events: true, wiki_page_events: true end.to change {project.hooks.count}.by(1) @@ -108,7 +109,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do token = "secret token" expect do - post api("/projects/#{project.id}/hooks", user), url: "http://example.com", token: token + post v3_api("/projects/#{project.id}/hooks", user), url: "http://example.com", token: token end.to change {project.hooks.count}.by(1) expect(response).to have_http_status(201) @@ -122,19 +123,19 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do end it "returns a 400 error if url not given" do - post api("/projects/#{project.id}/hooks", user) + post v3_api("/projects/#{project.id}/hooks", user) expect(response).to have_http_status(400) end it "returns a 422 error if url not valid" do - post api("/projects/#{project.id}/hooks", user), "url" => "ftp://example.com" + post v3_api("/projects/#{project.id}/hooks", user), "url" => "ftp://example.com" expect(response).to have_http_status(422) end end describe "PUT /projects/:id/hooks/:hook_id" do it "updates an existing project hook" do - put api("/projects/#{project.id}/hooks/#{hook.id}", user), + put v3_api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'http://example.org', push_events: false expect(response).to have_http_status(200) expect(json_response['url']).to eq('http://example.org') @@ -152,7 +153,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do it "adds the token without including it in the response" do token = "secret token" - put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: "http://example.org", token: token + put v3_api("/projects/#{project.id}/hooks/#{hook.id}", user), url: "http://example.org", token: token expect(response).to have_http_status(200) expect(json_response["url"]).to eq("http://example.org") @@ -163,17 +164,17 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do end it "returns 404 error if hook id not found" do - put api("/projects/#{project.id}/hooks/1234", user), url: 'http://example.org' + put v3_api("/projects/#{project.id}/hooks/1234", user), url: 'http://example.org' expect(response).to have_http_status(404) end it "returns 400 error if url is not given" do - put api("/projects/#{project.id}/hooks/#{hook.id}", user) + put v3_api("/projects/#{project.id}/hooks/#{hook.id}", user) expect(response).to have_http_status(400) end it "returns a 422 error if url is not valid" do - put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'ftp://example.com' + put v3_api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'ftp://example.com' expect(response).to have_http_status(422) end end @@ -181,23 +182,23 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do describe "DELETE /projects/:id/hooks/:hook_id" do it "deletes hook from project" do expect do - delete api("/projects/#{project.id}/hooks/#{hook.id}", user) + delete v3_api("/projects/#{project.id}/hooks/#{hook.id}", user) end.to change {project.hooks.count}.by(-1) expect(response).to have_http_status(200) end it "returns success when deleting hook" do - delete api("/projects/#{project.id}/hooks/#{hook.id}", user) + delete v3_api("/projects/#{project.id}/hooks/#{hook.id}", user) expect(response).to have_http_status(200) end it "returns a 404 error when deleting non existent hook" do - delete api("/projects/#{project.id}/hooks/42", user) + delete v3_api("/projects/#{project.id}/hooks/42", user) expect(response).to have_http_status(404) end it "returns a 404 error if hook id not given" do - delete api("/projects/#{project.id}/hooks", user) + delete v3_api("/projects/#{project.id}/hooks", user) expect(response).to have_http_status(404) end @@ -207,7 +208,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do other_project = create(:project) other_project.team << [test_user, :master] - delete api("/projects/#{other_project.id}/hooks/#{hook.id}", test_user) + delete v3_api("/projects/#{other_project.id}/hooks/#{hook.id}", test_user) expect(response).to have_http_status(404) expect(WebHook.exists?(hook.id)).to be_truthy end -- cgit v1.2.1