diff options
author | Chris Stephan <cstephan@squaremouth.com> | 2013-08-28 22:59:08 -0400 |
---|---|---|
committer | Chris Stephan <cstephan@squaremouth.com> | 2013-09-01 00:11:12 -0400 |
commit | 39e76e123c3023b93bb35d944e9c25c79c20714a (patch) | |
tree | cb435ff3850c6ab6bb362544d787cccf8cae1ab7 /spec | |
parent | b4e7679174e9a1fe6b047e7571ddfadd148e7a78 (diff) | |
download | gitlab-ci-39e76e123c3023b93bb35d944e9c25c79c20714a.tar.gz |
Change gravatar_icon helper to handle ssl
This commit refactors the gravatar_icon helper method to handle ssl.
This is because when running gitlab-ci with ssl enabled, it gives a
warning because portions of the page are not secure. In addition to
refactoring this method, it also adds some configuration values to the
application.yml.example file that are needed for the gravatar_icon
helper method. It also adds default values for settings relating to
gitlab_ci and gravatar. This is because the values will need defaults
if they aren't specified in the application.yml. It also adds the
no_avatar.png since it is being used in the gravatar_icon helper
method. Finally, this commit adds spec tests to cover the
refactored method.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/helpers/application_helper_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 0000000..a452278 --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe ApplicationHelper do + describe "gravatar_icon" do + let(:user_email) { 'user@email.com' } + + it "should return a generic avatar path when Gravatar is disabled" do + GitlabCi.config.gravatar.stub(:enabled).and_return(false) + gravatar_icon(user_email).should == 'no_avatar.png' + end + + it "should return a generic avatar path when email is blank" do + gravatar_icon('').should == 'no_avatar.png' + end + + it "should return default gravatar url" do + stub!(: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)) + 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)) + GitlabCi.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)) + 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)) + gravatar_icon(user_email, nil).should match(/\?s=40/) + end + + it "should be case insensitive" do + stub!(:request).and_return(double(:ssl? => false)) + gravatar_icon(user_email).should == gravatar_icon(user_email.upcase + " ") + end + end +end |