Skip to content

Commit

Permalink
Merge pull request #6324 from dmarcoux/staging-workflow-managers-grou…
Browse files Browse the repository at this point in the history
…p-improvements

Staging workflow managers group improvements
  • Loading branch information
hennevogel committed Nov 21, 2018
2 parents 44c3b43 + 779ebf1 commit 9bdbfea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ def create

staging_workflow.managers_group = Group.find_by(title: params[:managers_title])

unless staging_workflow.managers_group
flash[:error] = "Managers Group #{params[:managers_title]} couldn't be found"
redirect_to new_staging_workflow_path(project_name: @project)
return
end

if staging_workflow.save
flash[:success] = "Staging for #{@project} was successfully created"
redirect_to staging_workflow_path(staging_workflow)
else
flash[:error] = "Staging for #{@project} couldn't be created"
render :new
redirect_to new_staging_workflow_path(project_name: @project)
end
end

Expand Down
12 changes: 8 additions & 4 deletions src/api/app/views/webui2/webui/staging/workflows/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@
= render(partial: 'webui2/webui/project/tabs', locals: { project: @project })
.card-body
%h3= @pagetitle
.mb-3
%p
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.
%p
Managers groups can only be created by an admin. Please contact an
= Configuration[:admin_email] == 'unconfigured@openbuildservice.org' ? 'admin' : mail_to(Configuration[:admin_email], 'admin')
if don't have a group yet.
.mb-3.w-50.m-auto
= form_for @staging_workflow, method: :post do |f|
= hidden_field_tag :project_name, @project
.form-group#assign-managers-group-modal-input
= label_tag(:managers_title, 'Managers:')
= label_tag(:managers_title, 'Managers Group:')
.input-group
.input-group-prepend
%span.input-group-text#assign-managers-group-search-icon
%i.fa.fa-search
%i.fas.fa-spinner.fa-spin.d-none
= text_field_tag 'managers_title', '', required: true, placeholder: 'Type to autocomplete...', class: 'form-control',
data: { autocomplete_groups_url: url_for(controller: '/webui/groups', action: 'autocomplete') }
= text_field_tag 'managers_title', '', required: true, placeholder: 'Type the name of an existent group to autocomplete...',
class: 'form-control', data: { autocomplete_groups_url: url_for(controller: '/webui/groups', action: 'autocomplete') }
.text-center
= f.submit 'Create Staging Projects', class: 'btn btn-primary'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,26 @@
it { expect(flash[:success]).not_to be_nil }
end

context 'when it fails to save' do
context 'when it cannot find the managers group' do
let(:params) { { project_name: project.name, managers_title: 'ItDoesNotExist' } }

before do
post :create, params: params
end

it { expect(response).to redirect_to(new_staging_workflow_path(project_name: project)) }
it { expect(flash[:error]).to eq("Managers Group #{params[:managers_title]} couldn't be found") }
end

context 'when it fails to save the staging workflow' do
before do
allow_any_instance_of(Staging::Workflow).to receive(:save).and_return(false)
post :create, params: { project: project.name }
post :create, params: { project: project.name, managers_title: managers_group.title }
end

it { expect(Staging::Workflow.count).to eq(0) }
it { expect(response).to render_template(:new) }
it { expect(flash[:error]).not_to be_nil }
it { expect(response).to redirect_to(new_staging_workflow_path(project_name: project)) }
it { expect(flash[:error]).to eq("Staging for #{project} couldn't be created") }
end
end

Expand Down

0 comments on commit 9bdbfea

Please sign in to comment.