Commit 4c1d90824fcd9a6a5107b33b76af0158c06dcd3e
1 parent
88004758
Exists in
master
and in
1 other branch
Uses https-links for gravatar when using ssl
Showing
2 changed files
with
26 additions
and
3 deletions
Show diff stats
app/helpers/problems_helper.rb
| @@ -12,7 +12,7 @@ module ProblemsHelper | @@ -12,7 +12,7 @@ module ProblemsHelper | ||
| 12 | 12 | ||
| 13 | def gravatar_tag(email, options = {}) | 13 | def gravatar_tag(email, options = {}) |
| 14 | return nil unless email.present? | 14 | return nil unless email.present? |
| 15 | - | 15 | + |
| 16 | image_tag gravatar_url(email, options), :alt => email, :class => 'gravatar' | 16 | image_tag gravatar_url(email, options), :alt => email, :class => 'gravatar' |
| 17 | end | 17 | end |
| 18 | 18 | ||
| @@ -25,7 +25,8 @@ module ProblemsHelper | @@ -25,7 +25,8 @@ module ProblemsHelper | ||
| 25 | options.reverse_merge! default_options | 25 | options.reverse_merge! default_options |
| 26 | params = options.extract!(:s, :d).delete_if { |k, v| v.blank? } | 26 | params = options.extract!(:s, :d).delete_if { |k, v| v.blank? } |
| 27 | email_hash = Digest::MD5.hexdigest(email) | 27 | email_hash = Digest::MD5.hexdigest(email) |
| 28 | - "http://www.gravatar.com/avatar/#{email_hash}?#{params.to_query}" | 28 | + url = request.ssl? ? "https://secure.gravatar.com" : "http://www.gravatar.com" |
| 29 | + "#{url}/avatar/#{email_hash}?#{params.to_query}" | ||
| 29 | end | 30 | end |
| 30 | end | 31 | end |
| 31 | 32 |
spec/helpers/problems_helper_spec.rb
| @@ -42,10 +42,32 @@ describe ProblemsHelper do | @@ -42,10 +42,32 @@ describe ProblemsHelper do | ||
| 42 | describe "#gravatar_url" do | 42 | describe "#gravatar_url" do |
| 43 | context "no email" do | 43 | context "no email" do |
| 44 | let(:email) { nil } | 44 | let(:email) { nil } |
| 45 | - | 45 | + |
| 46 | it "should return nil" do | 46 | it "should return nil" do |
| 47 | helper.gravatar_url(email).should be_nil | 47 | helper.gravatar_url(email).should be_nil |
| 48 | end | 48 | end |
| 49 | end | 49 | end |
| 50 | + | ||
| 51 | + context "without ssl" do | ||
| 52 | + let(:email) { "gravatar@example.com" } | ||
| 53 | + let(:email_hash) { Digest::MD5.hexdigest email } | ||
| 54 | + | ||
| 55 | + it "should return the http url" do | ||
| 56 | + helper.gravatar_url(email).should eq("http://www.gravatar.com/avatar/#{email_hash}?d=identicon") | ||
| 57 | + end | ||
| 58 | + end | ||
| 59 | + | ||
| 60 | + context "with ssl" do | ||
| 61 | + let(:email) { "gravatar@example.com" } | ||
| 62 | + let(:email_hash) { Digest::MD5.hexdigest email } | ||
| 63 | + | ||
| 64 | + it "should return the http url" do | ||
| 65 | + # request.env['HTTPS'] = 'on' | ||
| 66 | + ActionController::TestRequest.any_instance.stub ssl?: true | ||
| 67 | + | ||
| 68 | + | ||
| 69 | + helper.gravatar_url(email).should eq("https://secure.gravatar.com/avatar/#{email_hash}?d=identicon") | ||
| 70 | + end | ||
| 71 | + end | ||
| 50 | end | 72 | end |
| 51 | end | 73 | end |