-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add #new and #create actions for StagingWorkflowController
Now the user will be able to create a StagingWorkflow. By default it creates/uses two subprojects of the main project (:Staging:A and :Staging:B)
- Loading branch information
Showing
9 changed files
with
199 additions
and
6 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/api/app/controllers/webui/staging_workflows_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,48 @@ | ||
class Webui::StagingWorkflowsController < Webui::WebuiController | ||
layout 'webui2/webui' | ||
|
||
before_action :require_login, except: [:show] | ||
before_action :set_bootstrap_views | ||
before_action :set_project, only: [:new, :create] | ||
after_action :verify_authorized, except: [:show, :new] | ||
|
||
def new | ||
if @project.staging | ||
redirect_to staging_workflow_path(@project.staging) | ||
return | ||
end | ||
|
||
@staging_workflow = @project.build_staging | ||
end | ||
|
||
def create | ||
staging_workflow = @project.build_staging | ||
|
||
authorize staging_workflow | ||
|
||
if staging_workflow.save | ||
flash[:success] = "Staging Workflow for #{@project.name} was successfully created" | ||
redirect_to staging_workflow_path(staging_workflow) | ||
else | ||
flash[:error] = "Staging Workflow for #{@project.name} couldn't be created" | ||
render :new | ||
end | ||
end | ||
|
||
def show | ||
@staging_workflow = StagingWorkflow.find_by(id: params[:id]) | ||
unless @staging_workflow | ||
redirect_back(fallback_location: root_path) | ||
flash[:error] = "StagingWorkflow with id = #{params[:id]} doesn't exist" | ||
return | ||
end | ||
|
||
@project = @staging_workflow.project | ||
end | ||
|
||
private | ||
|
||
def set_bootstrap_views | ||
prepend_view_path('app/views/webui2') | ||
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
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
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,11 @@ | ||
class StagingWorkflowPolicy < ApplicationPolicy | ||
def initialize(user, record) | ||
raise Pundit::NotAuthorizedError, 'staging workflow does not exist' unless record | ||
@user = user | ||
@record = record | ||
end | ||
|
||
def create? | ||
ProjectPolicy.new(@user, @record.project).create? | ||
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
13 changes: 13 additions & 0 deletions
13
src/api/app/views/webui2/webui/staging_workflows/new.html.haml
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,13 @@ | ||
- @pagetitle = "Staging Projects for #{@project}" | ||
|
||
.card.mb-3 | ||
= render(partial: 'webui2/webui/project/tabs', locals: { project: @project }) | ||
.card-body | ||
%h3= @pagetitle | ||
.mb-3 | ||
Adding the staging capability to this project will enable you to group | ||
requests into staging projects and being able to see how they build together. | ||
.text-center | ||
= form_for @staging_workflow, method: :post do |f| | ||
= hidden_field_tag :project_name, @project | ||
= f.submit 'Create Staging Projects', class: 'btn btn-primary' |
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
97 changes: 97 additions & 0 deletions
97
src/api/spec/controllers/webui/staging_workflows_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,97 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Webui::StagingWorkflowsController do | ||
let(:user) { create(:confirmed_user, login: 'tom') } | ||
let(:project) { user.home_project } | ||
|
||
before do | ||
login(user) | ||
end | ||
|
||
describe 'GET #new' do | ||
context 'non existent staging_workflow for project' do | ||
before do | ||
get :new, params: { project: project.name } | ||
end | ||
|
||
it { expect(StagingWorkflow.count).to eq(0) } | ||
it { expect(assigns[:staging_workflow].class).to be(StagingWorkflow) } | ||
it { expect(response).to render_template(:new) } | ||
end | ||
|
||
context 'with an existent staging_workflow for project' do | ||
before do | ||
project.create_staging | ||
get :new, params: { project: project.name } | ||
end | ||
|
||
it { expect(StagingWorkflow.count).to eq(1) } | ||
it { expect(response).to redirect_to(staging_workflow_path(project.staging)) } | ||
end | ||
end | ||
|
||
describe 'POST #create' do | ||
context 'a staging_workflow and staging_projects' do | ||
before do | ||
post :create, params: { project: project.name } | ||
end | ||
|
||
subject { project.staging } | ||
|
||
it { expect(StagingWorkflow.count).to eq(1) } | ||
it { expect(subject.staging_projects.map(&:name)).to match_array(['home:tom:Staging:A', 'home:tom:Staging:B']) } | ||
it { expect(response).to redirect_to(staging_workflow_path(project.staging)) } | ||
it { expect(flash[:success]).not_to be_nil } | ||
end | ||
|
||
context 'with existent stagings projects' do | ||
let!(:staging_a) { create(:project, name: "#{project}:Staging:A") } | ||
let!(:staging_b) { create(:project, name: "#{project}:Staging:B") } | ||
|
||
before do | ||
post :create, params: { project: project.name } | ||
end | ||
|
||
subject { project.staging } | ||
|
||
it { expect(StagingWorkflow.count).to eq(1) } | ||
it { expect(subject.staging_projects.map(&:name)).to match_array(['home:tom:Staging:A', 'home:tom:Staging:B']) } | ||
it { expect(response).to redirect_to(staging_workflow_path(project.staging)) } | ||
it { expect(flash[:success]).not_to be_nil } | ||
end | ||
|
||
context 'when it fails to save' do | ||
before do | ||
allow_any_instance_of(StagingWorkflow).to receive(:save).and_return(false) | ||
post :create, params: { project: project.name } | ||
end | ||
|
||
it { expect(StagingWorkflow.count).to eq(0) } | ||
it { expect(response).to render_template(:new) } | ||
it { expect(flash[:error]).not_to be_nil } | ||
end | ||
end | ||
|
||
describe 'GET #show' do | ||
context 'non existent staging_workflow for project' do | ||
before do | ||
get :show, params: { id: 5 } | ||
end | ||
|
||
it { expect(assigns[:staging_workflow]).to be_nil } | ||
it { expect(response).to redirect_to(root_path) } | ||
it { expect(flash[:error]).not_to be_nil } | ||
end | ||
|
||
context 'with an existent staging_workflow for project' do | ||
before do | ||
project.create_staging | ||
get :show, params: { id: project.staging } | ||
end | ||
|
||
it { expect(assigns[:staging_workflow]).to eq(project.staging) } | ||
it { expect(assigns[:project]).to eq(project) } | ||
it { expect(response).to render_template(:show) } | ||
end | ||
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