Commit 20047e72 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix environment specs related to protected actions

parent f8eb8fea
......@@ -8,6 +8,7 @@
= icon('caret-down')
%ul.dropdown-menu.dropdown-menu-align-right
- actions.each do |action|
- next unless can?(current_user, :update_build, action)
%li
= link_to [:play, @project.namespace.becomes(Namespace), @project, action], method: :post, rel: 'nofollow' do
= custom_icon('icon_play')
......
......@@ -13,7 +13,7 @@
= render 'projects/environments/metrics_button', environment: @environment
- if can?(current_user, :update_environment, @environment)
= link_to 'Edit', edit_namespace_project_environment_path(@project.namespace, @project, @environment), class: 'btn'
- if can?(current_user, :create_deployment, @environment) && @environment.can_stop?
- if can?(current_user, :stop_environment, @environment)
= link_to 'Stop', stop_namespace_project_environment_path(@project.namespace, @project, @environment), data: { confirm: 'Are you sure you want to stop this environment?' }, class: 'btn btn-danger', method: :post
.environments-container
......
......@@ -12,6 +12,7 @@ feature 'Environment', :feature do
feature 'environment details page' do
given!(:environment) { create(:environment, project: project) }
given!(:permissions) { }
given!(:deployment) { }
given!(:action) { }
......@@ -62,20 +63,31 @@ feature 'Environment', :feature do
name: 'deploy to production')
end
given(:role) { :master }
context 'when user has ability to trigger deployment' do
given(:permissions) do
create(:protected_branch, :developers_can_merge,
name: action.ref, project: project)
end
scenario 'does show a play button' do
expect(page).to have_link(action.name.humanize)
end
it 'does show a play button' do
expect(page).to have_link(action.name.humanize)
end
it 'does allow to play manual action' do
expect(action).to be_manual
scenario 'does allow to play manual action' do
expect(action).to be_manual
expect { click_link(action.name.humanize) }
.not_to change { Ci::Pipeline.count }
expect { click_link(action.name.humanize) }
.not_to change { Ci::Pipeline.count }
expect(page).to have_content(action.name)
expect(action.reload).to be_pending
end
end
expect(page).to have_content(action.name)
expect(action.reload).to be_pending
context 'when user has no ability to trigger a deployment' do
it 'does not show a play button' do
expect(page).not_to have_link(action.name.humanize)
end
end
context 'with external_url' do
......@@ -134,12 +146,23 @@ feature 'Environment', :feature do
on_stop: 'close_app')
end
given(:role) { :master }
context 'when user has ability to stop environment' do
given(:permissions) do
create(:protected_branch, :developers_can_merge,
name: action.ref, project: project)
end
scenario 'does allow to stop environment' do
click_link('Stop')
it 'allows to stop environment' do
click_link('Stop')
expect(page).to have_content('close_app')
expect(page).to have_content('close_app')
end
end
context 'when user has no ability to stop environment' do
it 'does not allow to stop environment' do
expect(page).to have_no_link('Stop')
end
end
context 'for reporter' do
......@@ -150,12 +173,6 @@ feature 'Environment', :feature do
end
end
end
context 'without stop action' do
scenario 'does allow to stop environment' do
click_link('Stop')
end
end
end
context 'when environment is stopped' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment