summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-06-14 14:47:00 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-06-14 14:47:00 +0200
commit30877effb15d8a3eccc13925549a4c97de93c58e (patch)
treecfe0f24ada671e70acfdb3a2b236a2b2cd5bed3e
parent6209b60c96d8b380ac184d83647c3c8b0b026cac (diff)
downloadgitlab-ce-30877effb15d8a3eccc13925549a4c97de93c58e.tar.gz
Test environment controller specs
-rw-r--r--app/models/deployment.rb4
-rw-r--r--app/views/projects/deployments/_deployment.html.haml6
-rw-r--r--spec/features/environments_spec.rb159
3 files changed, 168 insertions, 1 deletions
diff --git a/app/models/deployment.rb b/app/models/deployment.rb
index 44a0a7fdd10..32799ee27e6 100644
--- a/app/models/deployment.rb
+++ b/app/models/deployment.rb
@@ -24,4 +24,8 @@ class Deployment < ActiveRecord::Base
def short_sha
Commit::truncate_sha(sha)
end
+
+ def last?
+ self == environment.last_deployment
+ end
end
diff --git a/app/views/projects/deployments/_deployment.html.haml b/app/views/projects/deployments/_deployment.html.haml
index 539c297cad3..1ac17af8b58 100644
--- a/app/views/projects/deployments/_deployment.html.haml
+++ b/app/views/projects/deployments/_deployment.html.haml
@@ -27,4 +27,8 @@
%td
- if can?(current_user, :update_deployment, @project) && deployment.deployable
.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
diff --git a/spec/features/environments_spec.rb b/spec/features/environments_spec.rb
new file mode 100644
index 00000000000..b73bb30e216
--- /dev/null
+++ b/spec/features/environments_spec.rb
@@ -0,0 +1,159 @@
+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