diff options
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/auto_devops_helper_spec.rb | 6 | ||||
-rw-r--r-- | spec/helpers/dashboard_helper_spec.rb | 37 | ||||
-rw-r--r-- | spec/helpers/groups_helper_spec.rb | 6 | ||||
-rw-r--r-- | spec/helpers/issuables_helper_spec.rb | 41 | ||||
-rw-r--r-- | spec/helpers/labels_helper_spec.rb | 24 | ||||
-rw-r--r-- | spec/helpers/namespaces_helper_spec.rb | 4 | ||||
-rw-r--r-- | spec/helpers/submodule_helper_spec.rb | 94 | ||||
-rw-r--r-- | spec/helpers/wiki_helper_spec.rb | 2 |
8 files changed, 148 insertions, 66 deletions
diff --git a/spec/helpers/auto_devops_helper_spec.rb b/spec/helpers/auto_devops_helper_spec.rb index d2540696b17..e80388f9ea7 100644 --- a/spec/helpers/auto_devops_helper_spec.rb +++ b/spec/helpers/auto_devops_helper_spec.rb @@ -118,7 +118,7 @@ describe AutoDevopsHelper do it { is_expected.to eq('instance enabled') } end - context 'with groups', :nested_groups do + context 'with groups' do before do receiver.update(parent: parent) end @@ -170,7 +170,7 @@ describe AutoDevopsHelper do it { is_expected.to eq('instance enabled') } end - context 'with groups', :nested_groups do + context 'with groups' do let(:receiver) { create(:project, :repository, namespace: group) } before do @@ -203,7 +203,7 @@ describe AutoDevopsHelper do it { is_expected.to be_nil } end - context 'with groups', :nested_groups do + context 'with groups' do let(:receiver) { create(:project, :repository, namespace: group) } context 'when auto devops is disabled on group level' do diff --git a/spec/helpers/dashboard_helper_spec.rb b/spec/helpers/dashboard_helper_spec.rb index 023238ee0ae..49e23366355 100644 --- a/spec/helpers/dashboard_helper_spec.rb +++ b/spec/helpers/dashboard_helper_spec.rb @@ -22,6 +22,43 @@ describe DashboardHelper do end end + describe '#feature_entry' do + context 'when implicitly enabled' do + it 'considers feature enabled by default' do + entry = feature_entry('Demo', href: 'demo.link') + + expect(entry).to include('<p aria-label="Demo: status on">') + expect(entry).to include('<a href="demo.link">Demo</a>') + end + end + + context 'when explicitly enabled' do + it 'returns a link' do + entry = feature_entry('Demo', href: 'demo.link', enabled: true) + + expect(entry).to include('<p aria-label="Demo: status on">') + expect(entry).to include('<a href="demo.link">Demo</a>') + end + + it 'returns text if href is not provided' do + entry = feature_entry('Demo', enabled: true) + + expect(entry).to include('<p aria-label="Demo: status on">') + expect(entry).not_to match(/<a[^>]+>/) + end + end + + context 'when disabled' do + it 'returns text without link' do + entry = feature_entry('Demo', href: 'demo.link', enabled: false) + + expect(entry).to include('<p aria-label="Demo: status off">') + expect(entry).not_to match(/<a[^>]+>/) + expect(entry).to include('Demo') + end + end + end + describe '.has_start_trial?' do subject { helper.has_start_trial? } diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb index 1763c46389a..037b16c90ed 100644 --- a/spec/helpers/groups_helper_spec.rb +++ b/spec/helpers/groups_helper_spec.rb @@ -86,7 +86,7 @@ describe GroupsHelper do end end - describe 'group_title', :nested_groups do + describe 'group_title' do let(:group) { create(:group) } let(:nested_group) { create(:group, parent: group) } let(:deep_nested_group) { create(:group, parent: nested_group) } @@ -99,7 +99,7 @@ describe GroupsHelper do end # rubocop:disable Layout/SpaceBeforeComma - describe '#share_with_group_lock_help_text', :nested_groups do + describe '#share_with_group_lock_help_text' do let!(:root_group) { create(:group) } let!(:subgroup) { create(:group, parent: root_group) } let!(:sub_subgroup) { create(:group, parent: subgroup) } @@ -230,7 +230,7 @@ describe GroupsHelper do end end - describe 'parent_group_options', :nested_groups do + describe 'parent_group_options' do let(:current_user) { create(:user) } let(:group) { create(:group, name: 'group') } let(:group2) { create(:group, name: 'group2') } diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb index 1d1446eaa30..3c8179460ac 100644 --- a/spec/helpers/issuables_helper_spec.rb +++ b/spec/helpers/issuables_helper_spec.rb @@ -202,5 +202,46 @@ describe IssuablesHelper do } expect(helper.issuable_initial_data(issue)).to match(hash_including(expected_data)) end + + describe '#zoomMeetingUrl in issue' do + let(:issue) { create(:issue, author: user, description: description) } + + before do + assign(:project, issue.project) + end + + context 'no zoom links in the issue description' do + let(:description) { 'issue text' } + + it 'does not set zoomMeetingUrl' do + expect(helper.issuable_initial_data(issue)) + .not_to include(:zoomMeetingUrl) + end + end + + context 'no zoom links in the issue description if it has link but not a zoom link' do + let(:description) { 'issue text https://stackoverflow.com/questions/22' } + + it 'does not set zoomMeetingUrl' do + expect(helper.issuable_initial_data(issue)) + .not_to include(:zoomMeetingUrl) + end + end + + context 'with two zoom links in description' do + let(:description) do + <<~TEXT + issue text and + zoom call on https://zoom.us/j/123456789 this url + and new zoom url https://zoom.us/s/lastone and some more text + TEXT + end + + it 'sets zoomMeetingUrl value to the last url' do + expect(helper.issuable_initial_data(issue)) + .to include(zoomMeetingUrl: 'https://zoom.us/s/lastone') + end + end + end end end diff --git a/spec/helpers/labels_helper_spec.rb b/spec/helpers/labels_helper_spec.rb index 314305d7a8e..4f1cab38f34 100644 --- a/spec/helpers/labels_helper_spec.rb +++ b/spec/helpers/labels_helper_spec.rb @@ -3,10 +3,8 @@ require 'spec_helper' describe LabelsHelper do describe '#show_label_issuables_link?' do shared_examples 'a valid response to show_label_issuables_link?' do |issuables_type, when_enabled = true, when_disabled = false| - let(:context_project) { project } - context "when asking for a #{issuables_type} link" do - subject { show_label_issuables_link?(label.present(issuable_subject: nil), issuables_type, project: context_project) } + subject { show_label_issuables_link?(label.present(issuable_subject: nil), issuables_type) } context "when #{issuables_type} are enabled for the project" do let(:project) { create(:project, "#{issuables_type}_access_level": ProjectFeature::ENABLED) } @@ -39,27 +37,11 @@ describe LabelsHelper do let(:label) { create(:group_label, group: group, title: 'bug') } context 'when asking for an issue link' do - context 'in the context of a project' do - it_behaves_like 'a valid response to show_label_issuables_link?', :issues, true, true - end - - context 'in the context of a group' do - let(:context_project) { nil } - - it_behaves_like 'a valid response to show_label_issuables_link?', :issues, true, true - end + it_behaves_like 'a valid response to show_label_issuables_link?', :issues, true, true end context 'when asking for a merge requests link' do - context 'in the context of a project' do - it_behaves_like 'a valid response to show_label_issuables_link?', :merge_requests, true, true - end - - context 'in the context of a group' do - let(:context_project) { nil } - - it_behaves_like 'a valid response to show_label_issuables_link?', :merge_requests, true, true - end + it_behaves_like 'a valid response to show_label_issuables_link?', :merge_requests, true, true end end end diff --git a/spec/helpers/namespaces_helper_spec.rb b/spec/helpers/namespaces_helper_spec.rb index 601f864ef36..e38513f6d94 100644 --- a/spec/helpers/namespaces_helper_spec.rb +++ b/spec/helpers/namespaces_helper_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe NamespacesHelper, :postgresql do +describe NamespacesHelper do let!(:admin) { create(:admin) } let!(:admin_project_creation_level) { nil } let!(:admin_group) do @@ -109,7 +109,7 @@ describe NamespacesHelper, :postgresql do expect(options).to include(user_group.name) end - context 'when nested groups are available', :nested_groups do + context 'when nested groups are available' do it 'includes groups nested in groups the user can administer' do allow(helper).to receive(:current_user).and_return(user) child_group = create(:group, :private, parent: user_group) diff --git a/spec/helpers/submodule_helper_spec.rb b/spec/helpers/submodule_helper_spec.rb index ea48c69e0ae..ab4ef899119 100644 --- a/spec/helpers/submodule_helper_spec.rb +++ b/spec/helpers/submodule_helper_spec.rb @@ -3,15 +3,11 @@ require 'spec_helper' describe SubmoduleHelper do include RepoHelpers - describe 'submodule links' do - let(:submodule_item) { double(id: 'hash', path: 'rack') } - let(:config) { Gitlab.config.gitlab } - let(:repo) { double } - - before do - self.instance_variable_set(:@repository, repo) - end + let(:submodule_item) { double(id: 'hash', path: 'rack') } + let(:config) { Gitlab.config.gitlab } + let(:repo) { double } + shared_examples 'submodule_links' do context 'submodule on self' do before do allow(Gitlab.config.gitlab).to receive(:protocol).and_return('http') # set this just to be sure @@ -21,28 +17,28 @@ describe SubmoduleHelper do allow(Gitlab.config.gitlab_shell).to receive(:ssh_port).and_return(22) # set this just to be sure allow(Gitlab.config.gitlab_shell).to receive(:ssh_path_prefix).and_return(Settings.send(:build_gitlab_shell_ssh_path_prefix)) stub_url([config.user, '@', config.host, ':gitlab-org/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) + expect(subject).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) end it 'detects ssh on non-standard port' do allow(Gitlab.config.gitlab_shell).to receive(:ssh_port).and_return(2222) allow(Gitlab.config.gitlab_shell).to receive(:ssh_path_prefix).and_return(Settings.send(:build_gitlab_shell_ssh_path_prefix)) stub_url(['ssh://', config.user, '@', config.host, ':2222/gitlab-org/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) + expect(subject).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) end it 'detects http on standard port' do allow(Gitlab.config.gitlab).to receive(:port).and_return(80) allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url)) stub_url(['http://', config.host, '/gitlab-org/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) + expect(subject).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) end it 'detects http on non-standard port' do allow(Gitlab.config.gitlab).to receive(:port).and_return(3000) allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url)) stub_url(['http://', config.host, ':3000/gitlab-org/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) + expect(subject).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) end it 'works with relative_url_root' do @@ -50,7 +46,7 @@ describe SubmoduleHelper do allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root') allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url)) stub_url(['http://', config.host, '/gitlab/root/gitlab-org/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) + expect(subject).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')]) end it 'works with subgroups' do @@ -58,34 +54,34 @@ describe SubmoduleHelper do allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root') allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url)) stub_url(['http://', config.host, '/gitlab/root/gitlab-org/sub/gitlab-ce.git'].join('')) - expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org/sub', 'gitlab-ce'), namespace_project_tree_path('gitlab-org/sub', 'gitlab-ce', 'hash')]) + expect(subject).to eq([namespace_project_path('gitlab-org/sub', 'gitlab-ce'), namespace_project_tree_path('gitlab-org/sub', 'gitlab-ce', 'hash')]) end end context 'submodule on github.com' do it 'detects ssh' do stub_url('git@github.com:gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) + expect(subject).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) end it 'detects http' do stub_url('http://github.com/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) + expect(subject).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) end it 'detects https' do stub_url('https://github.com/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) + expect(subject).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) end it 'handles urls with no .git on the end' do stub_url('http://github.com/gitlab-org/gitlab-ce') - expect(submodule_links(submodule_item)).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) + expect(subject).to eq(['https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash']) end it 'returns original with non-standard url' do stub_url('http://github.com/another/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq([repo.submodule_url_for, nil]) + expect(subject).to eq([repo.submodule_url_for, nil]) end end @@ -97,39 +93,39 @@ describe SubmoduleHelper do allow(repo).to receive(:project).and_return(project) stub_url('./') - expect(submodule_links(submodule_item)).to eq(["/master-project/#{project.path}", "/master-project/#{project.path}/tree/hash"]) + expect(subject).to eq(["/master-project/#{project.path}", "/master-project/#{project.path}/tree/hash"]) end end context 'submodule on gitlab.com' do it 'detects ssh' do stub_url('git@gitlab.com:gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) + expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) end it 'detects http' do stub_url('http://gitlab.com/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) + expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) end it 'detects https' do stub_url('https://gitlab.com/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) + expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) end it 'handles urls with no .git on the end' do stub_url('http://gitlab.com/gitlab-org/gitlab-ce') - expect(submodule_links(submodule_item)).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) + expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) end it 'handles urls with trailing whitespace' do stub_url('http://gitlab.com/gitlab-org/gitlab-ce.git ') - expect(submodule_links(submodule_item)).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) + expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash']) end it 'returns original with non-standard url' do stub_url('http://gitlab.com/another/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq([repo.submodule_url_for, nil]) + expect(subject).to eq([repo.submodule_url_for, nil]) end end @@ -137,27 +133,25 @@ describe SubmoduleHelper do it 'sanitizes unsupported protocols' do stub_url('javascript:alert("XSS");') - expect(helper.submodule_links(submodule_item)).to eq([nil, nil]) + expect(subject).to eq([nil, nil]) end it 'sanitizes unsupported protocols disguised as a repository URL' do stub_url('javascript:alert("XSS");foo/bar.git') - expect(helper.submodule_links(submodule_item)).to eq([nil, nil]) + expect(subject).to eq([nil, nil]) end it 'sanitizes invalid URL with extended ASCII' do stub_url('é') - expect(helper.submodule_links(submodule_item)).to eq([nil, nil]) + expect(subject).to eq([nil, nil]) end it 'returns original' do stub_url('http://mygitserver.com/gitlab-org/gitlab-ce') - expect(submodule_links(submodule_item)).to eq([repo.submodule_url_for, nil]) - stub_url('http://mygitserver.com/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq([repo.submodule_url_for, nil]) + expect(subject).to eq([repo.submodule_url_for, nil]) end end @@ -168,8 +162,7 @@ describe SubmoduleHelper do def expect_relative_link_to_resolve_to(relative_path, expected_path) allow(repo).to receive(:submodule_url_for).and_return(relative_path) - - result = submodule_links(submodule_item) + result = subject expect(result).to eq([expected_path, "#{expected_path}/tree/#{submodule_item.id}"]) end @@ -190,7 +183,7 @@ describe SubmoduleHelper do it 'returns nil' do allow(repo).to receive(:submodule_url_for).and_return('../../test.git') - result = submodule_links(submodule_item) + result = subject expect(result).to eq([nil, nil]) end @@ -200,7 +193,7 @@ describe SubmoduleHelper do it 'returns nil because it is not possible to have repo nested under another repo' do allow(repo).to receive(:submodule_url_for).and_return('./test.git') - result = submodule_links(submodule_item) + result = subject expect(result).to eq([nil, nil]) end @@ -236,6 +229,35 @@ describe SubmoduleHelper do end end end + + context 'unknown submodule' do + before do + # When there is no `.gitmodules` file, or if `.gitmodules` does not + # know the submodule at the specified path, + # `Repository#submodule_url_for` returns `nil` + stub_url(nil) + end + + it 'returns no links' do + expect(subject).to eq([nil, nil]) + end + end + end + + context 'as view helpers in view context' do + subject { helper.submodule_links(submodule_item) } + + before do + self.instance_variable_set(:@repository, repo) + end + + it_behaves_like 'submodule_links' + end + + context 'as stand-alone module' do + subject { described_class.submodule_links(submodule_item, nil, repo) } + + it_behaves_like 'submodule_links' end def stub_url(url) diff --git a/spec/helpers/wiki_helper_spec.rb b/spec/helpers/wiki_helper_spec.rb index 8eab40aeaf3..ee977e37ec1 100644 --- a/spec/helpers/wiki_helper_spec.rb +++ b/spec/helpers/wiki_helper_spec.rb @@ -22,7 +22,7 @@ describe WikiHelper do describe '#wiki_sort_controls' do let(:project) { create(:project) } let(:wiki_link) { helper.wiki_sort_controls(project, sort, direction) } - let(:classes) { "btn btn-default has-tooltip reverse-sort-btn qa-reverse-sort" } + let(:classes) { "btn btn-default has-tooltip reverse-sort-btn qa-reverse-sort rspec-reverse-sort" } def expected_link(sort, direction, icon_class) path = "/#{project.full_path}/wikis/pages?direction=#{direction}&sort=#{sort}" |