protected_tags_spec.rb 3.11 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Protected Tags', :js do
4
  let(:user) { create(:user, :admin) }
5
  let(:project) { create(:project, :repository) }
6

7
  before do
8
    sign_in(user)
9
  end
10 11 12 13 14

  def set_protected_tag_name(tag_name)
    find(".js-protected-tag-select").click
    find(".dropdown-input-field").set(tag_name)
    click_on("Create wildcard #{tag_name}")
15
    find('.protected-tags-dropdown .dropdown-menu', visible: false)
16 17 18 19
  end

  describe "explicit protected tags" do
    it "allows creating explicit protected tags" do
20
      visit project_protected_tags_path(project)
21 22 23 24 25 26 27 28 29 30 31 32
      set_protected_tag_name('some-tag')
      click_on "Protect"

      within(".protected-tags-list") { expect(page).to have_content('some-tag') }
      expect(ProtectedTag.count).to eq(1)
      expect(ProtectedTag.last.name).to eq('some-tag')
    end

    it "displays the last commit on the matching tag if it exists" do
      commit = create(:commit, project: project)
      project.repository.add_tag(user, 'some-tag', commit.id)

33
      visit project_protected_tags_path(project)
34 35 36 37 38 39 40
      set_protected_tag_name('some-tag')
      click_on "Protect"

      within(".protected-tags-list") { expect(page).to have_content(commit.id[0..7]) }
    end

    it "displays an error message if the named tag does not exist" do
41
      visit project_protected_tags_path(project)
42 43 44 45 46 47 48 49 50
      set_protected_tag_name('some-tag')
      click_on "Protect"

      within(".protected-tags-list") { expect(page).to have_content('tag was removed') }
    end
  end

  describe "wildcard protected tags" do
    it "allows creating protected tags with a wildcard" do
51
      visit project_protected_tags_path(project)
52 53 54 55 56 57 58 59 60 61 62 63
      set_protected_tag_name('*-stable')
      click_on "Protect"

      within(".protected-tags-list") { expect(page).to have_content('*-stable') }
      expect(ProtectedTag.count).to eq(1)
      expect(ProtectedTag.last.name).to eq('*-stable')
    end

    it "displays the number of matching tags" do
      project.repository.add_tag(user, 'production-stable', 'master')
      project.repository.add_tag(user, 'staging-stable', 'master')

64
      visit project_protected_tags_path(project)
65 66 67
      set_protected_tag_name('*-stable')
      click_on "Protect"

68 69 70 71
      within(".protected-tags-list") do
        expect(page).to have_content("Protected tag (2)")
        expect(page).to have_content("2 matching tags")
      end
72 73 74 75 76 77 78
    end

    it "displays all the tags matching the wildcard" do
      project.repository.add_tag(user, 'production-stable', 'master')
      project.repository.add_tag(user, 'staging-stable', 'master')
      project.repository.add_tag(user, 'development', 'master')

79
      visit project_protected_tags_path(project)
80 81 82
      set_protected_tag_name('*-stable')
      click_on "Protect"

83
      visit project_protected_tags_path(project)
84 85 86 87 88 89 90 91 92 93 94 95 96 97
      click_on "2 matching tags"

      within(".protected-tags-list") do
        expect(page).to have_content("production-stable")
        expect(page).to have_content("staging-stable")
        expect(page).not_to have_content("development")
      end
    end
  end

  describe "access control" do
    include_examples "protected tags > access control > CE"
  end
end