diff options
author | Robert Speicher <rspeicher@gmail.com> | 2018-11-23 17:49:52 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2018-11-26 11:19:15 -0600 |
commit | c0fcf120b79ea90b60980a77b4b2e16c6653f450 (patch) | |
tree | 8efd67e03f4ea5ae2d653b13a90bf79c7018610a /spec/views/layouts | |
parent | 242baf1287302bded45164558986150ac8d9881f (diff) | |
download | gitlab-ce-c0fcf120b79ea90b60980a77b4b2e16c6653f450.tar.gz |
Convert "New menu" feature spec to a view spec
A feature spec to test this simple behavior takes about 2 minutes to run
in CI. Everything it's testing is conditionals and `href` attributes,
which can easily be done in a view spec that runs in about 8 seconds.
Diffstat (limited to 'spec/views/layouts')
-rw-r--r-- | spec/views/layouts/header/_new_dropdown.haml_spec.rb | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/spec/views/layouts/header/_new_dropdown.haml_spec.rb b/spec/views/layouts/header/_new_dropdown.haml_spec.rb new file mode 100644 index 00000000000..2e19d0cec26 --- /dev/null +++ b/spec/views/layouts/header/_new_dropdown.haml_spec.rb @@ -0,0 +1,134 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'layouts/header/_new_dropdown' do + let(:user) { create(:user) } + + context 'group-specific links' do + let(:group) { create(:group) } + + before do + stub_current_user(user) + + assign(:group, group) + end + + context 'as a Group owner' do + before do + group.add_owner(user) + end + + it 'has a "New project" link' do + render + + expect(rendered).to have_link( + 'New project', + href: new_project_path(namespace_id: group.id) + ) + end + + it 'has a "New subgroup" link', :nested_groups do + render + + expect(rendered).to have_link( + 'New subgroup', + href: new_group_path(parent_id: group.id) + ) + end + end + end + + context 'project-specific links' do + let(:project) { create(:project, creator: user, namespace: user.namespace) } + + before do + assign(:project, project) + end + + context 'as a Project owner' do + before do + stub_current_user(user) + end + + it 'has a "New issue" link' do + render + + expect(rendered).to have_link( + 'New issue', + href: new_project_issue_path(project) + ) + end + + it 'has a "New merge request" link' do + render + + expect(rendered).to have_link( + 'New merge request', + href: project_new_merge_request_path(project) + ) + end + + it 'has a "New snippet" link' do + render + + expect(rendered).to have_link( + 'New snippet', + href: new_project_snippet_path(project) + ) + end + end + + context 'as a Project guest' do + let(:guest) { create(:user) } + + before do + stub_current_user(guest) + project.add_guest(guest) + end + + it 'has no "New merge request" link' do + render + + expect(rendered).not_to have_link('New merge request') + end + + it 'has no "New snippet" link' do + render + + expect(rendered).not_to have_link( + 'New snippet', + href: new_project_snippet_path(project) + ) + end + end + end + + context 'global links' do + before do + stub_current_user(user) + end + + it 'has a "New project" link' do + render + + expect(rendered).to have_link('New project', href: new_project_path) + end + + it 'has a "New group" link' do + render + + expect(rendered).to have_link('New group', href: new_group_path) + end + + it 'has a "New snippet" link' do + render + + expect(rendered).to have_link('New snippet', href: new_snippet_path) + end + end + + def stub_current_user(current_user) + allow(view).to receive(:current_user).and_return(current_user) + end +end |