summaryrefslogtreecommitdiff
path: root/spec/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/application_helper_spec.rb76
-rw-r--r--spec/helpers/broadcast_messages_helper_spec.rb21
-rw-r--r--spec/helpers/gitlab_markdown_helper_spec.rb56
-rw-r--r--spec/helpers/issues_helper_spec.rb33
-rw-r--r--spec/helpers/notifications_helper_spec.rb42
-rw-r--r--spec/helpers/projects_helper_spec.rb23
-rw-r--r--spec/helpers/search_helper_spec.rb55
-rw-r--r--spec/helpers/tab_helper_spec.rb4
8 files changed, 279 insertions, 31 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 229f49659cf..c58c83a2970 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe ApplicationHelper do
describe 'current_controller?' do
before do
- controller.stub!(:controller_name).and_return('foo')
+ controller.stub(:controller_name).and_return('foo')
end
it "returns true when controller matches argument" do
@@ -22,7 +22,7 @@ describe ApplicationHelper do
describe 'current_action?' do
before do
- stub!(:action_name).and_return('foo')
+ allow(self).to receive(:action_name).and_return('foo')
end
it "returns true when action matches argument" do
@@ -39,46 +39,81 @@ describe ApplicationHelper do
end
end
+ 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!
+ group_icon(group.path).to_s.should == "/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!
+ group_icon(group.path).to_s.should == "/assets/no_group_avatar.png"
+ 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!
+ avatar_icon(user.email).to_s.should == "/uploads/user/avatar/#{ user.id }/gitlab_logo.png"
+ end
+
+ it "should call gravatar_icon when no avatar is present" do
+ user = create(:user)
+ user.save!
+ allow(self).to receive(:gravatar_icon).and_return('gravatar_method_called')
+ avatar_icon(user.email).to_s.should == "gravatar_method_called"
+ end
+ end
+
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 == 'no_avatar.png'
+ gravatar_icon(user_email).should == '/assets/no_avatar.png'
end
it "should return a generic avatar path when email is blank" do
- gravatar_icon('').should == 'no_avatar.png'
+ gravatar_icon('').should == '/assets/no_avatar.png'
end
it "should return default gravatar url" do
- stub!(:request).and_return(double(:ssl? => false))
+ allow(self).to receive(:request).and_return(double(:ssl? => false))
gravatar_icon(user_email).should match('http://www.gravatar.com/avatar/b58c6f14d292556214bd64909bcdb118')
end
it "should use SSL when appropriate" do
- stub!(:request).and_return(double(:ssl? => true))
+ allow(self).to receive(:request).and_return(double(:ssl? => true))
gravatar_icon(user_email).should match('https://secure.gravatar.com')
end
it "should return custom gravatar path when gravatar_url is set" do
- stub!(:request).and_return(double(:ssl? => false))
+ 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'
end
it "should accept a custom size" do
- stub!(:request).and_return(double(:ssl? => false))
+ allow(self).to receive(:request).and_return(double(:ssl? => false))
gravatar_icon(user_email, 64).should match(/\?s=64/)
end
it "should use default size when size is wrong" do
- stub!(:request).and_return(double(:ssl? => false))
+ allow(self).to receive(:request).and_return(double(:ssl? => false))
gravatar_icon(user_email, nil).should match(/\?s=40/)
end
it "should be case insensitive" do
- stub!(:request).and_return(double(:ssl? => false))
+ allow(self).to receive(:request).and_return(double(:ssl? => false))
gravatar_icon(user_email).should == gravatar_icon(user_email.upcase + " ")
end
@@ -87,7 +122,7 @@ describe ApplicationHelper do
describe "user_color_scheme_class" do
context "with current_user is nil" do
it "should return a string" do
- stub!(:current_user).and_return(nil)
+ allow(self).to receive(:current_user).and_return(nil)
user_color_scheme_class.should be_kind_of(String)
end
end
@@ -97,7 +132,7 @@ describe ApplicationHelper do
context "with color_scheme_id == #{color_scheme_id}" do
it "should return a string" do
current_user = double(:color_scheme_id => color_scheme_id)
- stub!(:current_user).and_return(current_user)
+ allow(self).to receive(:current_user).and_return(current_user)
user_color_scheme_class.should be_kind_of(String)
end
end
@@ -105,4 +140,21 @@ describe ApplicationHelper do
end
end
+ describe "simple_sanitize" do
+ let(:a_tag) { '<a href="#">Foo</a>' }
+
+ it "allows the a tag" do
+ simple_sanitize(a_tag).should == a_tag
+ end
+
+ it "allows the span tag" do
+ input = '<span class="foo">Bar</span>'
+ simple_sanitize(input).should == input
+ end
+
+ it "disallows other tags" do
+ input = "<strike><b>#{a_tag}</b></strike>"
+ simple_sanitize(input).should == a_tag
+ end
+ end
end
diff --git a/spec/helpers/broadcast_messages_helper_spec.rb b/spec/helpers/broadcast_messages_helper_spec.rb
new file mode 100644
index 00000000000..1338ce4873d
--- /dev/null
+++ b/spec/helpers/broadcast_messages_helper_spec.rb
@@ -0,0 +1,21 @@
+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
+ broadcast_styling(broadcast_message).should match('')
+ end
+ end
+
+ context "customiezd style" 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')
+ end
+ end
+ end
+end
diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb
index d49247accc2..59abfb38ec0 100644
--- a/spec/helpers/gitlab_markdown_helper_spec.rb
+++ b/spec/helpers/gitlab_markdown_helper_spec.rb
@@ -4,7 +4,7 @@ describe GitlabMarkdownHelper do
include ApplicationHelper
include IssuesHelper
- let!(:project) { create(:project_with_code) }
+ let!(:project) { create(:project) }
let(:user) { create(:user, username: 'gfm') }
let(:commit) { project.repository.commit }
@@ -16,6 +16,7 @@ describe GitlabMarkdownHelper do
before do
# Helper expects a @project instance variable
@project = project
+ @repository = project.repository
end
describe "#gfm" do
@@ -378,9 +379,10 @@ describe GitlabMarkdownHelper do
it "should leave code blocks untouched" do
helper.stub(:user_color_scheme_class).and_return(:white)
- helper.markdown("\n some code from $#{snippet.id}\n here too\n").should include("<div class=\"white\"><div class=\"highlight\"><pre><span class=\"n\">some</span> <span class=\"n\">code</span> <span class=\"n\">from</span> $#{snippet.id}\n<span class=\"n\">here</span> <span class=\"n\">too</span>\n</pre></div></div>")
+ 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"
- helper.markdown("\n```\nsome code from $#{snippet.id}\nhere too\n```\n").should include("<div class=\"white\"><div class=\"highlight\"><pre><span class=\"n\">some</span> <span class=\"n\">code</span> <span class=\"n\">from</span> $#{snippet.id}\n<span class=\"n\">here</span> <span class=\"n\">too</span>\n</pre></div></div>")
+ 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
end
it "should leave inline code untouched" do
@@ -392,7 +394,7 @@ describe GitlabMarkdownHelper do
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 href=\"#{project_merge_request_url(project, merge_request)}\" class=\"gfm gfm-merge_request \" title=\"Merge Request: #{merge_request.title}\">!#{merge_request.iid}</a><a href=\"http://example.tld/#!#{merge_request.iid}\"></a></p>\n"
+ 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"
end
it "should leave ref-like src of images untouched" do
@@ -406,11 +408,53 @@ describe GitlabMarkdownHelper do
it "should generate absolute urls for emoji" do
markdown(":smile:").should include("src=\"#{url_to_image("emoji/smile")}")
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/master/doc/api/README.md\">GitLab API doc</a></p>\n"
+ markdown(actual).should 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/master/doc/api\">GitLab API doc</a></p>\n"
+ markdown(actual).should 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)
+ end
+
+ it "should handle wiki urls" do
+ actual = "[Link](test/link)\n"
+ expected = "<p><a href=\"/#{project.path_with_namespace}/wikis/test/link\">Link</a></p>\n"
+ markdown(actual).should 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/master/doc/api/README.md\">GitLab API doc</a></p>\n"
+ markdown(actual).should 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/master/doc/api/\">GitLab API doc directory</a></p>\n"
+ markdown(actual).should 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)
+ end
end
describe "#render_wiki_content" do
before do
- @wiki = stub('WikiPage')
+ @wiki = double('WikiPage')
@wiki.stub(:content).and_return('wiki content')
end
@@ -424,7 +468,7 @@ describe GitlabMarkdownHelper do
it "should use the Gollum renderer for all other file types" do
@wiki.stub(:format).and_return(:rdoc)
- formatted_content_stub = stub('formatted_content')
+ formatted_content_stub = double('formatted_content')
formatted_content_stub.should_receive(:html_safe)
@wiki.stub(:formatted_content).and_return(formatted_content_stub)
diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb
index 3595af32431..9c95bc044f3 100644
--- a/spec/helpers/issues_helper_spec.rb
+++ b/spec/helpers/issues_helper_spec.rb
@@ -47,6 +47,17 @@ describe IssuesHelper do
url_for_project_issues.should 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)
+ end
+
+ it "should return path to internal tracker" do
+ url_for_project_issues.should match(polymorphic_path([@project]))
+ end
+ end
end
describe :url_for_issue do
@@ -75,6 +86,17 @@ describe IssuesHelper do
url_for_issue(issue.iid).should 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)
+ end
+
+ it "should return internal path" do
+ url_for_issue(issue.iid).should match(polymorphic_path([@project, issue]))
+ end
+ end
end
describe :url_for_new_issue do
@@ -101,6 +123,17 @@ describe IssuesHelper do
url_for_new_issue.should 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)
+ end
+
+ it "should return internal path" do
+ url_for_new_issue.should match(new_project_issue_path(@project))
+ end
+ end
end
end
diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb
index f97959ee8f4..c1efc1fb2a0 100644
--- a/spec/helpers/notifications_helper_spec.rb
+++ b/spec/helpers/notifications_helper_spec.rb
@@ -1,15 +1,35 @@
require 'spec_helper'
-# Specs in this file have access to a helper object that includes
-# the NotificationsHelper. For example:
-#
-# describe NotificationsHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# helper.concat_strings("this","that").should == "this that"
-# end
-# end
-# end
describe NotificationsHelper do
- pending "add some examples to (or delete) #{__FILE__}"
+ 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
+ notification_icon(notification).should match('class="icon-circle cred"')
+ end
+ end
+
+ context "participating notification" do
+ before { notification.stub(participating?: true) }
+
+ it "has a blue icon" do
+ notification_icon(notification).should match('class="icon-circle cblue"')
+ end
+ end
+
+ context "watched notification" do
+ before { notification.stub(watch?: true) }
+
+ it "has a green icon" do
+ notification_icon(notification).should match('class="icon-circle cgreen"')
+ end
+ end
+
+ it "has a blue icon" do
+ notification_icon(notification).should match('class="icon-circle-blank cblue"')
+ end
+ end
end
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
new file mode 100644
index 00000000000..114058e3095
--- /dev/null
+++ b/spec/helpers/projects_helper_spec.rb
@@ -0,0 +1,23 @@
+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>"
+ end
+ end
+end
diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb
new file mode 100644
index 00000000000..733f2754727
--- /dev/null
+++ b/spec/helpers/search_helper_spec.rb
@@ -0,0 +1,55 @@
+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
+ search_autocomplete_opts("q").should 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
+ search_autocomplete_opts("hel").size.should == 9
+ end
+
+ it "includes default sections" do
+ search_autocomplete_opts("adm").size.should == 1
+ end
+
+ it "includes the user's groups" do
+ create(:group).add_owner(user)
+ search_autocomplete_opts("gro").size.should == 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
+ 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
+ end
+ end
+ end
+ end
+end
diff --git a/spec/helpers/tab_helper_spec.rb b/spec/helpers/tab_helper_spec.rb
index ef8e4cf6375..fa8a3f554f7 100644
--- a/spec/helpers/tab_helper_spec.rb
+++ b/spec/helpers/tab_helper_spec.rb
@@ -5,8 +5,8 @@ describe TabHelper do
describe 'nav_link' do
before do
- controller.stub!(:controller_name).and_return('foo')
- stub!(:action_name).and_return('foo')
+ controller.stub(:controller_name).and_return('foo')
+ allow(self).to receive(:action_name).and_return('foo')
end
it "captures block output" do