BigW Consortium Gitlab

environments_spec.rb 6.99 KB
Newer Older
1 2
require 'spec_helper'

3 4 5 6
feature 'Environments', feature: true do
  given(:project) { create(:empty_project) }
  given(:user) { create(:user) }
  given(:role) { :developer }
7

8
  background do
9 10 11 12
    login_as(user)
    project.team << [user, role]
  end

13 14 15
  describe 'when showing environments' do
    given!(:environment) { }
    given!(:deployment) { }
16
    given!(:manual) { }
17

18 19 20
    before do
      visit namespace_project_environments_path(project.namespace, project)
    end
21

22 23
    context 'without environments' do
      scenario 'does show no environments' do
24
        expect(page).to have_content('You don\'t have any environments right now.')
25 26 27 28
      end
    end

    context 'with environments' do
29
      given(:environment) { create(:environment, project: project) }
30

31
      scenario 'does show environment name' do
32 33 34 35
        expect(page).to have_link(environment.name)
      end

      context 'without deployments' do
36
        scenario 'does show no deployments' do
Phil Hughes committed
37
          expect(page).to have_content('No deployments yet')
38 39 40 41
        end
      end

      context 'with deployments' do
42
        given(:deployment) { create(:deployment, environment: environment) }
43

44
        scenario 'does show deployment SHA' do
45 46
          expect(page).to have_link(deployment.short_sha)
        end
47 48 49 50
        
        scenario 'does show deployment internal id' do
          expect(page).to have_content(deployment.iid)
        end
51 52 53 54 55 56 57 58

        context 'with build and manual actions' do
          given(:pipeline) { create(:ci_pipeline, project: project) }
          given(:build) { create(:ci_build, pipeline: pipeline) }
          given(:deployment) { create(:deployment, environment: environment, deployable: build) }
          given(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'deploy to production') }

          scenario 'does show a play button' do
Kamil Trzcinski committed
59
            expect(page).to have_link(manual.name.humanize)
60 61 62 63
          end

          scenario 'does allow to play manual action' do
            expect(manual).to be_skipped
Kamil Trzcinski committed
64
            expect{ click_link(manual.name.humanize) }.not_to change { Ci::Pipeline.count }
65 66 67
            expect(page).to have_content(manual.name)
            expect(manual.reload).to be_pending
          end
68 69 70 71 72 73 74 75 76 77 78
          
          scenario 'does show build name and id' do
            expect(page).to have_link("#{build.name} (##{build.id})")
          end
          
          context 'with external_url' do
            given(:environment) { create(:environment, project: project, external_url: 'https://git.gitlab.com') }
            given(:build) { create(:ci_build, pipeline: pipeline) }
            given(:deployment) { create(:deployment, environment: environment, deployable: build) }
            
            scenario 'does show an external link button' do
79
              expect(page).to have_link(nil, href: environment.external_url)
80 81
            end
          end
82
        end
83 84 85
      end
    end

86
    scenario 'does have a New environment button' do
87 88 89 90
      expect(page).to have_link('New environment')
    end
  end

91 92 93
  describe 'when showing the environment' do
    given(:environment) { create(:environment, project: project) }
    given!(:deployment) { }
94
    given!(:manual) { }
95

96 97 98
    before do
      visit namespace_project_environment_path(project.namespace, project, environment)
    end
99 100

    context 'without deployments' do
101
      scenario 'does show no deployments' do
102
        expect(page).to have_content('You don\'t have any deployments right now.')
103 104 105 106
      end
    end

    context 'with deployments' do
107
      given(:deployment) { create(:deployment, environment: environment) }
108

109
      scenario 'does show deployment SHA' do
110 111 112
        expect(page).to have_link(deployment.short_sha)
      end

113 114
      scenario 'does not show a re-deploy button for deployment without build' do
        expect(page).not_to have_link('Re-deploy')
115 116 117
      end

      context 'with build' do
118 119
        given(:pipeline) { create(:ci_pipeline, project: project) }
        given(:build) { create(:ci_build, pipeline: pipeline) }
120
        given(:deployment) { create(:deployment, environment: environment, deployable: build) }
121

122
        scenario 'does show build name' do
123 124 125
          expect(page).to have_link("#{build.name} (##{build.id})")
        end

126 127
        scenario 'does show re-deploy button' do
          expect(page).to have_link('Re-deploy')
128
        end
129 130 131 132 133

        context 'with manual action' do
          given(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'deploy to production') }

          scenario 'does show a play button' do
Kamil Trzcinski committed
134
            expect(page).to have_link(manual.name.humanize)
135 136 137 138
          end

          scenario 'does allow to play manual action' do
            expect(manual).to be_skipped
Kamil Trzcinski committed
139
            expect{ click_link(manual.name.humanize) }.not_to change { Ci::Pipeline.count }
140 141 142
            expect(page).to have_content(manual.name)
            expect(manual.reload).to be_pending
          end
143 144 145 146 147 148 149
          
          context 'with external_url' do
            given(:environment) { create(:environment, project: project, external_url: 'https://git.gitlab.com') }
            given(:build) { create(:ci_build, pipeline: pipeline) }
            given(:deployment) { create(:deployment, environment: environment, deployable: build) }
            
            scenario 'does show an external link button' do
150
              expect(page).to have_link(nil, href: environment.external_url)
151 152
            end
          end
153
        end
154 155 156 157
      end
    end
  end

158 159 160 161
  describe 'when creating a new environment' do
    before do
      visit namespace_project_environments_path(project.namespace, project)
    end
162 163

    context 'when logged as developer' do
164 165 166
      before do
        click_link 'New environment'
      end
167 168 169

      context 'for valid name' do
        before do
170
          fill_in('Name', with: 'production')
171
          click_on 'Save'
172 173
        end

174
        scenario 'does create a new pipeline' do
Phil Hughes committed
175
          expect(page).to have_content('Production')
176 177 178 179 180
        end
      end

      context 'for invalid name' do
        before do
181
          fill_in('Name', with: 'name,with,commas')
182
          click_on 'Save'
183 184
        end

185 186 187
        scenario 'does show errors' do
          expect(page).to have_content('Name can contain only letters')
        end
188 189 190 191
      end
    end

    context 'when logged as reporter' do
192
      given(:role) { :reporter }
193

194
      scenario 'does not have a New environment link' do
195 196 197 198 199
        expect(page).not_to have_link('New environment')
      end
    end
  end

200 201
  describe 'when deleting existing environment' do
    given(:environment) { create(:environment, project: project) }
202

203 204 205
    before do
      visit namespace_project_environment_path(project.namespace, project, environment)
    end
206

207
    context 'when logged as master' do
208
      given(:role) { :master }
209

210 211
      scenario 'does delete environment' do
        click_link 'Destroy'
212 213 214 215
        expect(page).not_to have_link(environment.name)
      end
    end

216
    context 'when logged as developer' do
217
      given(:role) { :developer }
218

219
      scenario 'does not have a Destroy link' do
220 221 222 223 224
        expect(page).not_to have_link('Destroy')
      end
    end
  end
end