1# frozen_string_literal: true 2 3require 'spec_helper' 4 5RSpec.describe 'Protected Tags', :js do 6 include ProtectedTagHelpers 7 8 let(:project) { create(:project, :repository) } 9 let(:user) { project.owner } 10 11 before do 12 sign_in(user) 13 end 14 15 describe "explicit protected tags" do 16 it "allows creating explicit protected tags" do 17 visit project_protected_tags_path(project) 18 set_protected_tag_name('some-tag') 19 set_allowed_to('create') if Gitlab.ee? 20 click_on "Protect" 21 22 within(".protected-tags-list") { expect(page).to have_content('some-tag') } 23 expect(ProtectedTag.count).to eq(1) 24 expect(ProtectedTag.last.name).to eq('some-tag') 25 end 26 27 it "displays the last commit on the matching tag if it exists" do 28 commit = create(:commit, project: project) 29 project.repository.add_tag(user, 'some-tag', commit.id) 30 31 visit project_protected_tags_path(project) 32 set_protected_tag_name('some-tag') 33 set_allowed_to('create') if Gitlab.ee? 34 click_on "Protect" 35 36 within(".protected-tags-list") { expect(page).to have_content(commit.id[0..7]) } 37 end 38 39 it "displays an error message if the named tag does not exist" do 40 visit project_protected_tags_path(project) 41 set_protected_tag_name('some-tag') 42 set_allowed_to('create') if Gitlab.ee? 43 click_on "Protect" 44 45 within(".protected-tags-list") { expect(page).to have_content('tag was removed') } 46 end 47 end 48 49 describe "wildcard protected tags" do 50 it "allows creating protected tags with a wildcard" do 51 visit project_protected_tags_path(project) 52 set_protected_tag_name('*-stable') 53 set_allowed_to('create') if Gitlab.ee? 54 click_on "Protect" 55 56 within(".protected-tags-list") { expect(page).to have_content('*-stable') } 57 expect(ProtectedTag.count).to eq(1) 58 expect(ProtectedTag.last.name).to eq('*-stable') 59 end 60 61 it "displays the number of matching tags" do 62 project.repository.add_tag(user, 'production-stable', 'master') 63 project.repository.add_tag(user, 'staging-stable', 'master') 64 65 visit project_protected_tags_path(project) 66 set_protected_tag_name('*-stable') 67 set_allowed_to('create') if Gitlab.ee? 68 click_on "Protect" 69 70 within(".protected-tags-list") do 71 expect(page).to have_content("Protected tags (2)") 72 expect(page).to have_content("2 matching tags") 73 end 74 end 75 76 it "displays all the tags matching the wildcard" do 77 project.repository.add_tag(user, 'production-stable', 'master') 78 project.repository.add_tag(user, 'staging-stable', 'master') 79 project.repository.add_tag(user, 'development', 'master') 80 81 visit project_protected_tags_path(project) 82 set_protected_tag_name('*-stable') 83 set_allowed_to('create') if Gitlab.ee? 84 click_on "Protect" 85 86 visit project_protected_tags_path(project) 87 click_on "2 matching tags" 88 89 within(".protected-tags-list") do 90 expect(page).to have_content("production-stable") 91 expect(page).to have_content("staging-stable") 92 expect(page).not_to have_content("development") 93 end 94 end 95 end 96 97 describe "access control" do 98 before do 99 stub_licensed_features(protected_refs_for_users: false) 100 end 101 102 include_examples "protected tags > access control > CE" 103 end 104end 105