Commit 30877eff authored by Kamil Trzcinski's avatar Kamil Trzcinski

Test environment controller specs

parent 6209b60c
...@@ -24,4 +24,8 @@ class Deployment < ActiveRecord::Base ...@@ -24,4 +24,8 @@ class Deployment < ActiveRecord::Base
def short_sha def short_sha
Commit::truncate_sha(sha) Commit::truncate_sha(sha)
end end
def last?
self == environment.last_deployment
end
end end
...@@ -27,4 +27,8 @@ ...@@ -27,4 +27,8 @@
%td %td
- if can?(current_user, :update_deployment, @project) && deployment.deployable - if can?(current_user, :update_deployment, @project) && deployment.deployable
.pull-right .pull-right
= link_to 'Retry', retry_namespace_project_build_path(@project.namespace, @project, deployment.deployable), method: :post, class: 'btn btn-build' = link_to retry_namespace_project_build_path(@project.namespace, @project, deployment.deployable), method: :post, class: 'btn btn-build' do
- if deployment.last?
Retry
- else
Rollback
require 'spec_helper'
describe 'Environments' do
include GitlabRoutingHelper
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
let(:role) { :developer }
before do
login_as(user)
project.team << [user, role]
end
describe 'GET /:project/environments' do
subject { visit namespace_project_environments_path(project.namespace, project) }
context 'without environments' do
it 'does show no environments' do
subject
expect(page).to have_content('No environments to show')
end
end
context 'with environments' do
let!(:environment) { create(:environment, project: project) }
it 'does show environment name' do
subject
expect(page).to have_link(environment.name)
end
context 'without deployments' do
it 'does show no deployments' do
subject
expect(page).to have_content('No deployments yet')
end
end
context 'with deployments' do
let!(:deployment) { create(:deployment, environment: environment) }
it 'does show deployment SHA' do
subject
expect(page).to have_link(deployment.short_sha)
end
end
end
it 'does have a New environment button' do
subject
expect(page).to have_link('New environment')
end
end
describe 'GET /:project/environments/:id' do
let(:environment) { create(:environment, project: project) }
subject { visit namespace_project_environment_path(project.namespace, project, environment) }
context 'without deployments' do
it 'does show no deployments' do
subject
expect(page).to have_content('No deployments for')
end
end
context 'with deployments' do
let!(:deployment) { create(:deployment, environment: environment) }
before { subject }
it 'does show deployment SHA' do
expect(page).to have_link(deployment.short_sha)
end
it 'does not show a retry button for deployment without build' do
expect(page).not_to have_link('Retry')
end
context 'with build' do
let(:build) { create(:ci_build, project: project) }
let(:deployment) { create(:deployment, environment: environment, deployable: build) }
it 'does show build name' do
expect(page).to have_link("#{build.name} (##{build.id})")
end
it 'does show retry button' do
expect(page).to have_link('Retry')
end
end
end
end
describe 'POST /:project/environments' do
before { visit namespace_project_environments_path(project.namespace, project) }
context 'when logged as developer' do
before { click_link 'New environment' }
context 'for valid name' do
before do
fill_in('Environment name', with: 'production')
click_on 'Create environment'
end
it 'does create a new pipeline' do
expect(page).to have_content('production')
end
end
context 'for invalid name' do
before do
fill_in('Environment name', with: 'name with spaces')
click_on 'Create environment'
end
it { expect(page).to have_content('Name can contain only letters') }
end
end
context 'when logged as reporter' do
let(:role) { :reporter }
it 'does not have a New environment link' do
expect(page).not_to have_link('New environment')
end
end
end
describe 'DELETE /:project/environments/:id' do
let(:environment) { create(:environment, project: project) }
before { visit namespace_project_environment_path(project.namespace, project, environment) }
context 'when logged as developer' do
before { click_link 'Destroy' }
it 'does not have environment' do
expect(page).not_to have_link(environment.name)
end
end
context 'when logged as reporter' do
let(:role) { :reporter }
it 'does not have a Destroy link' do
expect(page).not_to have_link('Destroy')
end
end
end
end
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