diff options
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/application_helper_spec.rb | 262 | ||||
-rw-r--r-- | spec/helpers/broadcast_messages_helper_spec.rb | 22 | ||||
-rw-r--r-- | spec/helpers/diff_helper_spec.rb | 102 | ||||
-rw-r--r-- | spec/helpers/events_helper_spec.rb | 65 | ||||
-rw-r--r-- | spec/helpers/gitlab_markdown_helper_spec.rb | 916 | ||||
-rw-r--r-- | spec/helpers/groups_helper.rb | 21 | ||||
-rw-r--r-- | spec/helpers/icons_helper_spec.rb | 109 | ||||
-rw-r--r-- | spec/helpers/issues_helper_spec.rb | 138 | ||||
-rw-r--r-- | spec/helpers/labels_helper_spec.rb | 6 | ||||
-rw-r--r-- | spec/helpers/merge_requests_helper.rb | 12 | ||||
-rw-r--r-- | spec/helpers/nav_helper_spec.rb | 25 | ||||
-rw-r--r-- | spec/helpers/notifications_helper_spec.rb | 38 | ||||
-rw-r--r-- | spec/helpers/oauth_helper_spec.rb | 20 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 11 | ||||
-rw-r--r-- | spec/helpers/search_helper_spec.rb | 55 | ||||
-rw-r--r-- | spec/helpers/submodule_helper_spec.rb | 154 | ||||
-rw-r--r-- | spec/helpers/tab_helper_spec.rb | 44 | ||||
-rw-r--r-- | spec/helpers/tree_helper_spec.rb | 28 |
18 files changed, 0 insertions, 2028 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb deleted file mode 100644 index 015a66f7fa0..00000000000 --- a/spec/helpers/application_helper_spec.rb +++ /dev/null @@ -1,262 +0,0 @@ -require 'spec_helper' - -describe ApplicationHelper do - describe 'current_controller?' do - before do - allow(controller).to receive(:controller_name).and_return('foo') - end - - it 'returns true when controller matches argument' do - expect(current_controller?(:foo)).to be_truthy - end - - it 'returns false when controller does not match argument' do - expect(current_controller?(:bar)).not_to be_truthy - end - - it 'should take any number of arguments' do - expect(current_controller?(:baz, :bar)).not_to be_truthy - expect(current_controller?(:baz, :bar, :foo)).to be_truthy - end - end - - describe 'current_action?' do - before do - allow(self).to receive(:action_name).and_return('foo') - end - - it 'returns true when action matches argument' do - expect(current_action?(:foo)).to be_truthy - end - - it 'returns false when action does not match argument' do - expect(current_action?(:bar)).not_to be_truthy - end - - it 'should take any number of arguments' do - expect(current_action?(:baz, :bar)).not_to be_truthy - expect(current_action?(:baz, :bar, :foo)).to be_truthy - end - end - - describe 'project_icon' do - avatar_file_path = File.join(Rails.root, 'public', 'gitlab_logo.png') - - it 'should return an url for the avatar' do - project = create(:project) - project.avatar = File.open(avatar_file_path) - project.save! - avatar_url = "http://localhost/uploads/project/avatar/#{ project.id }/gitlab_logo.png" - expect(project_icon("#{project.namespace.to_param}/#{project.to_param}").to_s).to eq( - "<img alt=\"Gitlab logo\" src=\"#{avatar_url}\" />" - ) - end - - it 'should give uploaded icon when present' do - project = create(:project) - project.save! - - allow_any_instance_of(Project).to receive(:avatar_in_git).and_return(true) - - avatar_url = 'http://localhost' + namespace_project_avatar_path(project.namespace, project) - expect(project_icon("#{project.namespace.to_param}/#{project.to_param}").to_s).to match( - image_tag(avatar_url)) - end - end - - describe 'avatar_icon' do - avatar_file_path = File.join(Rails.root, 'public', 'gitlab_logo.png') - - it 'should return an url for the avatar' do - user = create(:user) - user.avatar = File.open(avatar_file_path) - user.save! - expect(avatar_icon(user.email).to_s). - to match("/uploads/user/avatar/#{ user.id }/gitlab_logo.png") - end - - it 'should return an url for the avatar with relative url' do - Gitlab.config.gitlab.stub(relative_url_root: '/gitlab') - Gitlab.config.gitlab.stub(url: Settings.send(:build_gitlab_url)) - - user = create(:user) - user.avatar = File.open(avatar_file_path) - user.save! - expect(avatar_icon(user.email).to_s). - to match("/gitlab/uploads/user/avatar/#{ user.id }/gitlab_logo.png") - end - - it 'should call gravatar_icon when no avatar is present' do - user = create(:user, email: 'test@example.com') - user.save! - expect(avatar_icon(user.email).to_s).to eq('http://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=40&d=identicon') - end - end - - describe 'gravatar_icon' do - let(:user_email) { 'user@email.com' } - - it 'should return a generic avatar path when Gravatar is disabled' do - ApplicationSetting.any_instance.stub(gravatar_enabled?: false) - expect(gravatar_icon(user_email)).to match('no_avatar.png') - end - - it 'should return a generic avatar path when email is blank' do - expect(gravatar_icon('')).to match('no_avatar.png') - end - - it 'should return default gravatar url' do - Gitlab.config.gitlab.stub(https: false) - url = 'http://www.gravatar.com/avatar/b58c6f14d292556214bd64909bcdb118' - expect(gravatar_icon(user_email)).to match(url) - end - - it 'should use SSL when appropriate' do - Gitlab.config.gitlab.stub(https: true) - expect(gravatar_icon(user_email)).to match('https://secure.gravatar.com') - end - - it 'should return custom gravatar path when gravatar_url is set' do - allow(self).to receive(:request).and_return(double(:ssl? => false)) - allow(Gitlab.config.gravatar). - to receive(:plain_url). - and_return('http://example.local/?s=%{size}&hash=%{hash}') - url = 'http://example.local/?s=20&hash=b58c6f14d292556214bd64909bcdb118' - expect(gravatar_icon(user_email, 20)).to eq(url) - end - - it 'should accept a custom size' do - allow(self).to receive(:request).and_return(double(:ssl? => false)) - expect(gravatar_icon(user_email, 64)).to match(/\?s=64/) - end - - it 'should use default size when size is wrong' do - allow(self).to receive(:request).and_return(double(:ssl? => false)) - expect(gravatar_icon(user_email, nil)).to match(/\?s=40/) - end - - it 'should be case insensitive' do - allow(self).to receive(:request).and_return(double(:ssl? => false)) - expect(gravatar_icon(user_email)). - to eq(gravatar_icon(user_email.upcase + ' ')) - end - end - - describe 'grouped_options_refs' do - # Override Rails' grouped_options_for_select helper since HTML is harder to work with - def grouped_options_for_select(options, *args) - options - end - - let(:options) { grouped_options_refs } - - before do - # Must be an instance variable - @project = create(:project) - end - - it 'includes a list of branch names' do - expect(options[0][0]).to eq('Branches') - expect(options[0][1]).to include('master', 'feature') - end - - it 'includes a list of tag names' do - expect(options[1][0]).to eq('Tags') - expect(options[1][1]).to include('v1.0.0', 'v1.1.0') - end - - it 'includes a specific commit ref if defined' do - # Must be an instance variable - @ref = '2ed06dc41dbb5936af845b87d79e05bbf24c73b8' - - expect(options[2][0]).to eq('Commit') - expect(options[2][1]).to eq([@ref]) - end - - it 'sorts tags in a natural order' do - # Stub repository.tag_names to make sure we get some valid testing data - expect(@project.repository).to receive(:tag_names). - and_return(['v1.0.9', 'v1.0.10', 'v2.0', 'v3.1.4.2', 'v2.0rc1¿', - 'v1.0.9a', 'v2.0-rc1', 'v2.0rc2']) - - expect(options[1][1]). - to eq(['v3.1.4.2', 'v2.0', 'v2.0rc2', 'v2.0rc1¿', 'v2.0-rc1', 'v1.0.10', - 'v1.0.9', 'v1.0.9a']) - end - end - - describe 'user_color_scheme_class' do - context 'with current_user is nil' do - it 'should return a string' do - allow(self).to receive(:current_user).and_return(nil) - expect(user_color_scheme_class).to be_kind_of(String) - end - end - - context 'with a current_user' do - (1..5).each do |color_scheme_id| - context "with color_scheme_id == #{color_scheme_id}" do - it 'should return a string' do - current_user = double(:color_scheme_id => color_scheme_id) - allow(self).to receive(:current_user).and_return(current_user) - expect(user_color_scheme_class).to be_kind_of(String) - end - end - end - end - end - - describe 'simple_sanitize' do - let(:a_tag) { '<a href="#">Foo</a>' } - - it 'allows the a tag' do - expect(simple_sanitize(a_tag)).to eq(a_tag) - end - - it 'allows the span tag' do - input = '<span class="foo">Bar</span>' - expect(simple_sanitize(input)).to eq(input) - end - - it 'disallows other tags' do - input = "<strike><b>#{a_tag}</b></strike>" - expect(simple_sanitize(input)).to eq(a_tag) - end - end - - describe 'link_to' do - it 'should not include rel=nofollow for internal links' do - expect(link_to('Home', root_path)).to eq('<a href="/">Home</a>') - end - - it 'should include rel=nofollow for external links' do - expect(link_to('Example', 'http://www.example.com')). - to eq '<a href="http://www.example.com" rel="nofollow">Example</a>' - end - - it 'should include rel=nofollow for external links and honor existing html_options' do - expect(link_to('Example', 'http://www.example.com', class: 'toggle', data: {toggle: 'dropdown'})) - .to eq '<a class="toggle" data-toggle="dropdown" href="http://www.example.com" rel="nofollow">Example</a>' - end - - it 'should include rel=nofollow for external links and preserve other rel values' do - expect(link_to('Example', 'http://www.example.com', rel: 'noreferrer')) - .to eq '<a href="http://www.example.com" rel="noreferrer nofollow">Example</a>' - end - - it 'should not include rel=nofollow for external links on the same host as GitLab' do - expect(Gitlab.config.gitlab).to receive(:host).and_return('example.foo') - expect(link_to('Example', 'http://example.foo/bar')). - to eq '<a href="http://example.foo/bar">Example</a>' - end - end - - describe 'markup_render' do - let(:content) { 'Noël' } - - it 'should preserve encoding' do - expect(content.encoding.name).to eq('UTF-8') - expect(render_markup('foo.rst', content).encoding.name).to eq('UTF-8') - end - end -end diff --git a/spec/helpers/broadcast_messages_helper_spec.rb b/spec/helpers/broadcast_messages_helper_spec.rb deleted file mode 100644 index f6df12662bb..00000000000 --- a/spec/helpers/broadcast_messages_helper_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' - -describe BroadcastMessagesHelper do - describe 'broadcast_styling' do - let(:broadcast_message) { double(color: "", font: "") } - - context "default style" do - it "should have no style" do - expect(broadcast_styling(broadcast_message)).to match('') - end - end - - context "customiezd style" do - before { broadcast_message.stub(color: "#f2dede", font: "#b94a48") } - - it "should have a customized style" do - expect(broadcast_styling(broadcast_message)). - to match('background-color:#f2dede;color:#b94a48') - end - end - end -end diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb deleted file mode 100644 index 5bd09793b11..00000000000 --- a/spec/helpers/diff_helper_spec.rb +++ /dev/null @@ -1,102 +0,0 @@ -require 'spec_helper' - -describe DiffHelper do - include RepoHelpers - - let(:project) { create(:project) } - let(:commit) { project.repository.commit(sample_commit.id) } - let(:diff) { commit.diffs.first } - let(:diff_file) { Gitlab::Diff::File.new(diff) } - - describe 'diff_hard_limit_enabled?' do - it 'should return true if param is provided' do - allow(controller).to receive(:params) { { force_show_diff: true } } - expect(diff_hard_limit_enabled?).to be_truthy - end - - it 'should return false if param is not provided' do - expect(diff_hard_limit_enabled?).to be_falsey - end - end - - describe 'allowed_diff_size' do - it 'should return hard limit for a diff if force diff is true' do - allow(controller).to receive(:params) { { force_show_diff: true } } - expect(allowed_diff_size).to eq(1000) - end - - it 'should return safe limit for a diff if force diff is false' do - expect(allowed_diff_size).to eq(100) - end - end - - describe 'parallel_diff' do - it 'should return an array of arrays containing the parsed diff' do - expect(parallel_diff(diff_file, 0)). - to match_array(parallel_diff_result_array) - end - end - - describe 'generate_line_code' do - it 'should generate correct line code' do - expect(generate_line_code(diff_file.file_path, diff_file.diff_lines.first)). - to eq('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6') - end - end - - describe 'unfold_bottom_class' do - it 'should return empty string when bottom line shouldnt be unfolded' do - expect(unfold_bottom_class(false)).to eq('') - end - - it 'should return js class when bottom lines should be unfolded' do - expect(unfold_bottom_class(true)).to eq('js-unfold-bottom') - end - end - - describe 'diff_line_content' do - - it 'should return non breaking space when line is empty' do - expect(diff_line_content(nil)).to eq(' ') - end - - it 'should return the line itself' do - expect(diff_line_content(diff_file.diff_lines.first.text)). - to eq('@@ -6,12 +6,18 @@ module Popen') - expect(diff_line_content(diff_file.diff_lines.first.type)).to eq('match') - expect(diff_line_content(diff_file.diff_lines.first.new_pos)).to eq(6) - end - end - - def parallel_diff_result_array - [ - ["match", 6, "@@ -6,12 +6,18 @@ module Popen", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6", "match", 6, "@@ -6,12 +6,18 @@ module Popen", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6"], - [nil, 6, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6", nil, 6, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6"], [nil, 7, " def popen(cmd, path=nil)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7", nil, 7, " def popen(cmd, path=nil)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"], - [nil, 8, " unless cmd.is_a?(Array)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_8_8", nil, 8, " unless cmd.is_a?(Array)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_8_8"], - ["old", 9, "- raise <span class='idiff'></span>"System commands must be given as an array of strings"", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9", "new", 9, "+ raise <span class='idiff'>RuntimeError, </span>"System commands must be given as an array of strings"", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"], - [nil, 10, " end", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_10", nil, 10, " end", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_10"], - [nil, 11, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_11_11", nil, 11, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_11_11"], - [nil, 12, " path ||= Dir.pwd", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_12_12", nil, 12, " path ||= Dir.pwd", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_12_12"], - ["old", 13, "- vars = { "PWD" => path }", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_13_13", "old", nil, " ", nil], - ["old", 14, "- options = { chdir: path }", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_14_13", "new", 13, "+", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_13"], - [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14", "new", 14, "+ vars = {", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14"], - [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15", "new", 15, "+ "PWD" => path", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"], - [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_16", "new", 16, "+ }", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_16"], - [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_17", "new", 17, "+", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_17"], - [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_18", "new", 18, "+ options = {", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_18"], - [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_19", "new", 19, "+ chdir: path", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_19"], - [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_20", "new", 20, "+ }", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_20"], - [nil, 15, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_21", nil, 21, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_21"], - [nil, 16, " unless File.directory?(path)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_16_22", nil, 22, " unless File.directory?(path)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_16_22"], - [nil, 17, " FileUtils.mkdir_p(path)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_17_23", nil, 23, " FileUtils.mkdir_p(path)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_17_23"], - ["match", 19, "@@ -19,6 +25,7 @@ module Popen", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25", "match", 25, "@@ -19,6 +25,7 @@ module Popen", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25"], - [nil, 19, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25", nil, 25, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25"], - [nil, 20, " @cmd_output = """, "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_20_26", nil, 26, " @cmd_output = """, "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_20_26"], - [nil, 21, " @cmd_status = 0", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_21_27", nil, 27, " @cmd_status = 0", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_21_27"], - [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_28", "new", 28, "+", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_28"], - [nil, 22, " Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_29", nil, 29, " Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_29"], - [nil, 23, " @cmd_output << stdout.read", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_23_30", nil, 30, " @cmd_output << stdout.read", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_23_30"], - [nil, 24, " @cmd_output << stderr.read", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_24_31", nil, 31, " @cmd_output << stderr.read", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_24_31"] - ] - end -end diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb deleted file mode 100644 index b392371deb4..00000000000 --- a/spec/helpers/events_helper_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -require 'spec_helper' - -describe EventsHelper do - include ApplicationHelper - include GitlabMarkdownHelper - - let(:current_user) { create(:user, email: "current@email.com") } - - it 'should display one line of plain text without alteration' do - input = 'A short, plain note' - expect(event_note(input)).to match(input) - expect(event_note(input)).not_to match(/\.\.\.\z/) - end - - it 'should display inline code' do - input = 'A note with `inline code`' - expected = 'A note with <code>inline code</code>' - - expect(event_note(input)).to match(expected) - end - - it 'should truncate a note with multiple paragraphs' do - input = "Paragraph 1\n\nParagraph 2" - expected = 'Paragraph 1...' - - expect(event_note(input)).to match(expected) - end - - it 'should display the first line of a code block' do - input = "```\nCode block\nwith two lines\n```" - expected = '<pre class="code highlight white plaintext"><code>' \ - 'Code block...</code></pre>' - - expect(event_note(input)).to match(expected) - end - - it 'should truncate a single long line of text' do - text = 'The quick brown fox jumped over the lazy dog twice' # 50 chars - input = "#{text}#{text}#{text}#{text}" # 200 chars - expected = "#{text}#{text}".sub(/.{3}/, '...') - - expect(event_note(input)).to match(expected) - end - - it 'should preserve a link href when link text is truncated' do - text = 'The quick brown fox jumped over the lazy dog' # 44 chars - input = "#{text}#{text}#{text} " # 133 chars - link_url = 'http://example.com/foo/bar/baz' # 30 chars - input << link_url - expected_link_text = 'http://example...</a>' - - expect(event_note(input)).to match(link_url) - expect(event_note(input)).to match(expected_link_text) - end - - it 'should preserve code color scheme' do - input = "```ruby\ndef test\n 'hello world'\nend\n```" - expected = '<pre class="code highlight white ruby">' \ - "<code><span class=\"k\">def</span> <span class=\"nf\">test</span>\n" \ - " <span class=\"s1\">\'hello world\'</span>\n" \ - "<span class=\"k\">end</span>\n" \ - '</code></pre>' - expect(event_note(input)).to eq(expected) - end -end diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb deleted file mode 100644 index 944e743675c..00000000000 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ /dev/null @@ -1,916 +0,0 @@ -require 'spec_helper' - -describe GitlabMarkdownHelper do - include ApplicationHelper - include IssuesHelper - - # TODO: Properly test this - def can?(*) - true - end - - let!(:project) { create(:project) } - let(:empty_project) { create(:empty_project) } - - let(:user) { create(:user, username: 'gfm') } - let(:commit) { project.repository.commit } - let(:earlier_commit){ project.repository.commit("HEAD~2") } - let(:issue) { create(:issue, project: project) } - let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } - let(:snippet) { create(:project_snippet, project: project) } - let(:member) { project.project_members.where(user_id: user).first } - - # Helper expects a current_user method. - let(:current_user) { user } - - def url_helper(image_name) - File.join(root_url, 'assets', image_name) - end - - before do - # Helper expects a @project instance variable - @project = project - @ref = 'markdown' - @repository = project.repository - @request.host = Gitlab.config.gitlab.host - end - - describe "#gfm" do - it "should return unaltered text if project is nil" do - actual = "Testing references: ##{issue.iid}" - - expect(gfm(actual)).not_to eq(actual) - - @project = nil - expect(gfm(actual)).to eq(actual) - end - - it "should not alter non-references" do - actual = expected = "_Please_ *stop* 'helping' and all the other b*$#%' you do." - expect(gfm(actual)).to eq(expected) - end - - it "should not touch HTML entities" do - allow(@project.issues).to receive(:where). - with(id: '39').and_return([issue]) - actual = 'We'll accept good pull requests.' - expect(gfm(actual)).to eq("We'll accept good pull requests.") - end - - it "should forward HTML options to links" do - expect(gfm("Fixed in #{commit.id}", @project, class: 'foo')). - to have_selector('a.gfm.foo') - end - - describe "referencing a commit range" do - let(:expected) { namespace_project_compare_path(project.namespace, project, from: earlier_commit.id, to: commit.id) } - - it "should link using a full id" do - actual = "What happened in #{earlier_commit.id}...#{commit.id}" - expect(gfm(actual)).to match(expected) - end - - it "should link using a short id" do - actual = "What happened in #{earlier_commit.short_id}...#{commit.short_id}" - expected = namespace_project_compare_path(project.namespace, project, from: earlier_commit.short_id, to: commit.short_id) - expect(gfm(actual)).to match(expected) - end - - it "should link inclusively" do - actual = "What happened in #{earlier_commit.id}..#{commit.id}" - expected = namespace_project_compare_path(project.namespace, project, from: "#{earlier_commit.id}^", to: commit.id) - expect(gfm(actual)).to match(expected) - end - - it "should link with adjacent text" do - actual = "(see #{earlier_commit.id}...#{commit.id})" - expect(gfm(actual)).to match(expected) - end - - it "should keep whitespace intact" do - actual = "Changes #{earlier_commit.id}...#{commit.id} dramatically" - expected = /Changes <a.+>#{earlier_commit.id}...#{commit.id}<\/a> dramatically/ - expect(gfm(actual)).to match(expected) - end - - it "should not link with an invalid id" do - actual = expected = "What happened in #{earlier_commit.id.reverse}...#{commit.id.reverse}" - expect(gfm(actual)).to eq(expected) - end - - it "should include a title attribute" do - actual = "What happened in #{earlier_commit.id}...#{commit.id}" - expect(gfm(actual)).to match(/title="Commits #{earlier_commit.id} through #{commit.id}"/) - end - - it "should include standard gfm classes" do - actual = "What happened in #{earlier_commit.id}...#{commit.id}" - expect(gfm(actual)).to match(/class="\s?gfm gfm-commit_range\s?"/) - end - end - - describe "referencing a commit" do - let(:expected) { namespace_project_commit_path(project.namespace, project, commit) } - - it "should link using a full id" do - actual = "Reverts #{commit.id}" - expect(gfm(actual)).to match(expected) - end - - it "should link using a short id" do - actual = "Backported from #{commit.short_id}" - expect(gfm(actual)).to match(expected) - end - - it "should link with adjacent text" do - actual = "Reverted (see #{commit.id})" - expect(gfm(actual)).to match(expected) - end - - it "should keep whitespace intact" do - actual = "Changes #{commit.id} dramatically" - expected = /Changes <a.+>#{commit.id}<\/a> dramatically/ - expect(gfm(actual)).to match(expected) - end - - it "should not link with an invalid id" do - actual = expected = "What happened in #{commit.id.reverse}" - expect(gfm(actual)).to eq(expected) - end - - it "should include a title attribute" do - actual = "Reverts #{commit.id}" - expect(gfm(actual)).to match(/title="#{commit.link_title}"/) - end - - it "should include standard gfm classes" do - actual = "Reverts #{commit.id}" - expect(gfm(actual)).to match(/class="\s?gfm gfm-commit\s?"/) - end - end - - describe "referencing a team member" do - let(:actual) { "@#{user.username} you are right." } - let(:expected) { user_path(user) } - - before do - project.team << [user, :master] - end - - it "should link using a simple name" do - expect(gfm(actual)).to match(expected) - end - - it "should link using a name with dots" do - user.update_attributes(name: "alphA.Beta") - expect(gfm(actual)).to match(expected) - end - - it "should link using name with underscores" do - user.update_attributes(name: "ping_pong_king") - expect(gfm(actual)).to match(expected) - end - - it "should link with adjacent text" do - actual = "Mail the admin (@#{user.username})" - expect(gfm(actual)).to match(expected) - end - - it "should keep whitespace intact" do - actual = "Yes, @#{user.username} is right." - expected = /Yes, <a.+>@#{user.username}<\/a> is right/ - expect(gfm(actual)).to match(expected) - end - - it "should not link with an invalid id" do - actual = expected = "@#{user.username.reverse} you are right." - expect(gfm(actual)).to eq(expected) - end - - it "should include standard gfm classes" do - expect(gfm(actual)).to match(/class="\s?gfm gfm-project_member\s?"/) - end - end - - # Shared examples for referencing an object - # - # Expects the following attributes to be available in the example group: - # - # - object - The object itself - # - reference - The object reference string (e.g., #1234, $1234, !1234) - # - # Currently limited to Snippets, Issues and MergeRequests - shared_examples 'referenced object' do - let(:actual) { "Reference to #{reference}" } - let(:expected) { polymorphic_path([project.namespace, project, object]) } - - it "should link using a valid id" do - expect(gfm(actual)).to match(expected) - end - - it "should link with adjacent text" do - # Wrap the reference in parenthesis - expect(gfm(actual.gsub(reference, "(#{reference})"))).to match(expected) - - # Append some text to the end of the reference - expect(gfm(actual.gsub(reference, "#{reference}, right?"))). - to match(expected) - end - - it "should keep whitespace intact" do - actual = "Referenced #{reference} already." - expected = /Referenced <a.+>[^\s]+<\/a> already/ - expect(gfm(actual)).to match(expected) - end - - it "should not link with an invalid id" do - # Modify the reference string so it's still parsed, but is invalid - reference.gsub!(/^(.)(\d+)$/, '\1' + ('\2' * 2)) - expect(gfm(actual)).to eq(actual) - end - - it "should include a title attribute" do - title = "#{object.class.to_s.titlecase}: #{object.title}" - expect(gfm(actual)).to match(/title="#{title}"/) - end - - it "should include standard gfm classes" do - css = object.class.to_s.underscore - expect(gfm(actual)).to match(/class="\s?gfm gfm-#{css}\s?"/) - end - end - - # Shared examples for referencing an object in a different project - # - # Expects the following attributes to be available in the example group: - # - # - object - The object itself - # - reference - The object reference string (e.g., #1234, $1234, !1234) - # - other_project - The project that owns the target object - # - # Currently limited to Snippets, Issues and MergeRequests - shared_examples 'cross-project referenced object' do - let(:project_path) { @other_project.path_with_namespace } - let(:full_reference) { "#{project_path}#{reference}" } - let(:actual) { "Reference to #{full_reference}" } - let(:expected) do - if object.is_a?(Commit) - namespace_project_commit_path(@other_project.namespace, @other_project, object) - else - polymorphic_path([@other_project.namespace, @other_project, object]) - end - end - - it 'should link using a valid id' do - expect(gfm(actual)).to match( - /#{expected}.*#{Regexp.escape(full_reference)}/ - ) - end - - it 'should link with adjacent text' do - # Wrap the reference in parenthesis - expect(gfm(actual.gsub(full_reference, "(#{full_reference})"))).to( - match(expected) - ) - - # Append some text to the end of the reference - expect(gfm(actual.gsub(full_reference, "#{full_reference}, right?"))). - to(match(expected)) - end - - it 'should keep whitespace intact' do - actual = "Referenced #{full_reference} already." - expected = /Referenced <a.+>[^\s]+<\/a> already/ - expect(gfm(actual)).to match(expected) - end - - it 'should not link with an invalid id' do - # Modify the reference string so it's still parsed, but is invalid - if object.is_a?(Commit) - reference.gsub!(/^(.).+$/, '\1' + '12345abcd') - else - reference.gsub!(/^(.)(\d+)$/, '\1' + ('\2' * 2)) - end - expect(gfm(actual)).to eq(actual) - end - - it 'should include a title attribute' do - if object.is_a?(Commit) - title = object.link_title - else - title = "#{object.class.to_s.titlecase}: #{object.title}" - end - expect(gfm(actual)).to match(/title="#{title}"/) - end - - it 'should include standard gfm classes' do - css = object.class.to_s.underscore - expect(gfm(actual)).to match(/class="\s?gfm gfm-#{css}\s?"/) - end - end - - describe "referencing an issue" do - let(:object) { issue } - let(:reference) { "##{issue.iid}" } - - include_examples 'referenced object' - end - - context 'cross-repo references' do - before(:all) do - @other_project = create(:project, :public) - @commit2 = @other_project.repository.commit - @issue2 = create(:issue, project: @other_project) - @merge_request2 = create(:merge_request, - source_project: @other_project, - target_project: @other_project) - end - - describe 'referencing an issue in another project' do - let(:object) { @issue2 } - let(:reference) { "##{@issue2.iid}" } - - include_examples 'cross-project referenced object' - end - - describe 'referencing an merge request in another project' do - let(:object) { @merge_request2 } - let(:reference) { "!#{@merge_request2.iid}" } - - include_examples 'cross-project referenced object' - end - - describe 'referencing a commit in another project' do - let(:object) { @commit2 } - let(:reference) { "@#{@commit2.id}" } - - include_examples 'cross-project referenced object' - end - end - - describe "referencing a Jira issue" do - let(:actual) { "Reference to JIRA-#{issue.iid}" } - let(:expected) { "http://jira.example/browse/JIRA-#{issue.iid}" } - let(:reference) { "JIRA-#{issue.iid}" } - - before do - jira = @project.create_jira_service if @project.jira_service.nil? - properties = {"title"=>"JIRA tracker", "project_url"=>"http://jira.example/issues/?jql=project=A", "issues_url"=>"http://jira.example/browse/:id", "new_issue_url"=>"http://jira.example/secure/CreateIssue.jspa"} - jira.update_attributes(properties: properties, active: true) - end - - after do - @project.jira_service.destroy! unless @project.jira_service.nil? - end - - it "should link using a valid id" do - expect(gfm(actual)).to match(expected) - end - - it "should link with adjacent text" do - # Wrap the reference in parenthesis - expect(gfm(actual.gsub(reference, "(#{reference})"))).to match(expected) - - # Append some text to the end of the reference - expect(gfm(actual.gsub(reference, "#{reference}, right?"))). - to match(expected) - end - - it "should keep whitespace intact" do - actual = "Referenced #{reference} already." - expected = /Referenced <a.+>[^\s]+<\/a> already/ - expect(gfm(actual)).to match(expected) - end - - it "should not link with an invalid id" do - # Modify the reference string so it's still parsed, but is invalid - invalid_reference = actual.gsub(/(\d+)$/, "r45") - expect(gfm(invalid_reference)).to eq(invalid_reference) - end - - it "should include a title attribute" do - title = "Issue in JIRA tracker" - expect(gfm(actual)).to match(/title="#{title}"/) - end - - it "should include standard gfm classes" do - expect(gfm(actual)).to match(/class="\s?gfm gfm-issue\s?"/) - end - end - - describe "referencing a merge request" do - let(:object) { merge_request } - let(:reference) { "!#{merge_request.iid}" } - - include_examples 'referenced object' - end - - describe "referencing a snippet" do - let(:object) { snippet } - let(:reference) { "$#{snippet.id}" } - let(:actual) { "Reference to #{reference}" } - let(:expected) { namespace_project_snippet_path(project.namespace, project, object) } - - it "should link using a valid id" do - expect(gfm(actual)).to match(expected) - end - - it "should link with adjacent text" do - # Wrap the reference in parenthesis - expect(gfm(actual.gsub(reference, "(#{reference})"))).to match(expected) - - # Append some text to the end of the reference - expect(gfm(actual.gsub(reference, "#{reference}, right?"))).to match(expected) - end - - it "should keep whitespace intact" do - actual = "Referenced #{reference} already." - expected = /Referenced <a.+>[^\s]+<\/a> already/ - expect(gfm(actual)).to match(expected) - end - - it "should not link with an invalid id" do - # Modify the reference string so it's still parsed, but is invalid - reference.gsub!(/^(.)(\d+)$/, '\1' + ('\2' * 2)) - expect(gfm(actual)).to eq(actual) - end - - it "should include a title attribute" do - title = "Snippet: #{object.title}" - expect(gfm(actual)).to match(/title="#{title}"/) - end - - it "should include standard gfm classes" do - css = object.class.to_s.underscore - expect(gfm(actual)).to match(/class="\s?gfm gfm-snippet\s?"/) - end - - end - - describe "referencing multiple objects" do - let(:actual) { "!#{merge_request.iid} -> #{commit.id} -> ##{issue.iid}" } - - it "should link to the merge request" do - expected = namespace_project_merge_request_path(project.namespace, project, merge_request) - expect(gfm(actual)).to match(expected) - end - - it "should link to the commit" do - expected = namespace_project_commit_path(project.namespace, project, commit) - expect(gfm(actual)).to match(expected) - end - - it "should link to the issue" do - expected = namespace_project_issue_path(project.namespace, project, issue) - expect(gfm(actual)).to match(expected) - end - end - - describe "emoji" do - it "matches at the start of a string" do - expect(gfm(":+1:")).to match(/<img/) - end - - it "matches at the end of a string" do - expect(gfm("This gets a :-1:")).to match(/<img/) - end - - it "matches with adjacent text" do - expect(gfm("+1 (:+1:)")).to match(/<img/) - end - - it "has a title attribute" do - expect(gfm(":-1:")).to match(/title=":-1:"/) - end - - it "has an alt attribute" do - expect(gfm(":-1:")).to match(/alt=":-1:"/) - end - - it "has an emoji class" do - expect(gfm(":+1:")).to match('class="emoji"') - end - - it "sets height and width" do - actual = gfm(":+1:") - expect(actual).to match(/width="20"/) - expect(actual).to match(/height="20"/) - end - - it "keeps whitespace intact" do - expect(gfm('This deserves a :+1: big time.')). - to match(/deserves a <img.+> big time/) - end - - it "ignores invalid emoji" do - expect(gfm(":invalid-emoji:")).not_to match(/<img/) - end - - it "should work independent of reference links (i.e. without @project being set)" do - @project = nil - expect(gfm(":+1:")).to match(/<img/) - end - end - end - - describe "#link_to_gfm" do - let(:commit_path) { namespace_project_commit_path(project.namespace, project, commit) } - let(:issues) { create_list(:issue, 2, project: project) } - - it "should handle references nested in links with all the text" do - actual = link_to_gfm("This should finally fix ##{issues[0].iid} and ##{issues[1].iid} for real", commit_path) - - # Break the result into groups of links with their content, without - # closing tags - groups = actual.split("</a>") - - # Leading commit link - expect(groups[0]).to match(/href="#{commit_path}"/) - expect(groups[0]).to match(/This should finally fix $/) - - # First issue link - expect(groups[1]). - to match(/href="#{namespace_project_issue_path(project.namespace, project, issues[0])}"/) - expect(groups[1]).to match(/##{issues[0].iid}$/) - - # Internal commit link - expect(groups[2]).to match(/href="#{commit_path}"/) - expect(groups[2]).to match(/ and /) - - # Second issue link - expect(groups[3]). - to match(/href="#{namespace_project_issue_path(project.namespace, project, issues[1])}"/) - expect(groups[3]).to match(/##{issues[1].iid}$/) - - # Trailing commit link - expect(groups[4]).to match(/href="#{commit_path}"/) - expect(groups[4]).to match(/ for real$/) - end - - it "should forward HTML options" do - actual = link_to_gfm("Fixed in #{commit.id}", commit_path, class: 'foo') - expect(actual).to have_selector 'a.gfm.gfm-commit.foo' - end - - it "escapes HTML passed in as the body" do - actual = "This is a <h1>test</h1> - see ##{issues[0].iid}" - expect(link_to_gfm(actual, commit_path)). - to match('<h1>test</h1>') - end - end - - describe "#markdown" do - it "should handle references in paragraphs" do - actual = "\n\nLorem ipsum dolor sit amet. #{commit.id} Nam pulvinar sapien eget.\n" - expected = namespace_project_commit_path(project.namespace, project, commit) - expect(markdown(actual)).to match(expected) - end - - it "should handle references in headers" do - actual = "\n# Working around ##{issue.iid}\n## Apply !#{merge_request.iid}" - - expect(markdown(actual, no_header_anchors: true)). - to match(%r{<h1[^<]*>Working around <a.+>##{issue.iid}</a></h1>}) - expect(markdown(actual, no_header_anchors: true)). - to match(%r{<h2[^<]*>Apply <a.+>!#{merge_request.iid}</a></h2>}) - end - - it "should add ids and links to headers" do - # Test every rule except nested tags. - text = '..Ab_c-d. e..' - id = 'ab_c-d-e' - expect(markdown("# #{text}")). - to match(%r{<h1 id="#{id}">#{text}<a href="[^"]*##{id}"></a></h1>}) - expect(markdown("# #{text}", {no_header_anchors:true})). - to eq("<h1>#{text}</h1>") - - id = 'link-text' - expect(markdown("# [link text](url) ![img alt](url)")).to match( - %r{<h1 id="#{id}"><a href="[^"]*url">link text</a> <img[^>]*><a href="[^"]*##{id}"></a></h1>} - ) - end - - it "should handle references in lists" do - project.team << [user, :master] - - actual = "\n* dark: ##{issue.iid}\n* light by @#{member.user.username}" - - expect(markdown(actual)). - to match(%r{<li>dark: <a.+>##{issue.iid}</a></li>}) - expect(markdown(actual)). - to match(%r{<li>light by <a.+>@#{member.user.username}</a></li>}) - end - - it "should not link the apostrophe to issue 39" do - project.team << [user, :master] - allow(project.issues). - to receive(:where).with(iid: '39').and_return([issue]) - - actual = "Yes, it is @#{member.user.username}'s task." - expected = /Yes, it is <a.+>@#{member.user.username}<\/a>'s task/ - expect(markdown(actual)).to match(expected) - end - - it "should not link the apostrophe to issue 39 in code blocks" do - project.team << [user, :master] - allow(project.issues). - to receive(:where).with(iid: '39').and_return([issue]) - - actual = "Yes, `it is @#{member.user.username}'s task.`" - expected = /Yes, <code>it is @gfm\'s task.<\/code>/ - expect(markdown(actual)).to match(expected) - end - - it "should handle references in <em>" do - actual = "Apply _!#{merge_request.iid}_ ASAP" - - expect(markdown(actual)). - to match(%r{Apply <em><a.+>!#{merge_request.iid}</a></em>}) - end - - it "should handle tables" do - actual = %Q{| header 1 | header 2 | -| -------- | -------- | -| cell 1 | cell 2 | -| cell 3 | cell 4 |} - - expect(markdown(actual)).to match(/\A<table/) - end - - it "should leave code blocks untouched" do - allow(helper).to receive(:user_color_scheme_class).and_return(:white) - - target_html = "<pre class=\"code highlight white plaintext\"><code>some code from $#{snippet.id}\nhere too\n</code></pre>\n" - - expect(helper.markdown("\n some code from $#{snippet.id}\n here too\n")). - to eq(target_html) - expect(helper.markdown("\n```\nsome code from $#{snippet.id}\nhere too\n```\n")). - to eq(target_html) - end - - it "should leave inline code untouched" do - expect(markdown("\nDon't use `$#{snippet.id}` here.\n")).to eq( - "<p>Don't use <code>$#{snippet.id}</code> here.</p>\n" - ) - end - - it "should leave ref-like autolinks untouched" do - expect(markdown("look at http://example.tld/#!#{merge_request.iid}")).to eq("<p>look at <a href=\"http://example.tld/#!#{merge_request.iid}\">http://example.tld/#!#{merge_request.iid}</a></p>\n") - end - - it "should leave ref-like href of 'manual' links untouched" do - expect(markdown("why not [inspect !#{merge_request.iid}](http://example.tld/#!#{merge_request.iid})")).to eq("<p>why not <a href=\"http://example.tld/#!#{merge_request.iid}\">inspect </a><a class=\"gfm gfm-merge_request \" href=\"#{namespace_project_merge_request_path(project.namespace, project, merge_request)}\" title=\"Merge Request: #{merge_request.title}\">!#{merge_request.iid}</a><a href=\"http://example.tld/#!#{merge_request.iid}\"></a></p>\n") - end - - it "should leave ref-like src of images untouched" do - expect(markdown("screen shot: ![some image](http://example.tld/#!#{merge_request.iid})")).to eq("<p>screen shot: <img src=\"http://example.tld/#!#{merge_request.iid}\" alt=\"some image\"></p>\n") - end - - it "should generate absolute urls for refs" do - expect(markdown("##{issue.iid}")).to include(namespace_project_issue_path(project.namespace, project, issue)) - end - - it "should generate absolute urls for emoji" do - expect(markdown(':smile:')).to( - include(%(src="#{Gitlab.config.gitlab.url}/assets/emoji/#{Emoji.emoji_filename('smile')}.png)) - ) - end - - it "should generate absolute urls for emoji if relative url is present" do - allow(Gitlab.config.gitlab).to receive(:url).and_return('http://localhost/gitlab/root') - expect(markdown(":smile:")).to include("src=\"http://localhost/gitlab/root/assets/emoji/#{Emoji.emoji_filename('smile')}.png") - end - - it "should generate absolute urls for emoji if asset_host is present" do - allow(Gitlab::Application.config).to receive(:asset_host).and_return("https://cdn.example.com") - ActionView::Base.any_instance.stub_chain(:config, :asset_host).and_return("https://cdn.example.com") - expect(markdown(":smile:")).to include("src=\"https://cdn.example.com/assets/emoji/#{Emoji.emoji_filename('smile')}.png") - end - - - it "should handle relative urls for a file in master" do - actual = "[GitLab API doc](doc/api/README.md)\n" - expected = "<p><a href=\"/#{project.path_with_namespace}/blob/#{@ref}/doc/api/README.md\">GitLab API doc</a></p>\n" - expect(markdown(actual)).to match(expected) - end - - it "should handle relative urls for a file in master with an anchor" do - actual = "[GitLab API doc](doc/api/README.md#section)\n" - expected = "<p><a href=\"/#{project.path_with_namespace}/blob/#{@ref}/doc/api/README.md#section\">GitLab API doc</a></p>\n" - expect(markdown(actual)).to match(expected) - end - - it "should not handle relative urls for the current file with an anchor" do - actual = "[GitLab API doc](#section)\n" - expected = "<p><a href=\"#section\">GitLab API doc</a></p>\n" - expect(markdown(actual)).to match(expected) - end - - it "should handle relative urls for a directory in master" do - actual = "[GitLab API doc](doc/api)\n" - expected = "<p><a href=\"/#{project.path_with_namespace}/tree/#{@ref}/doc/api\">GitLab API doc</a></p>\n" - expect(markdown(actual)).to match(expected) - end - - it "should handle absolute urls" do - actual = "[GitLab](https://www.gitlab.com)\n" - expected = "<p><a href=\"https://www.gitlab.com\">GitLab</a></p>\n" - expect(markdown(actual)).to match(expected) - end - - it "should handle relative urls in reference links for a file in master" do - actual = "[GitLab API doc][GitLab readme]\n [GitLab readme]: doc/api/README.md\n" - expected = "<p><a href=\"/#{project.path_with_namespace}/blob/#{@ref}/doc/api/README.md\">GitLab API doc</a></p>\n" - expect(markdown(actual)).to match(expected) - end - - it "should handle relative urls in reference links for a directory in master" do - actual = "[GitLab API doc directory][GitLab readmes]\n [GitLab readmes]: doc/api/\n" - expected = "<p><a href=\"/#{project.path_with_namespace}/tree/#{@ref}/doc/api\">GitLab API doc directory</a></p>\n" - expect(markdown(actual)).to match(expected) - end - - it "should not handle malformed relative urls in reference links for a file in master" do - actual = "[GitLab readme]: doc/api/README.md\n" - expected = "" - expect(markdown(actual)).to match(expected) - end - - it 'should allow whitelisted HTML tags from the user' do - actual = '<dl><dt>Term</dt><dd>Definition</dd></dl>' - expect(markdown(actual)).to match(actual) - end - - it 'should sanitize tags that are not whitelisted' do - actual = '<textarea>no inputs allowed</textarea> <blink>no blinks</blink>' - expected = 'no inputs allowed no blinks' - expect(markdown(actual)).to match(expected) - expect(markdown(actual)).not_to match('<.textarea>') - expect(markdown(actual)).not_to match('<.blink>') - end - - it 'should allow whitelisted tag attributes from the user' do - actual = '<a class="custom">link text</a>' - expect(markdown(actual)).to match(actual) - end - - it 'should sanitize tag attributes that are not whitelisted' do - actual = '<a href="http://example.com/bar.html" foo="bar">link text</a>' - expected = '<a href="http://example.com/bar.html">link text</a>' - expect(markdown(actual)).to match(expected) - end - - it 'should sanitize javascript in attributes' do - actual = %q(<a href="javascript:alert('foo')">link text</a>) - expected = '<a>link text</a>' - expect(markdown(actual)).to match(expected) - end - end - - describe 'markdown for empty repository' do - before do - @project = empty_project - @repository = empty_project.repository - end - - it "should not touch relative urls" do - actual = "[GitLab API doc][GitLab readme]\n [GitLab readme]: doc/api/README.md\n" - expected = "<p><a href=\"doc/api/README.md\">GitLab API doc</a></p>\n" - expect(markdown(actual)).to match(expected) - end - end - - describe "#render_wiki_content" do - before do - @wiki = double('WikiPage') - allow(@wiki).to receive(:content).and_return('wiki content') - end - - it "should use GitLab Flavored Markdown for markdown files" do - allow(@wiki).to receive(:format).and_return(:markdown) - - expect(helper).to receive(:markdown).with('wiki content') - - helper.render_wiki_content(@wiki) - end - - it "should use the Gollum renderer for all other file types" do - allow(@wiki).to receive(:format).and_return(:rdoc) - formatted_content_stub = double('formatted_content') - expect(formatted_content_stub).to receive(:html_safe) - allow(@wiki).to receive(:formatted_content).and_return(formatted_content_stub) - - helper.render_wiki_content(@wiki) - end - end - - describe '#gfm_with_tasks' do - before(:all) do - @source_text_asterisk = <<EOT.gsub(/^\s{8}/, '') - * [ ] valid unchecked task - * [x] valid lowercase checked task - * [X] valid uppercase checked task - * [ ] valid unchecked nested task - * [x] valid checked nested task - - [ ] not an unchecked task - no list item - [x] not a checked task - no list item - - * [ ] not an unchecked task - too many spaces - * [x ] not a checked task - too many spaces - * [] not an unchecked task - no spaces - * Not a task [ ] - not at beginning -EOT - - @source_text_dash = <<EOT.gsub(/^\s{8}/, '') - - [ ] valid unchecked task - - [x] valid lowercase checked task - - [X] valid uppercase checked task - - [ ] valid unchecked nested task - - [x] valid checked nested task -EOT - end - - it 'should render checkboxes at beginning of asterisk list items' do - rendered_text = markdown(@source_text_asterisk, parse_tasks: true) - - expect(rendered_text).to match(/<input.*checkbox.*valid unchecked task/) - expect(rendered_text).to match( - /<input.*checkbox.*valid lowercase checked task/ - ) - expect(rendered_text).to match( - /<input.*checkbox.*valid uppercase checked task/ - ) - end - - it 'should render checkboxes at beginning of dash list items' do - rendered_text = markdown(@source_text_dash, parse_tasks: true) - - expect(rendered_text).to match(/<input.*checkbox.*valid unchecked task/) - expect(rendered_text).to match( - /<input.*checkbox.*valid lowercase checked task/ - ) - expect(rendered_text).to match( - /<input.*checkbox.*valid uppercase checked task/ - ) - end - - it 'should render checkboxes for nested tasks' do - rendered_text = markdown(@source_text_asterisk, parse_tasks: true) - - expect(rendered_text).to match( - /<input.*checkbox.*valid unchecked nested task/ - ) - expect(rendered_text).to match( - /<input.*checkbox.*valid checked nested task/ - ) - end - - it 'should not be confused by whitespace before bullets' do - rendered_text_asterisk = markdown(@source_text_asterisk, - parse_tasks: true) - rendered_text_dash = markdown(@source_text_dash, parse_tasks: true) - - expect(rendered_text_asterisk).to match( - /<input.*checkbox.*valid unchecked nested task/ - ) - expect(rendered_text_asterisk).to match( - /<input.*checkbox.*valid checked nested task/ - ) - expect(rendered_text_dash).to match( - /<input.*checkbox.*valid unchecked nested task/ - ) - expect(rendered_text_dash).to match( - /<input.*checkbox.*valid checked nested task/ - ) - end - - it 'should not render checkboxes outside of list items' do - rendered_text = markdown(@source_text_asterisk, parse_tasks: true) - - expect(rendered_text).not_to match( - /<input.*checkbox.*not an unchecked task - no list item/ - ) - expect(rendered_text).not_to match( - /<input.*checkbox.*not a checked task - no list item/ - ) - end - - it 'should not render checkboxes with invalid formatting' do - rendered_text = markdown(@source_text_asterisk, parse_tasks: true) - - expect(rendered_text).not_to match( - /<input.*checkbox.*not an unchecked task - too many spaces/ - ) - expect(rendered_text).not_to match( - /<input.*checkbox.*not a checked task - too many spaces/ - ) - expect(rendered_text).not_to match( - /<input.*checkbox.*not an unchecked task - no spaces/ - ) - expect(rendered_text).not_to match( - /Not a task.*<input.*checkbox.*not at beginning/ - ) - end - end -end diff --git a/spec/helpers/groups_helper.rb b/spec/helpers/groups_helper.rb deleted file mode 100644 index 3e99ab84ec9..00000000000 --- a/spec/helpers/groups_helper.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper' - -describe GroupsHelper do - describe 'group_icon' do - avatar_file_path = File.join(Rails.root, 'public', 'gitlab_logo.png') - - it 'should return an url for the avatar' do - group = create(:group) - group.avatar = File.open(avatar_file_path) - group.save! - expect(group_icon(group.path).to_s). - to match("/uploads/group/avatar/#{ group.id }/gitlab_logo.png") - end - - it 'should give default avatar_icon when no avatar is present' do - group = create(:group) - group.save! - expect(group_icon(group.path)).to match('group_avatar.png') - end - end -end diff --git a/spec/helpers/icons_helper_spec.rb b/spec/helpers/icons_helper_spec.rb deleted file mode 100644 index c052981fe73..00000000000 --- a/spec/helpers/icons_helper_spec.rb +++ /dev/null @@ -1,109 +0,0 @@ -require 'spec_helper' - -describe IconsHelper do - describe 'file_type_icon_class' do - it 'returns folder class' do - expect(file_type_icon_class('folder', 0, 'folder_name')).to eq 'folder' - end - - it 'returns share class' do - expect(file_type_icon_class('file', '120000', 'link')).to eq 'share' - end - - it 'returns file-pdf-o class with .pdf' do - expect(file_type_icon_class('file', 0, 'filename.pdf')).to eq 'file-pdf-o' - end - - it 'returns file-image-o class with .jpg' do - expect(file_type_icon_class('file', 0, 'filename.jpg')).to eq 'file-image-o' - end - - it 'returns file-image-o class with .JPG' do - expect(file_type_icon_class('file', 0, 'filename.JPG')).to eq 'file-image-o' - end - - it 'returns file-image-o class with .png' do - expect(file_type_icon_class('file', 0, 'filename.png')).to eq 'file-image-o' - end - - it 'returns file-archive-o class with .tar' do - expect(file_type_icon_class('file', 0, 'filename.tar')).to eq 'file-archive-o' - end - - it 'returns file-archive-o class with .TAR' do - expect(file_type_icon_class('file', 0, 'filename.TAR')).to eq 'file-archive-o' - end - - it 'returns file-archive-o class with .tar.gz' do - expect(file_type_icon_class('file', 0, 'filename.tar.gz')).to eq 'file-archive-o' - end - - it 'returns file-audio-o class with .mp3' do - expect(file_type_icon_class('file', 0, 'filename.mp3')).to eq 'file-audio-o' - end - - it 'returns file-audio-o class with .MP3' do - expect(file_type_icon_class('file', 0, 'filename.MP3')).to eq 'file-audio-o' - end - - it 'returns file-audio-o class with .wav' do - expect(file_type_icon_class('file', 0, 'filename.wav')).to eq 'file-audio-o' - end - - it 'returns file-video-o class with .avi' do - expect(file_type_icon_class('file', 0, 'filename.avi')).to eq 'file-video-o' - end - - it 'returns file-video-o class with .AVI' do - expect(file_type_icon_class('file', 0, 'filename.AVI')).to eq 'file-video-o' - end - - it 'returns file-video-o class with .mp4' do - expect(file_type_icon_class('file', 0, 'filename.mp4')).to eq 'file-video-o' - end - - it 'returns file-word-o class with .doc' do - expect(file_type_icon_class('file', 0, 'filename.doc')).to eq 'file-word-o' - end - - it 'returns file-word-o class with .DOC' do - expect(file_type_icon_class('file', 0, 'filename.DOC')).to eq 'file-word-o' - end - - it 'returns file-word-o class with .docx' do - expect(file_type_icon_class('file', 0, 'filename.docx')).to eq 'file-word-o' - end - - it 'returns file-excel-o class with .xls' do - expect(file_type_icon_class('file', 0, 'filename.xls')).to eq 'file-excel-o' - end - - it 'returns file-excel-o class with .XLS' do - expect(file_type_icon_class('file', 0, 'filename.XLS')).to eq 'file-excel-o' - end - - it 'returns file-excel-o class with .xlsx' do - expect(file_type_icon_class('file', 0, 'filename.xlsx')).to eq 'file-excel-o' - end - - it 'returns file-excel-o class with .ppt' do - expect(file_type_icon_class('file', 0, 'filename.ppt')).to eq 'file-powerpoint-o' - end - - it 'returns file-excel-o class with .PPT' do - expect(file_type_icon_class('file', 0, 'filename.PPT')).to eq 'file-powerpoint-o' - end - - it 'returns file-excel-o class with .pptx' do - expect(file_type_icon_class('file', 0, 'filename.pptx')).to eq 'file-powerpoint-o' - end - - it 'returns file-text-o class with .unknow' do - expect(file_type_icon_class('file', 0, 'filename.unknow')).to eq 'file-text-o' - end - - it 'returns file-text-o class with no extension' do - expect(file_type_icon_class('file', 0, 'CHANGELOG')).to eq 'file-text-o' - end - end -end diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb deleted file mode 100644 index 54dd8d4aa64..00000000000 --- a/spec/helpers/issues_helper_spec.rb +++ /dev/null @@ -1,138 +0,0 @@ -require "spec_helper" - -describe IssuesHelper do - let(:project) { create :project } - let(:issue) { create :issue, project: project } - let(:ext_project) { create :redmine_project } - - describe "title_for_issue" do - it "should return issue title if used internal tracker" do - @project = project - expect(title_for_issue(issue.iid)).to eq issue.title - end - - it "should always return empty string if used external tracker" do - @project = ext_project - expect(title_for_issue(rand(100))).to eq "" - end - - it "should always return empty string if project nil" do - @project = nil - - expect(title_for_issue(rand(100))).to eq "" - end - end - - describe "url_for_project_issues" do - let(:project_url) { ext_project.external_issue_tracker.project_url } - let(:ext_expected) do - project_url.gsub(':project_id', ext_project.id.to_s) - .gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s) - end - let(:int_expected) { polymorphic_path([@project.namespace, project]) } - - it "should return internal path if used internal tracker" do - @project = project - expect(url_for_project_issues).to match(int_expected) - end - - it "should return path to external tracker" do - @project = ext_project - - expect(url_for_project_issues).to match(ext_expected) - end - - it "should return empty string if project nil" do - @project = nil - - expect(url_for_project_issues).to eq "" - end - - describe "when external tracker was enabled and then config removed" do - before do - @project = ext_project - allow(Gitlab.config).to receive(:issues_tracker).and_return(nil) - end - - it "should return path to external tracker" do - expect(url_for_project_issues).to match(ext_expected) - end - end - end - - describe "url_for_issue" do - let(:issues_url) { ext_project.external_issue_tracker.issues_url} - let(:ext_expected) do - issues_url.gsub(':id', issue.iid.to_s) - .gsub(':project_id', ext_project.id.to_s) - .gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s) - end - let(:int_expected) { polymorphic_path([@project.namespace, project, issue]) } - - it "should return internal path if used internal tracker" do - @project = project - expect(url_for_issue(issue.iid)).to match(int_expected) - end - - it "should return path to external tracker" do - @project = ext_project - - expect(url_for_issue(issue.iid)).to match(ext_expected) - end - - it "should return empty string if project nil" do - @project = nil - - expect(url_for_issue(issue.iid)).to eq "" - end - - describe "when external tracker was enabled and then config removed" do - before do - @project = ext_project - allow(Gitlab.config).to receive(:issues_tracker).and_return(nil) - end - - it "should return external path" do - expect(url_for_issue(issue.iid)).to match(ext_expected) - end - end - end - - describe '#url_for_new_issue' do - let(:issues_url) { ext_project.external_issue_tracker.new_issue_url } - let(:ext_expected) do - issues_url.gsub(':project_id', ext_project.id.to_s) - .gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s) - end - let(:int_expected) { new_namespace_project_issue_path(project.namespace, project) } - - it "should return internal path if used internal tracker" do - @project = project - expect(url_for_new_issue).to match(int_expected) - end - - it "should return path to external tracker" do - @project = ext_project - - expect(url_for_new_issue).to match(ext_expected) - end - - it "should return empty string if project nil" do - @project = nil - - expect(url_for_new_issue).to eq "" - end - - describe "when external tracker was enabled and then config removed" do - before do - @project = ext_project - allow(Gitlab.config).to receive(:issues_tracker).and_return(nil) - end - - it "should return internal path" do - expect(url_for_new_issue).to match(ext_expected) - end - end - end - -end diff --git a/spec/helpers/labels_helper_spec.rb b/spec/helpers/labels_helper_spec.rb deleted file mode 100644 index 1e64a201942..00000000000 --- a/spec/helpers/labels_helper_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'spec_helper' - -describe LabelsHelper do - it { expect(text_color_for_bg('#EEEEEE')).to eq('#333') } - it { expect(text_color_for_bg('#222E2E')).to eq('#FFF') } -end diff --git a/spec/helpers/merge_requests_helper.rb b/spec/helpers/merge_requests_helper.rb deleted file mode 100644 index 5262d644048..00000000000 --- a/spec/helpers/merge_requests_helper.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'spec_helper' - -describe MergeRequestsHelper do - describe :issues_sentence do - subject { issues_sentence(issues) } - let(:issues) do - [build(:issue, iid: 1), build(:issue, iid: 2), build(:issue, iid: 3)] - end - - it { is_expected.to eq('#1, #2, and #3') } - end -end diff --git a/spec/helpers/nav_helper_spec.rb b/spec/helpers/nav_helper_spec.rb deleted file mode 100644 index e4d18d8bfc6..00000000000 --- a/spec/helpers/nav_helper_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'spec_helper' - -# Specs in this file have access to a helper object that includes -# the NavHelper. For example: -# -# describe NavHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -describe NavHelper do - describe '#nav_menu_collapsed?' do - it 'returns true when the nav is collapsed in the cookie' do - helper.request.cookies[:collapsed_nav] = 'true' - expect(helper.nav_menu_collapsed?).to eq true - end - - it 'returns false when the nav is not collapsed in the cookie' do - helper.request.cookies[:collapsed_nav] = 'false' - expect(helper.nav_menu_collapsed?).to eq false - end - end -end diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb deleted file mode 100644 index 482cb33e94f..00000000000 --- a/spec/helpers/notifications_helper_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'spec_helper' - -describe NotificationsHelper do - include FontAwesome::Rails::IconHelper - include IconsHelper - - describe 'notification_icon' do - let(:notification) { double(disabled?: false, participating?: false, watch?: false) } - - context "disabled notification" do - before { notification.stub(disabled?: true) } - - it "has a red icon" do - expect(notification_icon(notification)).to match('class="fa fa-volume-off ns-mute"') - end - end - - context "participating notification" do - before { notification.stub(participating?: true) } - - it "has a blue icon" do - expect(notification_icon(notification)).to match('class="fa fa-volume-down ns-part"') - end - end - - context "watched notification" do - before { notification.stub(watch?: true) } - - it "has a green icon" do - expect(notification_icon(notification)).to match('class="fa fa-volume-up ns-watch"') - end - end - - it "has a blue icon" do - expect(notification_icon(notification)).to match('class="fa fa-circle-o ns-default"') - end - end -end diff --git a/spec/helpers/oauth_helper_spec.rb b/spec/helpers/oauth_helper_spec.rb deleted file mode 100644 index 088c342fa13..00000000000 --- a/spec/helpers/oauth_helper_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require "spec_helper" - -describe OauthHelper do - describe "additional_providers" do - it 'returns all enabled providers' do - allow(helper).to receive(:enabled_oauth_providers) { [:twitter, :github] } - expect(helper.additional_providers).to include(*[:twitter, :github]) - end - - it 'does not return ldap provider' do - allow(helper).to receive(:enabled_oauth_providers) { [:twitter, :ldapmain] } - expect(helper.additional_providers).to include(:twitter) - end - - it 'returns empty array' do - allow(helper).to receive(:enabled_oauth_providers) { [] } - expect(helper.additional_providers).to eq([]) - end - end -end
\ No newline at end of file diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb deleted file mode 100644 index 0f78725e3d9..00000000000 --- a/spec/helpers/projects_helper_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' - -describe ProjectsHelper do - describe "#project_status_css_class" do - it "returns appropriate class" do - expect(project_status_css_class("started")).to eq("active") - expect(project_status_css_class("failed")).to eq("danger") - expect(project_status_css_class("finished")).to eq("success") - end - end -end diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb deleted file mode 100644 index b327f4f911a..00000000000 --- a/spec/helpers/search_helper_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'spec_helper' - -describe SearchHelper do - # Override simple_sanitize for our testing purposes - def simple_sanitize(str) - str - end - - describe 'search_autocomplete_source' do - context "with no current user" do - before do - allow(self).to receive(:current_user).and_return(nil) - end - - it "it returns nil" do - expect(search_autocomplete_opts("q")).to be_nil - end - end - - context "with a user" do - let(:user) { create(:user) } - - before do - allow(self).to receive(:current_user).and_return(user) - end - - it "includes Help sections" do - expect(search_autocomplete_opts("hel").size).to eq(9) - end - - it "includes default sections" do - expect(search_autocomplete_opts("adm").size).to eq(1) - end - - it "includes the user's groups" do - create(:group).add_owner(user) - expect(search_autocomplete_opts("gro").size).to eq(1) - end - - it "includes the user's projects" do - project = create(:project, namespace: create(:namespace, owner: user)) - expect(search_autocomplete_opts(project.name).size).to eq(1) - end - - context "with a current project" do - before { @project = create(:project) } - - it "includes project-specific sections" do - expect(search_autocomplete_opts("Files").size).to eq(1) - expect(search_autocomplete_opts("Commits").size).to eq(1) - end - end - end - end -end diff --git a/spec/helpers/submodule_helper_spec.rb b/spec/helpers/submodule_helper_spec.rb deleted file mode 100644 index e99c3f5bc11..00000000000 --- a/spec/helpers/submodule_helper_spec.rb +++ /dev/null @@ -1,154 +0,0 @@ -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 - - context 'submodule on self' do - before do - Gitlab.config.gitlab.stub(protocol: 'http') # set this just to be sure - end - - it 'should detect ssh on standard port' do - Gitlab.config.gitlab_shell.stub(ssh_port: 22) # set this just to be sure - Gitlab.config.gitlab_shell.stub(ssh_path_prefix: 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') ]) - end - - it 'should detect ssh on non-standard port' do - Gitlab.config.gitlab_shell.stub(ssh_port: 2222) - Gitlab.config.gitlab_shell.stub(ssh_path_prefix: 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') ]) - end - - it 'should detect http on standard port' do - Gitlab.config.gitlab.stub(port: 80) - Gitlab.config.gitlab.stub(url: 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') ]) - end - - it 'should detect http on non-standard port' do - Gitlab.config.gitlab.stub(port: 3000) - Gitlab.config.gitlab.stub(url: 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') ]) - end - - it 'should work with relative_url_root' do - Gitlab.config.gitlab.stub(port: 80) # set this just to be sure - Gitlab.config.gitlab.stub(relative_url_root: '/gitlab/root') - Gitlab.config.gitlab.stub(url: 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') ]) - end - end - - context 'submodule on github.com' do - it 'should detect 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' ]) - end - - it 'should detect 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' ]) - end - - it 'should detect 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' ]) - end - - it 'should return original with non-standard url' do - stub_url('http://github.com/gitlab-org/gitlab-ce') - expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ]) - - stub_url('http://github.com/another/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ]) - end - end - - context 'submodule on gitlab.com' do - it 'should detect 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' ]) - end - - it 'should detect 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' ]) - end - - it 'should detect 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' ]) - end - - it 'should return original with non-standard url' do - stub_url('http://gitlab.com/gitlab-org/gitlab-ce') - expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ]) - - stub_url('http://gitlab.com/another/gitlab-org/gitlab-ce.git') - expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ]) - end - end - - context 'submodule on unsupported' do - it 'should return 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 ]) - end - end - - context 'submodules with relative links' do - let(:group) { create(:group) } - let(:project) { create(:project, group: group) } - - before do - self.instance_variable_set(:@project, project) - end - - it 'one level down' do - commit_id = sample_commit[:id] - result = relative_self_links('../test.git', commit_id) - expect(result).to eq(["/#{group.path}/test", "/#{group.path}/test/tree/#{commit_id}"]) - end - - it 'two levels down' do - commit_id = sample_commit[:id] - result = relative_self_links('../../test.git', commit_id) - expect(result).to eq(["/#{group.path}/test", "/#{group.path}/test/tree/#{commit_id}"]) - end - - it 'one level down with namespace and repo' do - commit_id = sample_commit[:id] - result = relative_self_links('../foobar/test.git', commit_id) - expect(result).to eq(["/foobar/test", "/foobar/test/tree/#{commit_id}"]) - end - - it 'two levels down with namespace and repo' do - commit_id = sample_commit[:id] - result = relative_self_links('../foobar/baz/test.git', commit_id) - expect(result).to eq(["/baz/test", "/baz/test/tree/#{commit_id}"]) - end - end - end - - def stub_url(url) - repo.stub(submodule_url_for: url) - end -end diff --git a/spec/helpers/tab_helper_spec.rb b/spec/helpers/tab_helper_spec.rb deleted file mode 100644 index fc0ceecfbe7..00000000000 --- a/spec/helpers/tab_helper_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'spec_helper' - -describe TabHelper do - include ApplicationHelper - - describe 'nav_link' do - before do - allow(controller).to receive(:controller_name).and_return('foo') - allow(self).to receive(:action_name).and_return('foo') - end - - it "captures block output" do - expect(nav_link { "Testing Blocks" }).to match(/Testing Blocks/) - end - - it "performs checks on the current controller" do - expect(nav_link(controller: :foo)).to match(/<li class="active">/) - expect(nav_link(controller: :bar)).not_to match(/active/) - expect(nav_link(controller: [:foo, :bar])).to match(/active/) - end - - it "performs checks on the current action" do - expect(nav_link(action: :foo)).to match(/<li class="active">/) - expect(nav_link(action: :bar)).not_to match(/active/) - expect(nav_link(action: [:foo, :bar])).to match(/active/) - end - - it "performs checks on both controller and action when both are present" do - expect(nav_link(controller: :bar, action: :foo)).not_to match(/active/) - expect(nav_link(controller: :foo, action: :bar)).not_to match(/active/) - expect(nav_link(controller: :foo, action: :foo)).to match(/active/) - end - - it "accepts a path shorthand" do - expect(nav_link(path: 'foo#bar')).not_to match(/active/) - expect(nav_link(path: 'foo#foo')).to match(/active/) - end - - it "passes extra html options to the list element" do - expect(nav_link(action: :foo, html_options: {class: 'home'})).to match(/<li class="home active">/) - expect(nav_link(html_options: {class: 'active'})).to match(/<li class="active">/) - end - end -end diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb deleted file mode 100644 index 8271e00f41b..00000000000 --- a/spec/helpers/tree_helper_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'spec_helper' - -describe TreeHelper do - describe 'flatten_tree' do - let(:project) { create(:project) } - - before { - @repository = project.repository - @commit = project.repository.commit("e56497bb") - } - - context "on a directory containing more than one file/directory" do - let(:tree_item) { double(name: "files", path: "files") } - - it "should return the directory name" do - expect(flatten_tree(tree_item)).to match('files') - end - end - - context "on a directory containing only one directory" do - let(:tree_item) { double(name: "foo", path: "foo") } - - it "should return the flattened path" do - expect(flatten_tree(tree_item)).to match('foo/bar') - end - end - end -end |