From 4c1d90824fcd9a6a5107b33b76af0158c06dcd3e Mon Sep 17 00:00:00 2001 From: Jeroen Jacobs Date: Mon, 5 Aug 2013 09:41:25 +0200 Subject: [PATCH] Uses https-links for gravatar when using ssl --- app/helpers/problems_helper.rb | 5 +++-- spec/helpers/problems_helper_spec.rb | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/helpers/problems_helper.rb b/app/helpers/problems_helper.rb index 4cc350d..a184c2a 100644 --- a/app/helpers/problems_helper.rb +++ b/app/helpers/problems_helper.rb @@ -12,7 +12,7 @@ module ProblemsHelper def gravatar_tag(email, options = {}) return nil unless email.present? - + image_tag gravatar_url(email, options), :alt => email, :class => 'gravatar' end @@ -25,7 +25,8 @@ module ProblemsHelper options.reverse_merge! default_options params = options.extract!(:s, :d).delete_if { |k, v| v.blank? } email_hash = Digest::MD5.hexdigest(email) - "http://www.gravatar.com/avatar/#{email_hash}?#{params.to_query}" + url = request.ssl? ? "https://secure.gravatar.com" : "http://www.gravatar.com" + "#{url}/avatar/#{email_hash}?#{params.to_query}" end end diff --git a/spec/helpers/problems_helper_spec.rb b/spec/helpers/problems_helper_spec.rb index e63cabc..a5ef664 100644 --- a/spec/helpers/problems_helper_spec.rb +++ b/spec/helpers/problems_helper_spec.rb @@ -42,10 +42,32 @@ describe ProblemsHelper do describe "#gravatar_url" do context "no email" do let(:email) { nil } - + it "should return nil" do helper.gravatar_url(email).should be_nil end end + + context "without ssl" do + let(:email) { "gravatar@example.com" } + let(:email_hash) { Digest::MD5.hexdigest email } + + it "should return the http url" do + helper.gravatar_url(email).should eq("http://www.gravatar.com/avatar/#{email_hash}?d=identicon") + end + end + + context "with ssl" do + let(:email) { "gravatar@example.com" } + let(:email_hash) { Digest::MD5.hexdigest email } + + it "should return the http url" do + # request.env['HTTPS'] = 'on' + ActionController::TestRequest.any_instance.stub ssl?: true + + + helper.gravatar_url(email).should eq("https://secure.gravatar.com/avatar/#{email_hash}?d=identicon") + end + end end end -- libgit2 0.21.2