Commit 4dbed7ca88c2fe8f127deb752f82a5ee9ab4cade

Authored by Ariejan de Vroom
1 parent 7066444f

Use secure.gravatar.com when running over SSL

app/helpers/application_helper.rb
1 1 require 'digest/md5'
2 2 module ApplicationHelper
  3 +
3 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 7 end
6 8  
7 9 def fixed_mode?
... ...
spec/helpers/application_helper_spec.rb 0 → 100644
... ... @@ -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
... ...