Commit a0a1b9e5075134d2730b519c6a2c1a29961e23e1
Exists in
master
and in
4 other branches
Merge pull request #79 from ariejan/fix_https_gravatar
Use secure.gravatar.com when running over SSL
Showing
2 changed files
with
38 additions
and
1 deletions
Show diff stats
app/helpers/application_helper.rb
1 | require 'digest/md5' | 1 | require 'digest/md5' |
2 | module ApplicationHelper | 2 | module ApplicationHelper |
3 | + | ||
3 | def gravatar_icon(user_email) | 4 | def gravatar_icon(user_email) |
4 | - "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(user_email)}?s=40&d=identicon" | 5 | + gravatar_host = request.ssl? ? "https://secure.gravatar.com" : "http://www.gravatar.com" |
6 | + "#{gravatar_host}/avatar/#{Digest::MD5.hexdigest(user_email)}?s=40&d=identicon" | ||
5 | end | 7 | end |
6 | 8 | ||
7 | def fixed_mode? | 9 | def fixed_mode? |
@@ -0,0 +1,35 @@ | @@ -0,0 +1,35 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe ApplicationHelper do | ||
4 | + context ".gravatar_icon" do | ||
5 | + context "over http" do | ||
6 | + it "returns the correct URL to www.gravatar.com" do | ||
7 | + expected = "http://www.gravatar.com/avatar/f7daa65b2aa96290bb47c4d68d11fe6a?s=40&d=identicon" | ||
8 | + | ||
9 | + # Pretend we're running over HTTP | ||
10 | + helper.stub(:request) do | ||
11 | + request = double('request') | ||
12 | + request.stub(:ssl?) { false } | ||
13 | + request | ||
14 | + end | ||
15 | + | ||
16 | + helper.gravatar_icon("admin@local.host").should == expected | ||
17 | + end | ||
18 | + end | ||
19 | + | ||
20 | + context "over https" do | ||
21 | + it "returns the correct URL to secure.gravatar.com" do | ||
22 | + expected = "https://secure.gravatar.com/avatar/f7daa65b2aa96290bb47c4d68d11fe6a?s=40&d=identicon" | ||
23 | + | ||
24 | + # Pretend we're running over HTTPS | ||
25 | + helper.stub(:request) do | ||
26 | + request = double('request') | ||
27 | + request.stub(:ssl?) { true } | ||
28 | + request | ||
29 | + end | ||
30 | + | ||
31 | + helper.gravatar_icon("admin@local.host").should == expected | ||
32 | + end | ||
33 | + end | ||
34 | + end | ||
35 | +end |