Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-02-26 15:32:42 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2018-03-07 17:12:31 +0300
commitb2ef83856de8c175d384688d09023d16dcfef0c6 (patch)
tree01802b6678de41951dbd035a25219e77d6b48cf7 /spec/models/project_spec.rb
parent792ab0631c85098fbf92e727b77158fb9dae5219 (diff)
Allow abilities on forks while MR is open
When an MR is created using `allow_maintainer_to_push`, we enable some abilities while the MR is open. This should allow every user with developer abilities on the target project, to push to the source project.
Diffstat (limited to 'spec/models/project_spec.rb')
-rw-r--r--spec/models/project_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index b1c9e6754b9..a95a4637234 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe Project do
+ include ProjectForksHelper
+
describe 'associations' do
it { is_expected.to belong_to(:group) }
it { is_expected.to belong_to(:namespace) }
@@ -3378,4 +3380,54 @@ describe Project do
end
end
end
+
+ describe '#branches_allowing_maintainer_access_to_user' do
+ let(:maintainer) { create(:user) }
+ let(:target_project) { create(:project) }
+ let(:project) { fork_project(target_project) }
+ let!(:merge_request) do
+ create(
+ :merge_request,
+ target_project: target_project,
+ source_project: project,
+ source_branch: 'awesome-feature-1',
+ allow_maintainer_to_push: true
+ )
+ end
+
+ before do
+ target_project.add_developer(maintainer)
+ end
+
+ it 'includes branch names for merge requests allowing maintainer access to a user' do
+ expect(project.branches_allowing_maintainer_access_to_user(maintainer))
+ .to include('awesome-feature-1')
+ end
+
+ it 'does not include branches for closed MRs' do
+ create(:merge_request, :closed,
+ target_project: target_project,
+ source_project: project,
+ source_branch: 'rejected-feature-1',
+ allow_maintainer_to_push: true)
+
+ expect(project.branches_allowing_maintainer_access_to_user(maintainer))
+ .not_to include('rejected-feature-1')
+ end
+
+ it 'only queries once per user' do
+ expect { 3.times { project.branches_allowing_maintainer_access_to_user(maintainer) } }
+ .not_to exceed_query_limit(1)
+ end
+
+ context 'when the requeststore is active', :request_store do
+ it 'only queries once per user accross project instances' do
+ # limiting to 3 queries:
+ # 2 times loading the project
+ # once loading the accessible branches
+ expect { 2.times { described_class.find(project.id).branches_allowing_maintainer_access_to_user(maintainer) } }
+ .not_to exceed_query_limit(3)
+ end
+ end
+ end
end