Skip to content

Commit

Permalink
Deal with non-existent managers group
Browse files Browse the repository at this point in the history
We need to use `redirect_to` instead of `render` as otherwise, the
value of `action_name` is `create` instead of `new`. This
would bring a lot of issues in the rendering of the breadcrumbs.

Fixes #6313
  • Loading branch information
dmarcoux committed Nov 21, 2018
1 parent 5801575 commit 319744d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 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
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 319744d

Please sign in to comment.