BigW Consortium Gitlab

builds_spec.rb 9.27 KB
Newer Older
1 2 3
require 'spec_helper'

describe "Builds" do
4 5
  let(:artifacts_file) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }

6 7
  before do
    login_as(:user)
8
    @commit = FactoryGirl.create :ci_pipeline
9
    @build = FactoryGirl.create :ci_build, pipeline: @commit
10
    @build2 = FactoryGirl.create :ci_build
11
    @project = @commit.project
12
    @project.team << [@user, :developer]
13 14
  end

Kamil Trzcinski committed
15
  describe "GET /:project/builds" do
16 17 18 19 20
    context "Pending scope" do
      before do
        visit namespace_project_builds_path(@project.namespace, @project, scope: :pending)
      end

21 22 23 24 25 26 27
      it "shows Pending tab builds" do
        expect(page).to have_link 'Cancel running'
        expect(page).to have_selector('.nav-links li.active', text: 'Pending')
        expect(page).to have_content @build.short_sha
        expect(page).to have_content @build.ref
        expect(page).to have_content @build.name
      end
28 29
    end

Kamil Trzcinski committed
30
    context "Running scope" do
Kamil Trzcinski committed
31
      before do
Kamil Trzcinski committed
32
        @build.run!
33
        visit namespace_project_builds_path(@project.namespace, @project, scope: :running)
Kamil Trzcinski committed
34 35
      end

36 37 38 39 40 41 42
      it "shows Running tab builds" do
        expect(page).to have_selector('.nav-links li.active', text: 'Running')
        expect(page).to have_link 'Cancel running'
        expect(page).to have_content @build.short_sha
        expect(page).to have_content @build.ref
        expect(page).to have_content @build.name
      end
Kamil Trzcinski committed
43 44
    end

Kamil Trzcinski committed
45
    context "Finished scope" do
Kamil Trzcinski committed
46
      before do
Kamil Trzcinski committed
47
        @build.run!
48
        visit namespace_project_builds_path(@project.namespace, @project, scope: :finished)
Kamil Trzcinski committed
49 50
      end

51 52 53 54 55
      it "shows Finished tab builds" do
        expect(page).to have_selector('.nav-links li.active', text: 'Finished')
        expect(page).to have_content 'No builds to show'
        expect(page).to have_link 'Cancel running'
      end
Kamil Trzcinski committed
56 57
    end

Kamil Trzcinski committed
58
    context "All builds" do
Kamil Trzcinski committed
59
      before do
60
        @project.builds.running_or_pending.each(&:success)
61
        visit namespace_project_builds_path(@project.namespace, @project)
Kamil Trzcinski committed
62 63
      end

64 65 66 67 68 69 70
      it "shows All tab builds" do
        expect(page).to have_selector('.nav-links li.active', text: 'All')
        expect(page).to have_content @build.short_sha
        expect(page).to have_content @build.ref
        expect(page).to have_content @build.name
        expect(page).not_to have_link 'Cancel running'
      end
Kamil Trzcinski committed
71 72 73
    end
  end

Kamil Trzcinski committed
74
  describe "POST /:project/builds/:id/cancel_all" do
Kamil Trzcinski committed
75 76
    before do
      @build.run!
77
      visit namespace_project_builds_path(@project.namespace, @project)
Douwe Maan committed
78
      click_link "Cancel running"
Kamil Trzcinski committed
79 80
    end

Dmitriy Zaporozhets committed
81
    it { expect(page).to have_selector('.nav-links li.active', text: 'All') }
82 83 84 85
    it { expect(page).to have_content 'canceled' }
    it { expect(page).to have_content @build.short_sha }
    it { expect(page).to have_content @build.ref }
    it { expect(page).to have_content @build.name }
86
    it { expect(page).not_to have_link 'Cancel running' }
Kamil Trzcinski committed
87 88
  end

89
  describe "GET /:project/builds/:id" do
90 91 92 93 94 95 96 97 98
    context "Build from project" do
      before do
        visit namespace_project_build_path(@project.namespace, @project, @build)
      end

      it { expect(page.status_code).to eq(200) }
      it { expect(page).to have_content @commit.sha[0..7] }
      it { expect(page).to have_content @commit.git_commit_message }
      it { expect(page).to have_content @commit.git_author_name }
99 100
    end

101 102 103 104 105 106 107
    context "Build from other project" do
      before do
        visit namespace_project_build_path(@project.namespace, @project, @build2)
      end

      it { expect(page.status_code).to eq(404) }
    end
108 109 110 111

    context "Download artifacts" do
      before do
        @build.update_attributes(artifacts_file: artifacts_file)
112
        visit namespace_project_build_path(@project.namespace, @project, @build)
113 114
      end

115
      it 'has button to download artifacts' do
Phil Hughes committed
116
        expect(page).to have_content 'Download'
117
      end
118
    end
119

120 121 122 123 124 125 126 127 128
    context 'Artifacts expire date' do
      before do
        @build.update_attributes(artifacts_file: artifacts_file, artifacts_expire_at: expire_at)
        visit namespace_project_build_path(@project.namespace, @project, @build)
      end

      context 'no expire date defined' do
        let(:expire_at) { nil }

129
        it 'does not have the Keep button' do
Kamil Trzcinski committed
130
          expect(page).not_to have_content 'Keep'
131 132 133 134 135 136
        end
      end

      context 'when expire date is defined' do
        let(:expire_at) { Time.now + 7.days }

137
        it 'keeps artifacts when Keep button is clicked' do
Kamil Trzcinski committed
138 139
          expect(page).to have_content 'The artifacts will be removed'
          click_link 'Keep'
140 141 142 143 144 145 146 147 148

          expect(page).not_to have_link 'Keep'
          expect(page).not_to have_content 'The artifacts will be removed'
        end
      end

      context 'when artifacts expired' do
        let(:expire_at) { Time.now - 7.days }

149
        it 'does not have the Keep button' do
Kamil Trzcinski committed
150 151
          expect(page).to have_content 'The artifacts were removed'
          expect(page).not_to have_link 'Keep'
152 153 154 155
        end
      end
    end

156 157 158 159 160 161 162 163
    context 'Build raw trace' do
      before do
        @build.run!
        @build.trace = 'BUILD TRACE'
        visit namespace_project_build_path(@project.namespace, @project, @build)
      end

      it do
Phil Hughes committed
164
        expect(page).to have_link 'Raw'
165 166
      end
    end
167
  end
168

Kamil Trzcinski committed
169
  describe "POST /:project/builds/:id/cancel" do
170 171 172 173 174 175 176 177 178 179
    context "Build from project" do
      before do
        @build.run!
        visit namespace_project_build_path(@project.namespace, @project, @build)
        click_link "Cancel"
      end

      it { expect(page.status_code).to eq(200) }
      it { expect(page).to have_content 'canceled' }
      it { expect(page).to have_content 'Retry' }
180 181
    end

182 183 184 185 186 187 188 189 190
    context "Build from other project" do
      before do
        @build.run!
        visit namespace_project_build_path(@project.namespace, @project, @build)
        page.driver.post(cancel_namespace_project_build_path(@project.namespace, @project, @build2))
      end

      it { expect(page.status_code).to eq(404) }
    end
191 192 193
  end

  describe "POST /:project/builds/:id/retry" do
194 195 196 197 198 199 200 201 202 203 204
    context "Build from project" do
      before do
        @build.run!
        visit namespace_project_build_path(@project.namespace, @project, @build)
        click_link 'Cancel'
        click_link 'Retry'
      end

      it { expect(page.status_code).to eq(200) }
      it { expect(page).to have_content 'pending' }
      it { expect(page).to have_content 'Cancel' }
205 206
    end

207 208 209 210 211 212 213 214 215 216
    context "Build from other project" do
      before do
        @build.run!
        visit namespace_project_build_path(@project.namespace, @project, @build)
        click_link 'Cancel'
        page.driver.post(retry_namespace_project_build_path(@project.namespace, @project, @build2))
      end

      it { expect(page.status_code).to eq(404) }
    end
217
  end
218 219

  describe "GET /:project/builds/:id/download" do
Phil Hughes committed
220 221 222 223
    before do
      @build.update_attributes(artifacts_file: artifacts_file)
      visit namespace_project_build_path(@project.namespace, @project, @build)
      click_link 'Download'
224 225
    end

226 227 228 229 230 231 232 233
    context "Build from other project" do
      before do
        @build2.update_attributes(artifacts_file: artifacts_file)
        visit download_namespace_project_build_artifacts_path(@project.namespace, @project, @build2)
      end

      it { expect(page.status_code).to eq(404) }
    end
234
  end
235 236

  describe "GET /:project/builds/:id/raw" do
237 238 239 240 241 242
    context "Build from project" do
      before do
        Capybara.current_session.driver.header('X-Sendfile-Type', 'X-Sendfile')
        @build.run!
        @build.trace = 'BUILD TRACE'
        visit namespace_project_build_path(@project.namespace, @project, @build)
Phil Hughes committed
243
        page.within('.js-build-sidebar') { click_link 'Raw' }
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
      end

      it 'sends the right headers' do
        expect(page.status_code).to eq(200)
        expect(page.response_headers['Content-Type']).to eq('text/plain; charset=utf-8')
        expect(page.response_headers['X-Sendfile']).to eq(@build.path_to_trace)
      end
    end

    context "Build from other project" do
      before do
        Capybara.current_session.driver.header('X-Sendfile-Type', 'X-Sendfile')
        @build2.run!
        @build2.trace = 'BUILD TRACE'
        visit raw_namespace_project_build_path(@project.namespace, @project, @build2)
        puts page.status_code
        puts current_url
      end

      it 'sends the right headers' do
        expect(page.status_code).to eq(404)
      end
    end
  end

  describe "GET /:project/builds/:id/trace.json" do
    context "Build from project" do
      before do
        visit trace_namespace_project_build_path(@project.namespace, @project, @build, format: :json)
      end

      it { expect(page.status_code).to eq(200) }
    end

    context "Build from other project" do
      before do
        visit trace_namespace_project_build_path(@project.namespace, @project, @build2, format: :json)
      end

      it { expect(page.status_code).to eq(404) }
    end
  end

  describe "GET /:project/builds/:id/status" do
    context "Build from project" do
      before do
        visit status_namespace_project_build_path(@project.namespace, @project, @build)
      end

      it { expect(page.status_code).to eq(200) }
294 295
    end

Phil Hughes committed
296 297 298 299
    context "Build from other project" do
      before do
        visit status_namespace_project_build_path(@project.namespace, @project, @build2)
      end
300

301
      it { expect(page.status_code).to eq(404) }
302
    end
303
  end
304
end