-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API endpoint for staged_requests
API endpoint to list all staged requests in a staging project
- Loading branch information
Showing
5 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
src/api/app/controllers/staging_project/staged_requests_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
5 changes: 5 additions & 0 deletions
5
src/api/app/views/staging_project/staged_requests/index.xml.builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/api/spec/controllers/staging_project/staged_requests_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |