summaryrefslogtreecommitdiff
path: root/spec/helpers
diff options
context:
space:
mode:
authorVinnie Okada <vokada@mrvinn.com>2015-03-17 20:53:09 -0600
committerVinnie Okada <vokada@mrvinn.com>2015-03-17 20:53:09 -0600
commitfeeffc442618d92040cd1cc38158b689a09988fd (patch)
treeb19c0ac2ddae23d830bbc69b99d920eec1f81363 /spec/helpers
parent1a9c2ddc55cf563ea42d67811a19b2693d7a44e9 (diff)
parent5bbc70da9cb439342bdbe022988e4e734d891f44 (diff)
downloadgitlab-ce-feeffc442618d92040cd1cc38158b689a09988fd.tar.gz
Merge branch 'master' into markdown-tags
Use the latest HTML pipeline gem
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/application_helper_spec.rb201
-rw-r--r--spec/helpers/broadcast_messages_helper_spec.rb5
-rw-r--r--spec/helpers/diff_helper_spec.rb31
-rw-r--r--spec/helpers/events_helper_spec.rb65
-rw-r--r--spec/helpers/gitlab_markdown_helper_spec.rb367
-rw-r--r--spec/helpers/groups_helper.rb21
-rw-r--r--spec/helpers/issues_helper_spec.rb63
-rw-r--r--spec/helpers/merge_requests_helper.rb2
-rw-r--r--spec/helpers/nav_helper_spec.rb25
-rw-r--r--spec/helpers/notifications_helper_spec.rb11
-rw-r--r--spec/helpers/oauth_helper_spec.rb20
-rw-r--r--spec/helpers/projects_helper_spec.rb22
-rw-r--r--spec/helpers/search_helper_spec.rb14
-rw-r--r--spec/helpers/submodule_helper_spec.rb34
-rw-r--r--spec/helpers/tab_helper_spec.rb30
-rw-r--r--spec/helpers/tree_helper_spec.rb28
16 files changed, 617 insertions, 322 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 2db67cfdf95..4c11709ed6e 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -3,20 +3,20 @@ require 'spec_helper'
describe ApplicationHelper do
describe 'current_controller?' do
before do
- controller.stub(:controller_name).and_return('foo')
+ allow(controller).to receive(:controller_name).and_return('foo')
end
- it "returns true when controller matches argument" do
- current_controller?(:foo).should be_true
+ 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
- current_controller?(:bar).should_not be_true
+ 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
- current_controller?(:baz, :bar).should_not be_true
- current_controller?(:baz, :bar, :foo).should be_true
+ 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
@@ -25,99 +25,124 @@ describe ApplicationHelper do
allow(self).to receive(:action_name).and_return('foo')
end
- it "returns true when action matches argument" do
- current_action?(:foo).should be_true
+ 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
- current_action?(:bar).should_not be_true
+ 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
- current_action?(:baz, :bar).should_not be_true
- current_action?(:baz, :bar, :foo).should be_true
+ 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 "group_icon" do
+ describe 'project_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!
- group_icon(group.path).to_s.should match("/uploads/group/avatar/#{ group.id }/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 default avatar_icon when no avatar is present" do
- group = create(:group)
- group.save!
- group_icon(group.path).should match("group_avatar.png")
+ 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
+ describe 'avatar_icon' do
avatar_file_path = File.join(Rails.root, 'public', 'gitlab_logo.png')
- it "should return an url for the avatar" do
+ 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!
- avatar_icon(user.email).to_s.should match("/uploads/user/avatar/#{ user.id }/gitlab_logo.png")
+ 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
+ it 'should call gravatar_icon when no avatar is present' do
user = create(:user, email: 'test@example.com')
user.save!
- avatar_icon(user.email).to_s.should == "http://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=40&d=identicon"
+ 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
+ describe 'gravatar_icon' do
let(:user_email) { 'user@email.com' }
- it "should return a generic avatar path when Gravatar is disabled" do
- Gitlab.config.gravatar.stub(:enabled).and_return(false)
- gravatar_icon(user_email).should match('no_avatar.png')
+ 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
- gravatar_icon('').should match('no_avatar.png')
+ 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
+ it 'should return default gravatar url' do
Gitlab.config.gitlab.stub(https: false)
- gravatar_icon(user_email).should match('http://www.gravatar.com/avatar/b58c6f14d292556214bd64909bcdb118')
+ url = 'http://www.gravatar.com/avatar/b58c6f14d292556214bd64909bcdb118'
+ expect(gravatar_icon(user_email)).to match(url)
end
- it "should use SSL when appropriate" do
+ it 'should use SSL when appropriate' do
Gitlab.config.gitlab.stub(https: true)
- gravatar_icon(user_email).should match('https://secure.gravatar.com')
+ expect(gravatar_icon(user_email)).to match('https://secure.gravatar.com')
end
- it "should return custom gravatar path when gravatar_url is set" do
+ it 'should return custom gravatar path when gravatar_url is set' do
allow(self).to receive(:request).and_return(double(:ssl? => false))
- Gitlab.config.gravatar.stub(:plain_url).and_return('http://example.local/?s=%{size}&hash=%{hash}')
- gravatar_icon(user_email, 20).should == 'http://example.local/?s=20&hash=b58c6f14d292556214bd64909bcdb118'
+ 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
+ it 'should accept a custom size' do
allow(self).to receive(:request).and_return(double(:ssl? => false))
- gravatar_icon(user_email, 64).should match(/\?s=64/)
+ expect(gravatar_icon(user_email, 64)).to match(/\?s=64/)
end
- it "should use default size when size is wrong" do
+ it 'should use default size when size is wrong' do
allow(self).to receive(:request).and_return(double(:ssl? => false))
- gravatar_icon(user_email, nil).should match(/\?s=40/)
+ expect(gravatar_icon(user_email, nil)).to match(/\?s=40/)
end
- it "should be case insensitive" do
+ it 'should be case insensitive' do
allow(self).to receive(:request).and_return(double(:ssl? => false))
- gravatar_icon(user_email).should == gravatar_icon(user_email.upcase + " ")
+ expect(gravatar_icon(user_email)).
+ to eq(gravatar_icon(user_email.upcase + ' '))
end
end
- describe "grouped_options_refs" do
+ 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
@@ -130,90 +155,94 @@ describe ApplicationHelper do
@project = create(:project)
end
- it "includes a list of branch names" do
- options[0][0].should == 'Branches'
- options[0][1].should include('master', 'feature')
+ 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
- options[1][0].should == 'Tags'
- options[1][1].should include('v1.0.0','v1.1.0')
+ 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
+ it 'includes a specific commit ref if defined' do
# Must be an instance variable
@ref = '2ed06dc41dbb5936af845b87d79e05bbf24c73b8'
- options[2][0].should == 'Commit'
- options[2][1].should == [@ref]
+ expect(options[2][0]).to eq('Commit')
+ expect(options[2][1]).to eq([@ref])
end
- it "sorts tags in a natural order" do
+ 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", "v1.0.9a"])
+ 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'])
- options[1][1].should == ["v3.1.4.2", "v2.0", "v1.0.10", "v1.0.9a", "v1.0.9"]
+ 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
+ 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)
- user_color_scheme_class.should be_kind_of(String)
+ expect(user_color_scheme_class).to be_kind_of(String)
end
end
- context "with a current_user" do
+ 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
+ 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)
- user_color_scheme_class.should be_kind_of(String)
+ expect(user_color_scheme_class).to be_kind_of(String)
end
end
end
end
end
- describe "simple_sanitize" do
+ describe 'simple_sanitize' do
let(:a_tag) { '<a href="#">Foo</a>' }
- it "allows the a tag" do
- simple_sanitize(a_tag).should == a_tag
+ it 'allows the a tag' do
+ expect(simple_sanitize(a_tag)).to eq(a_tag)
end
- it "allows the span tag" do
+ it 'allows the span tag' do
input = '<span class="foo">Bar</span>'
- simple_sanitize(input).should == input
+ expect(simple_sanitize(input)).to eq(input)
end
- it "disallows other tags" do
+ it 'disallows other tags' do
input = "<strike><b>#{a_tag}</b></strike>"
- simple_sanitize(input).should == a_tag
+ expect(simple_sanitize(input)).to eq(a_tag)
end
end
- describe "link_to" do
+ 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>")
+ 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>")
+ 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 re=nofollow for external links and honor existing html_options" do
+ it 'should include re=nofollow for external links and honor existing html_options' do
expect(
- link_to("Example", "http://www.example.com", class: "toggle", data: {toggle: "dropdown"})
+ 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 preserver other rel values" do
+ it 'should include rel=nofollow for external links and preserver other rel values' do
expect(
- link_to("Example", "http://www.example.com", rel: "noreferrer")
+ link_to('Example', 'http://www.example.com', rel: 'noreferrer')
).to eq("<a href=\"http://www.example.com\" rel=\"noreferrer nofollow\">Example</a>")
end
end
@@ -222,7 +251,7 @@ describe ApplicationHelper do
let(:content) { 'Noël' }
it 'should preserve encoding' do
- content.encoding.name.should == 'UTF-8'
+ expect(content.encoding.name).to eq('UTF-8')
expect(render_markup('foo.rst', content).encoding.name).to eq('UTF-8')
end
end
diff --git a/spec/helpers/broadcast_messages_helper_spec.rb b/spec/helpers/broadcast_messages_helper_spec.rb
index 1338ce4873d..f6df12662bb 100644
--- a/spec/helpers/broadcast_messages_helper_spec.rb
+++ b/spec/helpers/broadcast_messages_helper_spec.rb
@@ -6,7 +6,7 @@ describe BroadcastMessagesHelper do
context "default style" do
it "should have no style" do
- broadcast_styling(broadcast_message).should match('')
+ expect(broadcast_styling(broadcast_message)).to match('')
end
end
@@ -14,7 +14,8 @@ describe BroadcastMessagesHelper do
before { broadcast_message.stub(color: "#f2dede", font: "#b94a48") }
it "should have a customized style" do
- broadcast_styling(broadcast_message).should match('background-color:#f2dede;color:#b94a48')
+ expect(broadcast_styling(broadcast_message)).
+ to match('background-color:#f2dede;color:#b94a48')
end
end
end
diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb
index b07742a6ee2..5bd09793b11 100644
--- a/spec/helpers/diff_helper_spec.rb
+++ b/spec/helpers/diff_helper_spec.rb
@@ -10,58 +10,61 @@ describe DiffHelper do
describe 'diff_hard_limit_enabled?' do
it 'should return true if param is provided' do
- controller.stub(:params).and_return { { :force_show_diff => true } }
- diff_hard_limit_enabled?.should be_true
+ 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
- diff_hard_limit_enabled?.should be_false
+ 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
- controller.stub(:params).and_return { { :force_show_diff => true } }
- allowed_diff_size.should eq(1000)
+ 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
- allowed_diff_size.should eq(100)
+ 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
- parallel_diff(diff_file, 0).should match_array(parallel_diff_result_array)
+ 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
- generate_line_code(diff_file.file_path, diff_file.diff_lines.first).should == '2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6'
+ 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
- unfold_bottom_class(false).should == ''
+ expect(unfold_bottom_class(false)).to eq('')
end
it 'should return js class when bottom lines should be unfolded' do
- unfold_bottom_class(true).should == 'js-unfold-bottom'
+ 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
- diff_line_content(nil).should eq(" &nbsp;")
+ expect(diff_line_content(nil)).to eq(' &nbsp;')
end
it 'should return the line itself' do
- diff_line_content(diff_file.diff_lines.first.text).should eq("@@ -6,12 +6,18 @@ module Popen")
- diff_line_content(diff_file.diff_lines.first.type).should eq("match")
- diff_line_content(diff_file.diff_lines.first.new_pos).should eq(6)
+ 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
diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb
new file mode 100644
index 00000000000..b392371deb4
--- /dev/null
+++ b/spec/helpers/events_helper_spec.rb
@@ -0,0 +1,65 @@
+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
index c75773ad321..3a884d39bf1 100644
--- a/spec/helpers/gitlab_markdown_helper_spec.rb
+++ b/spec/helpers/gitlab_markdown_helper_spec.rb
@@ -1,4 +1,4 @@
-require "spec_helper"
+require 'spec_helper'
describe GitlabMarkdownHelper do
include ApplicationHelper
@@ -9,6 +9,7 @@ describe GitlabMarkdownHelper do
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) }
@@ -23,71 +24,120 @@ describe GitlabMarkdownHelper do
@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}"
- gfm(actual).should_not == actual
+ expect(gfm(actual)).not_to eq(actual)
@project = nil
- gfm(actual).should == actual
+ 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."
- gfm(actual).should == expected
+ expect(gfm(actual)).to eq(expected)
end
it "should not touch HTML entities" do
- @project.issues.stub(:where).with(id: '39').and_return([issue])
+ allow(@project.issues).to receive(:where).
+ with(id: '39').and_return([issue])
actual = 'We&#39;ll accept good pull requests.'
- gfm(actual).should == "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
- gfm("Fixed in #{commit.id}", @project, class: 'foo').
- should have_selector('a.gfm.foo')
+ 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) { project_commit_path(project, commit) }
+ let(:expected) { namespace_project_commit_path(project.namespace, project, commit) }
it "should link using a full id" do
actual = "Reverts #{commit.id}"
- gfm(actual).should match(expected)
+ expect(gfm(actual)).to match(expected)
end
it "should link using a short id" do
- actual = "Backported from #{commit.short_id(6)}"
- gfm(actual).should match(expected)
+ 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})"
- gfm(actual).should match(expected)
+ 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/
- gfm(actual).should match(expected)
+ expect(gfm(actual)).to match(expected)
end
it "should not link with an invalid id" do
actual = expected = "What happened in #{commit.id.reverse}"
- gfm(actual).should == expected
+ expect(gfm(actual)).to eq(expected)
end
it "should include a title attribute" do
actual = "Reverts #{commit.id}"
- gfm(actual).should match(/title="#{commit.link_title}"/)
+ expect(gfm(actual)).to match(/title="#{commit.link_title}"/)
end
it "should include standard gfm classes" do
actual = "Reverts #{commit.id}"
- gfm(actual).should match(/class="\s?gfm gfm-commit\s?"/)
+ expect(gfm(actual)).to match(/class="\s?gfm gfm-commit\s?"/)
end
end
@@ -100,37 +150,37 @@ describe GitlabMarkdownHelper do
end
it "should link using a simple name" do
- gfm(actual).should match(expected)
+ expect(gfm(actual)).to match(expected)
end
it "should link using a name with dots" do
user.update_attributes(name: "alphA.Beta")
- gfm(actual).should match(expected)
+ expect(gfm(actual)).to match(expected)
end
it "should link using name with underscores" do
user.update_attributes(name: "ping_pong_king")
- gfm(actual).should match(expected)
+ expect(gfm(actual)).to match(expected)
end
it "should link with adjacent text" do
actual = "Mail the admin (@#{user.username})"
- gfm(actual).should match(expected)
+ 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/
- gfm(actual).should match(expected)
+ expect(gfm(actual)).to match(expected)
end
it "should not link with an invalid id" do
actual = expected = "@#{user.username.reverse} you are right."
- gfm(actual).should == expected
+ expect(gfm(actual)).to eq(expected)
end
it "should include standard gfm classes" do
- gfm(actual).should match(/class="\s?gfm gfm-team_member\s?"/)
+ expect(gfm(actual)).to match(/class="\s?gfm gfm-project_member\s?"/)
end
end
@@ -144,40 +194,41 @@ describe GitlabMarkdownHelper do
# Currently limited to Snippets, Issues and MergeRequests
shared_examples 'referenced object' do
let(:actual) { "Reference to #{reference}" }
- let(:expected) { polymorphic_path([project, object]) }
+ let(:expected) { polymorphic_path([project.namespace, project, object]) }
it "should link using a valid id" do
- gfm(actual).should match(expected)
+ expect(gfm(actual)).to match(expected)
end
it "should link with adjacent text" do
# Wrap the reference in parenthesis
- gfm(actual.gsub(reference, "(#{reference})")).should match(expected)
+ expect(gfm(actual.gsub(reference, "(#{reference})"))).to match(expected)
# Append some text to the end of the reference
- gfm(actual.gsub(reference, "#{reference}, right?")).should match(expected)
+ 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/
- gfm(actual).should match(expected)
+ 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))
- gfm(actual).should == actual
+ expect(gfm(actual)).to eq(actual)
end
it "should include a title attribute" do
title = "#{object.class.to_s.titlecase}: #{object.title}"
- gfm(actual).should match(/title="#{title}"/)
+ expect(gfm(actual)).to match(/title="#{title}"/)
end
it "should include standard gfm classes" do
css = object.class.to_s.underscore
- gfm(actual).should match(/class="\s?gfm gfm-#{css}\s?"/)
+ expect(gfm(actual)).to match(/class="\s?gfm gfm-#{css}\s?"/)
end
end
@@ -196,34 +247,33 @@ describe GitlabMarkdownHelper do
let(:actual) { "Reference to #{full_reference}" }
let(:expected) do
if object.is_a?(Commit)
- project_commit_path(@other_project, object)
+ namespace_project_commit_path(@other_project.namespace, @other_project, object)
else
- polymorphic_path([@other_project, object])
+ polymorphic_path([@other_project.namespace, @other_project, object])
end
end
it 'should link using a valid id' do
- gfm(actual).should match(
+ expect(gfm(actual)).to match(
/#{expected}.*#{Regexp.escape(full_reference)}/
)
end
it 'should link with adjacent text' do
# Wrap the reference in parenthesis
- gfm(actual.gsub(full_reference, "(#{full_reference})")).should(
+ expect(gfm(actual.gsub(full_reference, "(#{full_reference})"))).to(
match(expected)
)
# Append some text to the end of the reference
- gfm(actual.gsub(full_reference, "#{full_reference}, right?")).should(
- match(expected)
- )
+ 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/
- gfm(actual).should match(expected)
+ expect(gfm(actual)).to match(expected)
end
it 'should not link with an invalid id' do
@@ -233,7 +283,7 @@ describe GitlabMarkdownHelper do
else
reference.gsub!(/^(.)(\d+)$/, '\1' + ('\2' * 2))
end
- gfm(actual).should == actual
+ expect(gfm(actual)).to eq(actual)
end
it 'should include a title attribute' do
@@ -242,12 +292,12 @@ describe GitlabMarkdownHelper do
else
title = "#{object.class.to_s.titlecase}: #{object.title}"
end
- gfm(actual).should match(/title="#{title}"/)
+ expect(gfm(actual)).to match(/title="#{title}"/)
end
it 'should include standard gfm classes' do
css = object.class.to_s.underscore
- gfm(actual).should match(/class="\s?gfm gfm-#{css}\s?"/)
+ expect(gfm(actual)).to match(/class="\s?gfm gfm-#{css}\s?"/)
end
end
@@ -296,43 +346,47 @@ describe GitlabMarkdownHelper do
let(:reference) { "JIRA-#{issue.iid}" }
before do
- issue_tracker_config = { "jira" => { "title" => "JIRA tracker", "issues_url" => "http://jira.example/browse/:id" } }
- Gitlab.config.stub(:issues_tracker).and_return(issue_tracker_config)
- @project.stub(:issues_tracker).and_return("jira")
- @project.stub(:issues_tracker_id).and_return("JIRA")
+ 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
- gfm(actual).should match(expected)
+ expect(gfm(actual)).to match(expected)
end
it "should link with adjacent text" do
# Wrap the reference in parenthesis
- gfm(actual.gsub(reference, "(#{reference})")).should match(expected)
+ expect(gfm(actual.gsub(reference, "(#{reference})"))).to match(expected)
# Append some text to the end of the reference
- gfm(actual.gsub(reference, "#{reference}, right?")).should match(expected)
+ 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/
- gfm(actual).should match(expected)
+ 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")
- gfm(invalid_reference).should == invalid_reference
+ expect(gfm(invalid_reference)).to eq(invalid_reference)
end
it "should include a title attribute" do
title = "Issue in JIRA tracker"
- gfm(actual).should match(/title="#{title}"/)
+ expect(gfm(actual)).to match(/title="#{title}"/)
end
it "should include standard gfm classes" do
- gfm(actual).should match(/class="\s?gfm gfm-issue\s?"/)
+ expect(gfm(actual)).to match(/class="\s?gfm gfm-issue\s?"/)
end
end
@@ -347,40 +401,40 @@ describe GitlabMarkdownHelper do
let(:object) { snippet }
let(:reference) { "$#{snippet.id}" }
let(:actual) { "Reference to #{reference}" }
- let(:expected) { project_snippet_path(project, object) }
+ let(:expected) { namespace_project_snippet_path(project.namespace, project, object) }
it "should link using a valid id" do
- gfm(actual).should match(expected)
+ expect(gfm(actual)).to match(expected)
end
it "should link with adjacent text" do
# Wrap the reference in parenthesis
- gfm(actual.gsub(reference, "(#{reference})")).should match(expected)
+ expect(gfm(actual.gsub(reference, "(#{reference})"))).to match(expected)
# Append some text to the end of the reference
- gfm(actual.gsub(reference, "#{reference}, right?")).should match(expected)
+ 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/
- gfm(actual).should match(expected)
+ 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))
- gfm(actual).should == actual
+ expect(gfm(actual)).to eq(actual)
end
it "should include a title attribute" do
title = "Snippet: #{object.title}"
- gfm(actual).should match(/title="#{title}"/)
+ expect(gfm(actual)).to match(/title="#{title}"/)
end
it "should include standard gfm classes" do
css = object.class.to_s.underscore
- gfm(actual).should match(/class="\s?gfm gfm-snippet\s?"/)
+ expect(gfm(actual)).to match(/class="\s?gfm gfm-snippet\s?"/)
end
end
@@ -389,70 +443,70 @@ describe GitlabMarkdownHelper do
let(:actual) { "!#{merge_request.iid} -> #{commit.id} -> ##{issue.iid}" }
it "should link to the merge request" do
- expected = project_merge_request_path(project, merge_request)
- gfm(actual).should match(expected)
+ 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 = project_commit_path(project, commit)
- gfm(actual).should match(expected)
+ expected = namespace_project_commit_path(project.namespace, project, commit)
+ expect(gfm(actual)).to match(expected)
end
it "should link to the issue" do
- expected = project_issue_path(project, issue)
- gfm(actual).should match(expected)
+ 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
- gfm(":+1:").should match(/<img/)
+ expect(gfm(":+1:")).to match(/<img/)
end
it "matches at the end of a string" do
- gfm("This gets a :-1:").should match(/<img/)
+ expect(gfm("This gets a :-1:")).to match(/<img/)
end
it "matches with adjacent text" do
- gfm("+1 (:+1:)").should match(/<img/)
+ expect(gfm("+1 (:+1:)")).to match(/<img/)
end
it "has a title attribute" do
- gfm(":-1:").should match(/title=":-1:"/)
+ expect(gfm(":-1:")).to match(/title=":-1:"/)
end
it "has an alt attribute" do
- gfm(":-1:").should match(/alt=":-1:"/)
+ expect(gfm(":-1:")).to match(/alt=":-1:"/)
end
it "has an emoji class" do
- gfm(":+1:").should match('class="emoji"')
+ expect(gfm(":+1:")).to match('class="emoji"')
end
it "sets height and width" do
actual = gfm(":+1:")
- actual.should match(/width="20"/)
- actual.should match(/height="20"/)
+ expect(actual).to match(/width="20"/)
+ expect(actual).to match(/height="20"/)
end
it "keeps whitespace intact" do
- gfm('This deserves a :+1: big time.').
- should match(/deserves a <img.+> big time/)
+ expect(gfm('This deserves a :+1: big time.')).
+ to match(/deserves a <img.+> big time/)
end
it "ignores invalid emoji" do
- gfm(":invalid-emoji:").should_not match(/<img/)
+ 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
- gfm(":+1:").should match(/<img/)
+ expect(gfm(":+1:")).to match(/<img/)
end
end
end
describe "#link_to_gfm" do
- let(:commit_path) { project_commit_path(project, commit) }
+ 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
@@ -463,60 +517,67 @@ describe GitlabMarkdownHelper do
groups = actual.split("</a>")
# Leading commit link
- groups[0].should match(/href="#{commit_path}"/)
- groups[0].should match(/This should finally fix $/)
+ expect(groups[0]).to match(/href="#{commit_path}"/)
+ expect(groups[0]).to match(/This should finally fix $/)
# First issue link
- groups[1].should match(/href="#{project_issue_url(project, issues[0])}"/)
- groups[1].should match(/##{issues[0].iid}$/)
+ 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
- groups[2].should match(/href="#{commit_path}"/)
- groups[2].should match(/ and /)
+ expect(groups[2]).to match(/href="#{commit_path}"/)
+ expect(groups[2]).to match(/ and /)
# Second issue link
- groups[3].should match(/href="#{project_issue_url(project, issues[1])}"/)
- groups[3].should match(/##{issues[1].iid}$/)
+ 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
- groups[4].should match(/href="#{commit_path}"/)
- groups[4].should match(/ for real$/)
+ 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')
- actual.should have_selector 'a.gfm.gfm-commit.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}"
- link_to_gfm(actual, commit_path).should match('&lt;h1&gt;test&lt;/h1&gt;')
+ expect(link_to_gfm(actual, commit_path)).
+ to match('&lt;h1&gt;test&lt;/h1&gt;')
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 = project_commit_path(project, commit)
- markdown(actual).should match(expected)
+ 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}"
- markdown(actual, {no_header_anchors:true}).should match(%r{<h1[^<]*>Working around <a.+>##{issue.iid}</a></h1>})
- markdown(actual, {no_header_anchors:true}).should match(%r{<h2[^<]*>Apply <a.+>!#{merge_request.iid}</a></h2>})
+ 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'
- markdown("# #{text}").should match(%r{<h1 id="#{id}">#{text}<a href="[^"]*##{id}"></a></h1>})
- markdown("# #{text}", {no_header_anchors:true}).should == "<h1>#{text}</h1>"
+ 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'
- markdown("# [link text](url) ![img alt](url)").should match(
+ 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
@@ -526,14 +587,37 @@ describe GitlabMarkdownHelper do
actual = "\n* dark: ##{issue.iid}\n* light by @#{member.user.username}"
- markdown(actual).should match(%r{<li>dark: <a.+>##{issue.iid}</a></li>})
- markdown(actual).should match(%r{<li>light by <a.+>@#{member.user.username}</a></li>})
+ 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"
- markdown(actual).should match(%r{Apply <em><a.+>!#{merge_request.iid}</a></em>})
+ expect(markdown(actual)).
+ to match(%r{Apply <em><a.+>!#{merge_request.iid}</a></em>})
end
it "should handle tables" do
@@ -542,77 +626,106 @@ describe GitlabMarkdownHelper do
| cell 1 | cell 2 |
| cell 3 | cell 4 |}
- markdown(actual).should match(/\A<table/)
+ expect(markdown(actual)).to match(/\A<table/)
end
it "should leave code blocks untouched" do
- helper.stub(:user_color_scheme_class).and_return(:white)
+ allow(helper).to receive(:user_color_scheme_class).and_return(:white)
- target_html = "\n<div class=\"highlighted-data white\">\n <div class=\"highlight\">\n <pre><code class=\"\">some code from $#{snippet.id}\nhere too\n</code></pre>\n </div>\n</div>\n\n"
+ target_html = "<pre class=\"code highlight white plaintext\"><code>some code from $#{snippet.id}\nhere too\n</code></pre>\n"
- helper.markdown("\n some code from $#{snippet.id}\n here too\n").should == target_html
- helper.markdown("\n```\nsome code from $#{snippet.id}\nhere too\n```\n").should == target_html
+ 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
- markdown("\nDon't use `$#{snippet.id}` here.\n").should ==
+ 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
- markdown("look at http://example.tld/#!#{merge_request.iid}").should == "<p>look at <a href=\"http://example.tld/#!#{merge_request.iid}\">http://example.tld/#!#{merge_request.iid}</a></p>\n"
+ 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
- markdown("why not [inspect !#{merge_request.iid}](http://example.tld/#!#{merge_request.iid})").should == "<p>why not <a href=\"http://example.tld/#!#{merge_request.iid}\">inspect </a><a class=\"gfm gfm-merge_request \" href=\"#{project_merge_request_url(project, merge_request)}\" title=\"Merge Request: #{merge_request.title}\">!#{merge_request.iid}</a><a href=\"http://example.tld/#!#{merge_request.iid}\"></a></p>\n"
+ 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_url(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
- markdown("screen shot: ![some image](http://example.tld/#!#{merge_request.iid})").should == "<p>screen shot: <img src=\"http://example.tld/#!#{merge_request.iid}\" alt=\"some image\"></p>\n"
+ 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
- markdown("##{issue.iid}").should include(project_issue_url(project, issue))
+ expect(markdown("##{issue.iid}")).to include(namespace_project_issue_path(project.namespace, project, issue))
end
it "should generate absolute urls for emoji" do
- markdown(":smile:").should include("src=\"#{url_helper('emoji/smile')}")
+ 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"
- markdown(actual).should match(expected)
+ 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"
- markdown(actual).should match(expected)
+ 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"
- markdown(actual).should match(expected)
+ 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"
- markdown(actual).should match(expected)
+ 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"
- markdown(actual).should match(expected)
+ 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 = ""
- markdown(actual).should match(expected)
+ expect(markdown(actual)).to match(expected)
end
it 'should allow whitelisted HTML tags from the user' do
@@ -655,29 +768,29 @@ describe GitlabMarkdownHelper do
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"
- markdown(actual).should match(expected)
+ expect(markdown(actual)).to match(expected)
end
end
describe "#render_wiki_content" do
before do
@wiki = double('WikiPage')
- @wiki.stub(:content).and_return('wiki content')
+ allow(@wiki).to receive(:content).and_return('wiki content')
end
it "should use GitLab Flavored Markdown for markdown files" do
- @wiki.stub(:format).and_return(:markdown)
+ allow(@wiki).to receive(:format).and_return(:markdown)
- helper.should_receive(:markdown).with('wiki content')
+ 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
- @wiki.stub(:format).and_return(:rdoc)
+ allow(@wiki).to receive(:format).and_return(:rdoc)
formatted_content_stub = double('formatted_content')
- formatted_content_stub.should_receive(:html_safe)
- @wiki.stub(:formatted_content).and_return(formatted_content_stub)
+ 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
diff --git a/spec/helpers/groups_helper.rb b/spec/helpers/groups_helper.rb
new file mode 100644
index 00000000000..3e99ab84ec9
--- /dev/null
+++ b/spec/helpers/groups_helper.rb
@@ -0,0 +1,21 @@
+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/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb
index 9c95bc044f3..54dd8d4aa64 100644
--- a/spec/helpers/issues_helper_spec.rb
+++ b/spec/helpers/issues_helper_spec.rb
@@ -5,133 +5,132 @@ describe IssuesHelper do
let(:issue) { create :issue, project: project }
let(:ext_project) { create :redmine_project }
- describe :title_for_issue do
+ describe "title_for_issue" do
it "should return issue title if used internal tracker" do
@project = project
- title_for_issue(issue.iid).should eq issue.title
+ 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
- title_for_issue(rand(100)).should eq ""
+ expect(title_for_issue(rand(100))).to eq ""
end
it "should always return empty string if project nil" do
@project = nil
- title_for_issue(rand(100)).should eq ""
+ expect(title_for_issue(rand(100))).to eq ""
end
end
- describe :url_for_project_issues do
- let(:project_url) { Gitlab.config.issues_tracker.redmine.project_url}
+ 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]) }
+ let(:int_expected) { polymorphic_path([@project.namespace, project]) }
it "should return internal path if used internal tracker" do
@project = project
- url_for_project_issues.should match(int_expected)
+ expect(url_for_project_issues).to match(int_expected)
end
it "should return path to external tracker" do
@project = ext_project
- url_for_project_issues.should match(ext_expected)
+ expect(url_for_project_issues).to match(ext_expected)
end
it "should return empty string if project nil" do
@project = nil
- url_for_project_issues.should eq ""
+ expect(url_for_project_issues).to eq ""
end
describe "when external tracker was enabled and then config removed" do
before do
@project = ext_project
- Gitlab.config.stub(:issues_tracker).and_return(nil)
+ allow(Gitlab.config).to receive(:issues_tracker).and_return(nil)
end
- it "should return path to internal tracker" do
- url_for_project_issues.should match(polymorphic_path([@project]))
+ 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(:issue_id) { 3 }
- let(:issues_url) { Gitlab.config.issues_tracker.redmine.issues_url}
+ describe "url_for_issue" do
+ let(:issues_url) { ext_project.external_issue_tracker.issues_url}
let(:ext_expected) do
- issues_url.gsub(':id', issue_id.to_s)
+ 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, issue]) }
+ let(:int_expected) { polymorphic_path([@project.namespace, project, issue]) }
it "should return internal path if used internal tracker" do
@project = project
- url_for_issue(issue.iid).should match(int_expected)
+ expect(url_for_issue(issue.iid)).to match(int_expected)
end
it "should return path to external tracker" do
@project = ext_project
- url_for_issue(issue_id).should match(ext_expected)
+ expect(url_for_issue(issue.iid)).to match(ext_expected)
end
it "should return empty string if project nil" do
@project = nil
- url_for_issue(issue.iid).should eq ""
+ 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
- Gitlab.config.stub(:issues_tracker).and_return(nil)
+ allow(Gitlab.config).to receive(:issues_tracker).and_return(nil)
end
- it "should return internal path" do
- url_for_issue(issue.iid).should match(polymorphic_path([@project, issue]))
+ 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) { Gitlab.config.issues_tracker.redmine.new_issue_url}
+ 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_project_issue_path(project) }
+ let(:int_expected) { new_namespace_project_issue_path(project.namespace, project) }
it "should return internal path if used internal tracker" do
@project = project
- url_for_new_issue.should match(int_expected)
+ expect(url_for_new_issue).to match(int_expected)
end
it "should return path to external tracker" do
@project = ext_project
- url_for_new_issue.should match(ext_expected)
+ expect(url_for_new_issue).to match(ext_expected)
end
it "should return empty string if project nil" do
@project = nil
- url_for_new_issue.should eq ""
+ expect(url_for_new_issue).to eq ""
end
describe "when external tracker was enabled and then config removed" do
before do
@project = ext_project
- Gitlab.config.stub(:issues_tracker).and_return(nil)
+ allow(Gitlab.config).to receive(:issues_tracker).and_return(nil)
end
it "should return internal path" do
- url_for_new_issue.should match(new_project_issue_path(@project))
+ expect(url_for_new_issue).to match(ext_expected)
end
end
end
diff --git a/spec/helpers/merge_requests_helper.rb b/spec/helpers/merge_requests_helper.rb
index 5a317c4886b..5262d644048 100644
--- a/spec/helpers/merge_requests_helper.rb
+++ b/spec/helpers/merge_requests_helper.rb
@@ -7,6 +7,6 @@ describe MergeRequestsHelper do
[build(:issue, iid: 1), build(:issue, iid: 2), build(:issue, iid: 3)]
end
- it { should eq('#1, #2, and #3') }
+ 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
new file mode 100644
index 00000000000..e4d18d8bfc6
--- /dev/null
+++ b/spec/helpers/nav_helper_spec.rb
@@ -0,0 +1,25 @@
+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
index 31ecdacf28e..482cb33e94f 100644
--- a/spec/helpers/notifications_helper_spec.rb
+++ b/spec/helpers/notifications_helper_spec.rb
@@ -1,6 +1,9 @@
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) }
@@ -8,7 +11,7 @@ describe NotificationsHelper do
before { notification.stub(disabled?: true) }
it "has a red icon" do
- notification_icon(notification).should match('class="fa fa-volume-off ns-mute"')
+ expect(notification_icon(notification)).to match('class="fa fa-volume-off ns-mute"')
end
end
@@ -16,7 +19,7 @@ describe NotificationsHelper do
before { notification.stub(participating?: true) }
it "has a blue icon" do
- notification_icon(notification).should match('class="fa fa-volume-down ns-part"')
+ expect(notification_icon(notification)).to match('class="fa fa-volume-down ns-part"')
end
end
@@ -24,12 +27,12 @@ describe NotificationsHelper do
before { notification.stub(watch?: true) }
it "has a green icon" do
- notification_icon(notification).should match('class="fa fa-volume-up ns-watch"')
+ expect(notification_icon(notification)).to match('class="fa fa-volume-up ns-watch"')
end
end
it "has a blue icon" do
- notification_icon(notification).should match('class="fa fa-circle-o ns-default"')
+ 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
new file mode 100644
index 00000000000..088c342fa13
--- /dev/null
+++ b/spec/helpers/oauth_helper_spec.rb
@@ -0,0 +1,20 @@
+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
index 114058e3095..0f78725e3d9 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -1,23 +1,11 @@
require 'spec_helper'
describe ProjectsHelper do
- describe '#project_issues_trackers' do
- it "returns the correct issues trackers available" do
- project_issues_trackers.should ==
- "<option value=\"redmine\">Redmine</option>\n" \
- "<option value=\"gitlab\">GitLab</option>"
- end
-
- it "returns the correct issues trackers available with current tracker 'gitlab' selected" do
- project_issues_trackers('gitlab').should ==
- "<option value=\"redmine\">Redmine</option>\n" \
- "<option selected=\"selected\" value=\"gitlab\">GitLab</option>"
- end
-
- it "returns the correct issues trackers available with current tracker 'redmine' selected" do
- project_issues_trackers('redmine').should ==
- "<option selected=\"selected\" value=\"redmine\">Redmine</option>\n" \
- "<option value=\"gitlab\">GitLab</option>"
+ 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
index 733f2754727..b327f4f911a 100644
--- a/spec/helpers/search_helper_spec.rb
+++ b/spec/helpers/search_helper_spec.rb
@@ -13,7 +13,7 @@ describe SearchHelper do
end
it "it returns nil" do
- search_autocomplete_opts("q").should be_nil
+ expect(search_autocomplete_opts("q")).to be_nil
end
end
@@ -25,29 +25,29 @@ describe SearchHelper do
end
it "includes Help sections" do
- search_autocomplete_opts("hel").size.should == 9
+ expect(search_autocomplete_opts("hel").size).to eq(9)
end
it "includes default sections" do
- search_autocomplete_opts("adm").size.should == 1
+ expect(search_autocomplete_opts("adm").size).to eq(1)
end
it "includes the user's groups" do
create(:group).add_owner(user)
- search_autocomplete_opts("gro").size.should == 1
+ 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))
- search_autocomplete_opts(project.name).size.should == 1
+ 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
- search_autocomplete_opts("Files").size.should == 1
- search_autocomplete_opts("Commits").size.should == 1
+ expect(search_autocomplete_opts("Files").size).to eq(1)
+ expect(search_autocomplete_opts("Commits").size).to eq(1)
end
end
end
diff --git a/spec/helpers/submodule_helper_spec.rb b/spec/helpers/submodule_helper_spec.rb
index 41c9f038c26..aef1108e333 100644
--- a/spec/helpers/submodule_helper_spec.rb
+++ b/spec/helpers/submodule_helper_spec.rb
@@ -19,28 +19,28 @@ describe SubmoduleHelper 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(''))
- submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ]
+ 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(''))
- submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ]
+ 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(''))
- submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ]
+ 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(''))
- submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ]
+ 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
@@ -48,67 +48,67 @@ describe SubmoduleHelper do
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(''))
- submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ]
+ 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')
- submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ]
+ 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')
- submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ]
+ 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')
- submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ]
+ 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')
- submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ]
+ expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ])
stub_url('http://github.com/another/gitlab-org/gitlab-ce.git')
- submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ]
+ 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')
- submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ]
+ 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')
- submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ]
+ 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')
- submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ]
+ 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')
- submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ]
+ expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ])
stub_url('http://gitlab.com/another/gitlab-org/gitlab-ce.git')
- submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ]
+ 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')
- submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ]
+ expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ])
stub_url('http://mygitserver.com/gitlab-org/gitlab-ce.git')
- submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ]
+ expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ])
end
end
end
diff --git a/spec/helpers/tab_helper_spec.rb b/spec/helpers/tab_helper_spec.rb
index fa8a3f554f7..fc0ceecfbe7 100644
--- a/spec/helpers/tab_helper_spec.rb
+++ b/spec/helpers/tab_helper_spec.rb
@@ -5,40 +5,40 @@ describe TabHelper do
describe 'nav_link' do
before do
- controller.stub(:controller_name).and_return('foo')
+ allow(controller).to receive(:controller_name).and_return('foo')
allow(self).to receive(:action_name).and_return('foo')
end
it "captures block output" do
- nav_link { "Testing Blocks" }.should match(/Testing Blocks/)
+ expect(nav_link { "Testing Blocks" }).to match(/Testing Blocks/)
end
it "performs checks on the current controller" do
- nav_link(controller: :foo).should match(/<li class="active">/)
- nav_link(controller: :bar).should_not match(/active/)
- nav_link(controller: [:foo, :bar]).should match(/active/)
+ 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
- nav_link(action: :foo).should match(/<li class="active">/)
- nav_link(action: :bar).should_not match(/active/)
- nav_link(action: [:foo, :bar]).should match(/active/)
+ 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
- nav_link(controller: :bar, action: :foo).should_not match(/active/)
- nav_link(controller: :foo, action: :bar).should_not match(/active/)
- nav_link(controller: :foo, action: :foo).should match(/active/)
+ 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
- nav_link(path: 'foo#bar').should_not match(/active/)
- nav_link(path: 'foo#foo').should match(/active/)
+ 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
- nav_link(action: :foo, html_options: {class: 'home'}).should match(/<li class="home active">/)
- nav_link(html_options: {class: 'active'}).should match(/<li class="active">/)
+ 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
new file mode 100644
index 00000000000..8271e00f41b
--- /dev/null
+++ b/spec/helpers/tree_helper_spec.rb
@@ -0,0 +1,28 @@
+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