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

Fix environment specs related to protected actions

parent f8eb8fea
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
= icon('caret-down') = icon('caret-down')
%ul.dropdown-menu.dropdown-menu-align-right %ul.dropdown-menu.dropdown-menu-align-right
- actions.each do |action| - actions.each do |action|
- next unless can?(current_user, :update_build, action)
%li %li
= link_to [:play, @project.namespace.becomes(Namespace), @project, action], method: :post, rel: 'nofollow' do = link_to [:play, @project.namespace.becomes(Namespace), @project, action], method: :post, rel: 'nofollow' do
= custom_icon('icon_play') = custom_icon('icon_play')
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
= render 'projects/environments/metrics_button', environment: @environment = render 'projects/environments/metrics_button', environment: @environment
- if can?(current_user, :update_environment, @environment) - if can?(current_user, :update_environment, @environment)
= link_to 'Edit', edit_namespace_project_environment_path(@project.namespace, @project, @environment), class: 'btn' = 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 = 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 .environments-container
......
...@@ -12,6 +12,7 @@ feature 'Environment', :feature do ...@@ -12,6 +12,7 @@ feature 'Environment', :feature do
feature 'environment details page' do feature 'environment details page' do
given!(:environment) { create(:environment, project: project) } given!(:environment) { create(:environment, project: project) }
given!(:permissions) { }
given!(:deployment) { } given!(:deployment) { }
given!(:action) { } given!(:action) { }
...@@ -62,20 +63,31 @@ feature 'Environment', :feature do ...@@ -62,20 +63,31 @@ feature 'Environment', :feature do
name: 'deploy to production') name: 'deploy to production')
end 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 it 'does show a play button' do
expect(page).to have_link(action.name.humanize) expect(page).to have_link(action.name.humanize)
end end
it 'does allow to play manual action' do
expect(action).to be_manual
scenario 'does allow to play manual action' do expect { click_link(action.name.humanize) }
expect(action).to be_manual .not_to change { Ci::Pipeline.count }
expect { click_link(action.name.humanize) } expect(page).to have_content(action.name)
.not_to change { Ci::Pipeline.count } expect(action.reload).to be_pending
end
end
expect(page).to have_content(action.name) context 'when user has no ability to trigger a deployment' do
expect(action.reload).to be_pending it 'does not show a play button' do
expect(page).not_to have_link(action.name.humanize)
end
end end
context 'with external_url' do context 'with external_url' do
...@@ -134,12 +146,23 @@ feature 'Environment', :feature do ...@@ -134,12 +146,23 @@ feature 'Environment', :feature do
on_stop: 'close_app') on_stop: 'close_app')
end 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 it 'allows to stop environment' do
click_link('Stop') 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 end
context 'for reporter' do context 'for reporter' do
...@@ -150,12 +173,6 @@ feature 'Environment', :feature do ...@@ -150,12 +173,6 @@ feature 'Environment', :feature do
end end
end end
end end
context 'without stop action' do
scenario 'does allow to stop environment' do
click_link('Stop')
end
end
end end
context 'when environment is stopped' do 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