diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-01 00:09:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-01 00:09:47 +0300 |
commit | 3aeda4e6146bea1920c3283e98b01ca4fcf796a8 (patch) | |
tree | b44e6298a749bd8a02283bc5867ab4a3269b62c3 /spec/helpers | |
parent | adafb996ef88da50b30c737cdb8caee8307ec6d6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/application_helper_spec.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index e7d2a027640..d679768be6c 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -280,11 +280,16 @@ describe ApplicationHelper do end context 'when @project is set' do - it 'includes all possible body data elements and associates the project elements with project' do - project = create(:project) + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + before do assign(:project, project) + allow(helper).to receive(:current_user).and_return(nil) + end + it 'includes all possible body data elements and associates the project elements with project' do + expect(helper).to receive(:can?).with(nil, :download_code, project) expect(helper.body_data).to eq( { page: 'application', @@ -305,12 +310,11 @@ describe ApplicationHelper do context 'when params[:id] is present and the issue exsits and action_name is show' do it 'sets all project and id elements correctly related to the issue' do - issue = create(:issue) + issue = create(:issue, project: project) stub_controller_method(:action_name, 'show') stub_controller_method(:params, { id: issue.id }) - assign(:project, issue.project) - + expect(helper).to receive(:can?).with(nil, :download_code, project).and_return(false) expect(helper.body_data).to eq( { page: 'projects:issues:show', @@ -325,6 +329,15 @@ describe ApplicationHelper do end end end + + context 'when current_user has download_code permission' do + it 'returns find_file with the default branch' do + allow(helper).to receive(:current_user).and_return(user) + + expect(helper).to receive(:can?).with(user, :download_code, project).and_return(true) + expect(helper.body_data[:find_file]).to end_with(project.default_branch) + end + end end def stub_controller_method(method_name, value) |