Extract EE specific files/lines for spec/features/protected_*

We have the following files containing EE specific code. We should move them to ee/

spec/features/protected_branches_spec.rb
diff --git a/spec/features/protected_branches_spec.rb b/home/yorickpeterse/Projects/gitlab/gdk-ee/gitlab/spec/features/protected_branches_spec.rb
index 0aff916ec83..4c68c6620be 100644
--- a/spec/features/protected_branches_spec.rb
+++ b/home/yorickpeterse/Projects/gitlab/gdk-ee/gitlab/spec/features/protected_branches_spec.rb
@@ -1,6 +1,8 @@
 require 'spec_helper'
 
 describe 'Protected Branches', :js do
+  include EE::ProtectedBranchHelpers
+
   let(:user) { create(:user) }
   let(:admin) { create(:admin) }
   let(:project) { create(:project, :repository) }
@@ -70,8 +72,9 @@ describe 'Protected Branches', :js do
     describe "explicit protected branches" do
       it "allows creating explicit protected branches" do
         visit project_protected_branches_path(project)
-        set_defaults
         set_protected_branch_name('some-branch')
+        set_allowed_to('merge')
+        set_allowed_to('push')
         click_on "Protect"
 
         within(".protected-branches-list") { expect(page).to have_content('some-branch') }
@@ -84,8 +87,9 @@ describe 'Protected Branches', :js do
         project.repository.add_branch(admin, 'some-branch', commit.id)
 
         visit project_protected_branches_path(project)
-        set_defaults
         set_protected_branch_name('some-branch')
+        set_allowed_to('merge')
+        set_allowed_to('push')
         click_on "Protect"
 
         within(".protected-branches-list") { expect(page).to have_content(commit.id[0..7]) }
@@ -93,8 +97,9 @@ describe 'Protected Branches', :js do
 
       it "displays an error message if the named branch does not exist" do
         visit project_protected_branches_path(project)
-        set_defaults
         set_protected_branch_name('some-branch')
+        set_allowed_to('merge')
+        set_allowed_to('push')
         click_on "Protect"
 
         within(".protected-branches-list") { expect(page).to have_content('branch was deleted') }
@@ -104,8 +109,9 @@ describe 'Protected Branches', :js do
     describe "wildcard protected branches" do
       it "allows creating protected branches with a wildcard" do
         visit project_protected_branches_path(project)
-        set_defaults
         set_protected_branch_name('*-stable')
+        set_allowed_to('merge')
+        set_allowed_to('push')
         click_on "Protect"
 
         within(".protected-branches-list") { expect(page).to have_content('*-stable') }
@@ -118,8 +124,9 @@ describe 'Protected Branches', :js do
         project.repository.add_branch(admin, 'staging-stable', 'master')
 
         visit project_protected_branches_path(project)
-        set_defaults
         set_protected_branch_name('*-stable')
+        set_allowed_to('merge')
+        set_allowed_to('push')
         click_on "Protect"
 
         within(".protected-branches-list") do
@@ -135,7 +142,8 @@ describe 'Protected Branches', :js do
 
         visit project_protected_branches_path(project)
         set_protected_branch_name('*-stable')
-        set_defaults
+        set_allowed_to('merge')
+        set_allowed_to('push')
         click_on "Protect"
 
         visit project_protected_branches_path(project)
@@ -150,7 +158,68 @@ describe 'Protected Branches', :js do
     end
 
     describe "access control" do
-      include_examples "protected branches > access control > CE"
+      describe 'with ref permissions for users enabled' do
+        before do
+          stub_licensed_features(protected_refs_for_users: true)
+        end
+
+        include_examples "protected branches > access control > EE"
+      end
+
+      describe 'with ref permissions for users disabled' do
+        before do
+          stub_licensed_features(protected_refs_for_users: false)
+        end
+
+        include_examples "protected branches > access control > CE"
+
+        context 'with existing access levels' do
+          let(:protected_branch) { create(:protected_branch, project: project) }
+
+          it 'shows users that can push to the branch' do
+            protected_branch.push_access_levels.new(user: create(:user, name: 'Jane'))
+              .save!(validate: false)
+
+            visit project_settings_repository_path(project)
+
+            expect(page).to have_content("The following user can also push to this branch: "\
+                                         "Jane")
+          end
+
+          it 'shows groups that can push to the branch' do
+            protected_branch.push_access_levels.new(group: create(:group, name: 'Team Awesome'))
+              .save!(validate: false)
+
+            visit project_settings_repository_path(project)
+
+            expect(page).to have_content("Members of this group can also push to "\
+                                         "this branch: Team Awesome")
+          end
+
+          it 'shows users that can merge into the branch' do
+            protected_branch.merge_access_levels.new(user: create(:user, name: 'Jane'))
+              .save!(validate: false)
+
+            visit project_settings_repository_path(project)
+
+            expect(page).to have_content("The following user can also merge into "\
+                                         "this branch: Jane")
+          end
+
+          it 'shows groups that have can push to the branch' do
+            protected_branch.merge_access_levels.new(group: create(:group, name: 'Team Awesome'))
+              .save!(validate: false)
+            protected_branch.merge_access_levels.new(group: create(:group, name: 'Team B'))
+              .save!(validate: false)
+
+            visit project_settings_repository_path(project)
+
+            expect(page).to have_content("Members of these groups can also merge into "\
+                                         "this branch:")
+            expect(page).to have_content(/(Team Awesome|Team B) and (Team Awesome|Team B)/)
+          end
+        end
+      end
     end
   end
 
@@ -159,18 +228,4 @@ describe 'Protected Branches', :js do
     find(".dropdown-input-field").set(branch_name)
     click_on("Create wildcard #{branch_name}")
   end
-
-  def set_defaults
-    find(".js-allowed-to-merge").click
-    within('.qa-allowed-to-merge-dropdown') do
-      expect(first("li")).to have_content("Roles")
-      find(:link, 'No one').click
-    end
-
-    find(".js-allowed-to-push").click
-    within('.qa-allowed-to-push-dropdown') do
-      expect(first("li")).to have_content("Roles")
-      find(:link, 'No one').click
-    end
-  end
 end
spec/features/protected_tags_spec.rb
diff --git a/spec/features/protected_tags_spec.rb b/home/yorickpeterse/Projects/gitlab/gdk-ee/gitlab/spec/features/protected_tags_spec.rb
index c8e92cd1c07..fd29c193566 100644
--- a/spec/features/protected_tags_spec.rb
+++ b/home/yorickpeterse/Projects/gitlab/gdk-ee/gitlab/spec/features/protected_tags_spec.rb
@@ -8,6 +8,19 @@ describe 'Protected Tags', :js do
     sign_in(user)
   end
 
+  def set_allowed_to(operation, option = 'Maintainers', form: '.new-protected-tag')
+    within form do
+      find(".js-allowed-to-#{operation}").click
+      wait_for_requests
+
+      within('.dropdown-content') do
+        Array(option).each { |opt| click_on(opt) }
+      end
+
+      find(".js-allowed-to-#{operation}").click # needed to submit form in some cases
+    end
+  end
+
   def set_protected_tag_name(tag_name)
     find(".js-protected-tag-select").click
     find(".dropdown-input-field").set(tag_name)
@@ -19,6 +32,7 @@ describe 'Protected Tags', :js do
     it "allows creating explicit protected tags" do
       visit project_protected_tags_path(project)
       set_protected_tag_name('some-tag')
+      set_allowed_to('create')
       click_on "Protect"
 
       within(".protected-tags-list") { expect(page).to have_content('some-tag') }
@@ -32,6 +46,7 @@ describe 'Protected Tags', :js do
 
       visit project_protected_tags_path(project)
       set_protected_tag_name('some-tag')
+      set_allowed_to('create')
       click_on "Protect"
 
       within(".protected-tags-list") { expect(page).to have_content(commit.id[0..7]) }
@@ -40,6 +55,7 @@ describe 'Protected Tags', :js do
     it "displays an error message if the named tag does not exist" do
       visit project_protected_tags_path(project)
       set_protected_tag_name('some-tag')
+      set_allowed_to('create')
       click_on "Protect"
 
       within(".protected-tags-list") { expect(page).to have_content('tag was removed') }
@@ -50,6 +66,7 @@ describe 'Protected Tags', :js do
     it "allows creating protected tags with a wildcard" do
       visit project_protected_tags_path(project)
       set_protected_tag_name('*-stable')
+      set_allowed_to('create')
       click_on "Protect"
 
       within(".protected-tags-list") { expect(page).to have_content('*-stable') }
@@ -63,6 +80,7 @@ describe 'Protected Tags', :js do
 
       visit project_protected_tags_path(project)
       set_protected_tag_name('*-stable')
+      set_allowed_to('create')
       click_on "Protect"
 
       within(".protected-tags-list") do
@@ -78,6 +96,7 @@ describe 'Protected Tags', :js do
 
       visit project_protected_tags_path(project)
       set_protected_tag_name('*-stable')
+      set_allowed_to('create')
       click_on "Protect"
 
       visit project_protected_tags_path(project)
@@ -92,6 +111,44 @@ describe 'Protected Tags', :js do
   end
 
   describe "access control" do
-    include_examples "protected tags > access control > CE"
+    describe 'with ref permissions for users enabled' do
+      before do
+        stub_licensed_features(protected_refs_for_users: true)
+      end
+
+      include_examples "protected tags > access control > EE"
+    end
+
+    describe 'with ref permissions for users disabled' do
+      before do
+        stub_licensed_features(protected_refs_for_users: false)
+      end
+
+      include_examples "protected tags > access control > CE"
+
+      describe 'with existing access levels' do
+        let(:protected_tag) { create(:protected_tag, project: project) }
+
+        it 'shows users that can push to the branch' do
+          protected_tag.create_access_levels.new(user: create(:user, name: 'Jane'))
+            .save!(validate: false)
+
+          visit project_settings_repository_path(project)
+
+          expect(page).to have_content("The following user can also create tags: "\
+                                       "Jane")
+        end
+
+        it 'shows groups that can create to the branch' do
+          protected_tag.create_access_levels.new(group: create(:group, name: 'Team Awesome'))
+            .save!(validate: false)
+
+          visit project_settings_repository_path(project)
+
+          expect(page).to have_content("Members of this group can also create tags: "\
+                                       "Team Awesome")
+        end
+      end
+    end
   end
 end
Edited Feb 26, 2019 by Yorick Peterse
Assignee Loading
Time tracking Loading