Fix specs

This commit is contained in:
Kamil Trzcinski 2016-10-17 22:01:56 +02:00
parent e988072207
commit 34e19b9b8d
4 changed files with 43 additions and 57 deletions

View File

@ -1,7 +1,7 @@
class Projects::EnvironmentsController < Projects::ApplicationController
layout 'project'
before_action :authorize_read_environment!
before_action :authorize_create_environment!, only: [:new, :create, :stop]
before_action :authorize_create_environment!, only: [:new, :create]
before_action :authorize_create_deployment!, only: [:stop]
before_action :authorize_update_environment!, only: [:edit, :update]
before_action :environment, only: [:show, :edit, :update, :stop]

View File

@ -119,7 +119,7 @@ feature 'Environments', feature: true do
expect(page).to have_selector('.close-env-link')
end
scenario 'does allow to stop environment' do
scenario 'starts build when stop button clicked' do
first('.close-env-link').click
expect(page).to have_content('close_app')
@ -217,7 +217,7 @@ feature 'Environments', feature: true do
expect(page).to have_link('Stop')
end
scenario 'does allow to stop environment' do
scenario ' scenario 'does allow to stop environment' do' do
click_link('Stop')
expect(page).to have_content('close_app')
@ -277,42 +277,4 @@ feature 'Environments', feature: true do
end
end
end
describe 'when deleting existing environment' do
given(:environment) { create(:environment, project: project) }
before do
visit namespace_project_environment_path(project.namespace, project, environment)
end
context 'when logged as master' do
given(:role) { :master }
scenario 'does not have a Close link' do
expect(page).not_to have_link('Close')
end
context 'when environment is opened and can be closed' do
let(:project) { create(:project) }
let(:environment) { create(:environment, project: project) }
let!(:deployment) do
create(:deployment, environment: environment, sha: project.commit('master').id)
end
scenario 'does have a Close link' do
# TODO: Add missing validation. In order to have Close link
# this must be true: last_deployment.try(:close_action)
end
end
end
context 'when logged as developer' do
given(:role) { :developer }
scenario 'does not have a Close link' do
expect(page).not_to have_link('Close')
end
end
end
end

View File

@ -101,15 +101,6 @@ feature 'Merge When Build Succeeds', feature: true, js: true do
expect(page).not_to have_link "Merge When Build Succeeds"
end
end
context 'Has Environment' do
let(:environment) { create(:environment, project: project) }
it 'does show link to close the environment' do
# TODO add test to verify if the button is visible when this condition
# is met: if environment.closeable?
end
end
def visit_merge_request(merge_request)
visit namespace_project_merge_request_path(merge_request.project.namespace, merge_request.project, merge_request)

View File

@ -4,23 +4,56 @@ feature 'Widget Deployments Header', feature: true, js: true do
include WaitForAjax
describe 'when deployed to an environment' do
let(:project) { merge_request.target_project }
let(:merge_request) { create(:merge_request, :merged) }
let(:environment) { create(:environment, project: project) }
let!(:deployment) do
given(:user) { create(:user) }
given(:project) { merge_request.target_project }
given(:merge_request) { create(:merge_request, :merged) }
given(:environment) { create(:environment, project: project) }
given(:role) { :developer }
given!(:deployment) do
create(:deployment, environment: environment, sha: project.commit('master').id)
end
given!(:manual) { }
before do
login_as :admin
background do
login_as(user)
project.team << [user, role]
visit namespace_project_merge_request_path(project.namespace, project, merge_request)
end
it 'displays that the environment is deployed' do
scenario 'displays that the environment is deployed' do
wait_for_ajax
expect(page).to have_content("Deployed to #{environment.name}")
expect(find('.ci_widget > span > span')['data-title']).to eq(deployment.created_at.to_time.in_time_zone.to_s(:medium))
end
context 'with stop action' do
given(:pipeline) { create(:ci_pipeline, project: project) }
given(:build) { create(:ci_build, pipeline: pipeline) }
given(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'close_app') }
given(:deployment) { create(:deployment, environment: environment, deployable: build, on_stop: 'close_app') }
background do
wait_for_ajax
end
scenario 'does show stop button' do
expect(page).to have_link('Stop environment')
end
scenario 'does start build when stop button clicked' do
click_link('Stop environment')
expect(page).to have_content('close_app')
end
context 'for reporter' do
given(:role) { :reporter }
scenario 'does not show stop button' do
expect(page).not_to have_link('Stop environment')
end
end
end
end
end