BigW Consortium Gitlab

environments_spec.rb 4.22 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

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

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

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

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

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

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

43
        scenario 'does show deployment SHA' do
44 45 46 47 48
          expect(page).to have_link(deployment.short_sha)
        end
      end
    end

49
    scenario 'does have a New environment button' do
50 51 52 53
      expect(page).to have_link('New environment')
    end
  end

54 55 56
  describe 'when showing the environment' do
    given(:environment) { create(:environment, project: project) }
    given!(:deployment) { }
57

58 59 60
    before do
      visit namespace_project_environment_path(project.namespace, project, environment)
    end
61 62

    context 'without deployments' do
63
      scenario 'does show no deployments' do
64
        expect(page).to have_content('You don\'t have any deployments right now.')
65 66 67 68
      end
    end

    context 'with deployments' do
69
      given(:deployment) { create(:deployment, environment: environment) }
70

71
      scenario 'does show deployment SHA' do
72 73 74
        expect(page).to have_link(deployment.short_sha)
      end

75
      scenario 'does not show a retry button for deployment without build' do
76 77 78 79
        expect(page).not_to have_link('Retry')
      end

      context 'with build' do
80 81
        given(:build) { create(:ci_build, project: project) }
        given(:deployment) { create(:deployment, environment: environment, deployable: build) }
82

83
        scenario 'does show build name' do
84 85 86
          expect(page).to have_link("#{build.name} (##{build.id})")
        end

87
        scenario 'does show retry button' do
88 89 90 91 92 93
          expect(page).to have_link('Retry')
        end
      end
    end
  end

94 95 96 97
  describe 'when creating a new environment' do
    before do
      visit namespace_project_environments_path(project.namespace, project)
    end
98 99

    context 'when logged as developer' do
100 101 102
      before do
        click_link 'New environment'
      end
103 104 105

      context 'for valid name' do
        before do
106
          fill_in('Name', with: 'production')
107 108 109
          click_on 'Create environment'
        end

110
        scenario 'does create a new pipeline' do
Phil Hughes committed
111
          expect(page).to have_content('Production')
112 113 114 115 116
        end
      end

      context 'for invalid name' do
        before do
117
          fill_in('Name', with: 'name with spaces')
118 119 120
          click_on 'Create environment'
        end

121 122 123
        scenario 'does show errors' do
          expect(page).to have_content('Name can contain only letters')
        end
124 125 126 127
      end
    end

    context 'when logged as reporter' do
128
      given(:role) { :reporter }
129

130
      scenario 'does not have a New environment link' do
131 132 133 134 135
        expect(page).not_to have_link('New environment')
      end
    end
  end

136 137
  describe 'when deleting existing environment' do
    given(:environment) { create(:environment, project: project) }
138

139 140 141
    before do
      visit namespace_project_environment_path(project.namespace, project, environment)
    end
142

143
    context 'when logged as master' do
144
      given(:role) { :master }
145

146 147
      scenario 'does delete environment' do
        click_link 'Destroy'
148 149 150 151
        expect(page).not_to have_link(environment.name)
      end
    end

152
    context 'when logged as developer' do
153
      given(:role) { :developer }
154

155
      scenario 'does not have a Destroy link' do
156 157 158 159 160
        expect(page).not_to have_link('Destroy')
      end
    end
  end
end