Commit 821ab7cf authored by Dongqing Hu's avatar Dongqing Hu

tests for #mr_closes_issues and #mr_issues_mentioned_but_not_closing in MergeRequestsHelper

parent da81add8
---
title: pass in current_user in MergeRequest and MergeRequestsHelper
merge_request: 8624
author: Dongqing Hu
...@@ -77,4 +77,86 @@ describe MergeRequestsHelper do ...@@ -77,4 +77,86 @@ describe MergeRequestsHelper do
expect(mr_widget_refresh_url(nil)).to end_with('') expect(mr_widget_refresh_url(nil)).to end_with('')
end end
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 end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment