Skip to content

Commit

Permalink
Add API endpoint for staged_requests
Browse files Browse the repository at this point in the history
API endpoint to list all staged requests in a staging project
  • Loading branch information
vpereira committed Oct 30, 2018
1 parent feaa93e commit 27bee31
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class StagingProject::StagedRequestsController < StagingProjectController
def index
@requests = @project.staged_requests
end
end
10 changes: 10 additions & 0 deletions src/api/app/controllers/staging_project_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class StagingProjectController < ApplicationController
before_action :set_project

private

def set_project
@project = Project.find_by(name: params[:project])
raise ActiveRecord::RecordNotFound unless @project
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
xml.staged_requests do
@requests.each do |bs_request|
xml.request(id: bs_request.number, creator: bs_request.creator, state: bs_request.state, package: bs_request.first_target_package)
end
end
3 changes: 3 additions & 0 deletions src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,9 @@ def self.public_or_about_path?(request)
get 'projects/:project/packages/:package/requests' => 'webui/packages/bs_requests#index', constraints: cons, as: 'packages_requests'
end

# StagingWorkflow API
get 'staging_project/:project/staged_requests' => 'staging_project/staged_requests#index', constraints: cons, as: 'staged_requests'

controller :source_attribute do
get 'source/:project(/:package(/:binary))/_attribute(/:attribute)' => :show, constraints: cons
post 'source/:project(/:package(/:binary))/_attribute(/:attribute)' => :update, constraints: cons, as: :change_attribute
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'rails_helper'

RSpec.describe StagingProject::StagedRequestsController, type: :controller do
render_views
describe 'GET #index' do
let(:user) { create(:confirmed_user) }
let(:project) { create(:project_with_package) }
let(:staging_workflow) { create(:staging_workflow_with_staging_projects, project: project) }
let(:staging_project) { staging_workflow.staging_projects.first }
let(:source_project) { create(:project, name: 'source_project') }
let(:target_package) { create(:package, name: 'target_package', project: project) }
let(:source_package) { create(:package, name: 'source_package', project: source_project) }
let(:bs_request) do
create(:bs_request_with_submit_action,
target_project: project.name,
target_package: target_package.name,
source_project: source_project.name,
source_package: source_package.name,
description: 'BsRequest 1')
end

before do
bs_request.staging_project = staging_project
bs_request.save
login user
get :index, params: { project: staging_project.name, format: :xml }
end

it { expect(response).to have_http_status(:success) }
it 'returns the staged_requests xml' do
assert_select 'staged_requests' do
assert_select 'request', 1
end
end
end
end

0 comments on commit 27bee31

Please sign in to comment.