environments_spec.rb 5.73 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's avatar
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 51 52 53 54

        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
55
            expect(page).to have_link(manual.name.capitalize)
56 57 58 59
          end

          scenario 'does allow to play manual action' do
            expect(manual).to be_skipped
60
            expect{ click_link(manual.name.capitalize) }.to change{ Ci::Pipeline.count }.by(0)
61 62 63 64
            expect(page).to have_content(manual.name)
            expect(manual.reload).to be_pending
          end
        end
65 66 67
      end
    end

68
    scenario 'does have a New environment button' do
69 70 71 72
      expect(page).to have_link('New environment')
    end
  end

73 74 75
  describe 'when showing the environment' do
    given(:environment) { create(:environment, project: project) }
    given!(:deployment) { }
76
    given!(:manual) { }
77

78 79 80
    before do
      visit namespace_project_environment_path(project.namespace, project, environment)
    end
81 82

    context 'without deployments' do
83
      scenario 'does show no deployments' do
84
        expect(page).to have_content('You don\'t have any deployments right now.')
85 86 87 88
      end
    end

    context 'with deployments' do
89
      given(:deployment) { create(:deployment, environment: environment) }
90

91
      scenario 'does show deployment SHA' do
92 93 94
        expect(page).to have_link(deployment.short_sha)
      end

95
      scenario 'does not show a retry button for deployment without build' do
96 97 98 99
        expect(page).not_to have_link('Retry')
      end

      context 'with build' do
100 101
        given(:pipeline) { create(:ci_pipeline, project: project) }
        given(:build) { create(:ci_build, pipeline: pipeline) }
102
        given(:deployment) { create(:deployment, environment: environment, deployable: build) }
103

104
        scenario 'does show build name' do
105 106 107
          expect(page).to have_link("#{build.name} (##{build.id})")
        end

108
        scenario 'does show retry button' do
109 110
          expect(page).to have_link('Retry')
        end
111 112 113 114 115

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

          scenario 'does show a play button' do
116
            expect(page).to have_link(manual.name.capitalize)
117 118 119 120
          end

          scenario 'does allow to play manual action' do
            expect(manual).to be_skipped
121
            expect{ click_link(manual.name.capitalize) }.to change{ Ci::Pipeline.count }.by(0)
122 123 124 125
            expect(page).to have_content(manual.name)
            expect(manual.reload).to be_pending
          end
        end
126 127 128 129
      end
    end
  end

130 131 132 133
  describe 'when creating a new environment' do
    before do
      visit namespace_project_environments_path(project.namespace, project)
    end
134 135

    context 'when logged as developer' do
136 137 138
      before do
        click_link 'New environment'
      end
139 140 141

      context 'for valid name' do
        before do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
142
          fill_in('Name', with: 'production')
143 144 145
          click_on 'Create environment'
        end

146
        scenario 'does create a new pipeline' do
Phil Hughes's avatar
Phil Hughes committed
147
          expect(page).to have_content('Production')
148 149 150 151 152
        end
      end

      context 'for invalid name' do
        before do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
153
          fill_in('Name', with: 'name with spaces')
154 155 156
          click_on 'Create environment'
        end

157 158 159
        scenario 'does show errors' do
          expect(page).to have_content('Name can contain only letters')
        end
160 161 162 163
      end
    end

    context 'when logged as reporter' do
164
      given(:role) { :reporter }
165

166
      scenario 'does not have a New environment link' do
167 168 169 170 171
        expect(page).not_to have_link('New environment')
      end
    end
  end

172 173
  describe 'when deleting existing environment' do
    given(:environment) { create(:environment, project: project) }
174

175 176 177
    before do
      visit namespace_project_environment_path(project.namespace, project, environment)
    end
178

Kamil Trzcinski's avatar
Kamil Trzcinski committed
179
    context 'when logged as master' do
180
      given(:role) { :master }
181

182 183
      scenario 'does delete environment' do
        click_link 'Destroy'
184 185 186 187
        expect(page).not_to have_link(environment.name)
      end
    end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
188
    context 'when logged as developer' do
189
      given(:role) { :developer }
190

191
      scenario 'does not have a Destroy link' do
192 193 194 195 196
        expect(page).not_to have_link('Destroy')
      end
    end
  end
end