File: archive_download_buttons_shared_examples.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (67 lines) | stat: -rw-r--r-- 2,322 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true

RSpec.shared_examples 'archive download buttons' do
  let(:path_to_visit) { project_path(project) }
  let(:ref) { project.default_branch }

  context 'when static objects external storage is enabled' do
    before do
      allow_any_instance_of(ApplicationSetting).to receive(:static_objects_external_storage_url).and_return('https://cdn.gitlab.com')
      visit path_to_visit
    end

    context 'private project', :js do
      it 'shows archive download buttons with external storage URL prepended and user token appended to their href' do
        Gitlab::Workhorse::ARCHIVE_FORMATS.each do |format|
          path = archive_path(project, ref, format)
          uri = URI('https://cdn.gitlab.com')
          uri.path = path
          uri.query = "token=#{user.static_object_token}"

          all('[data-testid="download-source-code-button"]').first do
            find_by_testid('base-dropdown-toggle').click
            expect(page).to have_link format, href: uri.to_s
          end
        end
      end
    end

    context 'public project', :js do
      let(:project) { create(:project, :repository, :public) }

      it 'shows archive download buttons with external storage URL prepended to their href', :js do
        Gitlab::Workhorse::ARCHIVE_FORMATS.each do |format|
          path = archive_path(project, ref, format)
          uri = URI('https://cdn.gitlab.com')
          uri.path = path

          all('[data-testid="download-source-code-button"]').first do
            find_by_testid('base-dropdown-toggle').click
            expect(page).to have_link format, href: uri.to_s
          end
        end
      end
    end
  end

  context 'when static objects external storage is disabled', :js do
    before do
      visit path_to_visit
    end

    it 'shows default archive download buttons', :js do
      Gitlab::Workhorse::ARCHIVE_FORMATS.each do |format|
        path = archive_path(project, ref, format)

        all('[data-testid="download-source-code-button"]').first do
          find_by_testid('base-dropdown-toggle').click
          expect(page).to have_link format, href: path
        end
      end
    end
  end

  def archive_path(project, ref, format)
    project_archive_path(project, id: "#{ref}/#{project.path}-#{ref}", path: nil, format: format)
  end
end