diff options
author | Dongqing Hu <sorra@outlook.com> | 2017-01-25 05:44:05 +0300 |
---|---|---|
committer | Dongqing Hu <sorra@outlook.com> | 2017-01-25 05:44:05 +0300 |
commit | 821ab7cf7dc45932167986005013044e346c8823 (patch) | |
tree | 15787c9d0d7b6c83ca92eeb71ed146b4d0ca91e6 /spec/helpers/merge_requests_helper_spec.rb | |
parent | da81add825b0b7b4a3b4351f67fbab25a947922c (diff) |
tests for #mr_closes_issues and #mr_issues_mentioned_but_not_closing in MergeRequestsHelper
Diffstat (limited to 'spec/helpers/merge_requests_helper_spec.rb')
-rw-r--r-- | spec/helpers/merge_requests_helper_spec.rb | 82 |
1 files changed, 82 insertions, 0 deletions
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 |