diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-03 00:06:28 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-03 00:06:28 +0000 |
commit | 10d0e5693c0eed9fd9c40f4fadeda187237db6b5 (patch) | |
tree | 82a723f14e4a44146c7c5e2259b9c7d6d9b834bb /spec/helpers | |
parent | a19a376bf35b2009566e86b8190662c21ed7e2ba (diff) | |
download | gitlab-ce-10d0e5693c0eed9fd9c40f4fadeda187237db6b5.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/application_helper_spec.rb | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index d3d25d3cb74..a0c85863150 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -235,4 +235,88 @@ describe ApplicationHelper do end end end + + describe '#body_data' do + context 'when @project is not set' do + it 'does not include project data in the body data elements' do + expect(helper.body_data).to eq( + { + page: 'application', + page_type_id: nil, + find_file: nil, + group: '' + } + ) + end + + context 'when @group is set' do + it 'sets group in the body data elements' do + group = create(:group) + + assign(:group, group) + + expect(helper.body_data).to eq( + { + page: 'application', + page_type_id: nil, + find_file: nil, + group: group.path + } + ) + end + end + 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) + + assign(:project, project) + + expect(helper.body_data).to eq( + { + page: 'application', + page_type_id: nil, + find_file: nil, + group: '', + project_id: project.id, + project: project.name, + namespace_id: project.namespace.id + } + ) + end + + context 'when controller is issues' do + before do + stub_controller_method(:controller_path, 'projects:issues') + end + + 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) + stub_controller_method(:action_name, 'show') + stub_controller_method(:params, { id: issue.id }) + + assign(:project, issue.project) + + expect(helper.body_data).to eq( + { + page: 'projects:issues:show', + page_type_id: issue.id, + find_file: nil, + group: '', + project_id: issue.project.id, + project: issue.project.name, + namespace_id: issue.project.namespace.id + } + ) + end + end + end + end + + def stub_controller_method(method_name, value) + allow(helper.controller).to receive(method_name).and_return(value) + end + end end |