diff options
author | Dongqing Hu <sorra@outlook.com> | 2017-01-25 10:44:05 +0800 |
---|---|---|
committer | Dongqing Hu <sorra@outlook.com> | 2017-01-25 10:44:05 +0800 |
commit | 821ab7cf7dc45932167986005013044e346c8823 (patch) | |
tree | 15787c9d0d7b6c83ca92eeb71ed146b4d0ca91e6 | |
parent | da81add825b0b7b4a3b4351f67fbab25a947922c (diff) | |
download | gitlab-ce-821ab7cf7dc45932167986005013044e346c8823.tar.gz |
tests for #mr_closes_issues and #mr_issues_mentioned_but_not_closing in MergeRequestsHelper
-rw-r--r-- | changelogs/unreleased/pass in current_user in MergeRequest and MergeRequestsHelper.yml | 4 | ||||
-rw-r--r-- | spec/helpers/merge_requests_helper_spec.rb | 82 |
2 files changed, 86 insertions, 0 deletions
diff --git a/changelogs/unreleased/pass in current_user in MergeRequest and MergeRequestsHelper.yml b/changelogs/unreleased/pass in current_user in MergeRequest and MergeRequestsHelper.yml new file mode 100644 index 00000000000..0751047c3c0 --- /dev/null +++ b/changelogs/unreleased/pass in current_user in MergeRequest and MergeRequestsHelper.yml @@ -0,0 +1,4 @@ +--- +title: pass in current_user in MergeRequest and MergeRequestsHelper +merge_request: 8624 +author: Dongqing Hu diff --git a/spec/helpers/merge_requests_helper_spec.rb b/spec/helpers/merge_requests_helper_spec.rb index 1f221487393..408ee93f7df 100644 --- a/spec/helpers/merge_requests_helper_spec.rb +++ b/spec/helpers/merge_requests_helper_spec.rb @@ -77,4 +77,86 @@ describe MergeRequestsHelper do expect(mr_widget_refresh_url(nil)).to end_with('') end end + + describe '#mr_closes_issues' do + let(:user_1) { create(:user) } + let(:user_2) { create(:user) } + + let(:project_1) { create(:project, :private, creator: user_1, namespace: user_1.namespace) } + let(:project_2) { create(:project, :private, creator: user_2, namespace: user_2.namespace) } + + let(:issue_1) { create(:issue, project: project_1) } + let(:issue_2) { create(:issue, project: project_2) } + + let(:merge_request) { create(:merge_request, source_project: project_1, target_project: project_1,) } + + let(:merge_request) do + create(:merge_request, + source_project: project_1, target_project: project_1, + description: "Fixes #{issue_1.to_reference} Fixes #{issue_2.to_reference(project_1)}") + end + + before do + project_1.team << [user_2, :developer] + project_2.team << [user_2, :developer] + allow(merge_request.project).to receive(:default_branch).and_return(merge_request.target_branch) + @merge_request = merge_request + end + + context 'user without access to another private project' do + let(:current_user) { user_1 } + + it 'cannot see that project\'s issue that will be closed on acceptance' do + expect(mr_closes_issues).to contain_exactly(issue_1) + end + end + + context 'user with access to another private project' do + let(:current_user) { user_2 } + + it 'can see that project\'s issue that will be closed on acceptance' do + expect(mr_closes_issues).to contain_exactly(issue_1, issue_2) + end + end + end + + describe '#mr_issues_mentioned_but_not_closing' do + let(:user_1) { create(:user) } + let(:user_2) { create(:user) } + + let(:project_1) { create(:project, :private, creator: user_1, namespace: user_1.namespace) } + let(:project_2) { create(:project, :private, creator: user_2, namespace: user_2.namespace) } + + let(:issue_1) { create(:issue, project: project_1) } + let(:issue_2) { create(:issue, project: project_2) } + + let(:merge_request) do + create(:merge_request, + source_project: project_1, target_project: project_1, + description: "#{issue_1.to_reference} #{issue_2.to_reference(project_1)}") + end + + before do + project_1.team << [user_2, :developer] + project_2.team << [user_2, :developer] + allow(merge_request.project).to receive(:default_branch).and_return(merge_request.target_branch) + @merge_request = merge_request + end + + context 'user without access to another private project' do + let(:current_user) { user_1 } + + it 'cannot see that project\'s issue that will be closed on acceptance' do + expect(mr_issues_mentioned_but_not_closing).to contain_exactly(issue_1) + end + end + + context 'user with access to another private project' do + let(:current_user) { user_2 } + + it 'can see that project\'s issue that will be closed on acceptance' do + expect(mr_issues_mentioned_but_not_closing).to contain_exactly(issue_1, issue_2) + end + end + end end |