diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 983f3fd8b..cbdbcca4e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1134,7 +1134,7 @@ module ApplicationHelper # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe ') def avatar(user, options = { }) if Setting.gravatar_enabled? - options.merge!({:ssl => (request && request.ssl?), :default => Setting.gravatar_default}) + options.merge!({:ssl => (Setting.protocol == 'https'), :default => Setting.gravatar_default}) email = nil if user.respond_to?(:mail) email = user.mail diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index b3757b092..edb01ea6d 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -970,25 +970,37 @@ RAW end end - def test_avatar - # turn on avatars - Setting.gravatar_enabled = '1' - assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) - assert avatar('jsmith ').include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) - # Default size is 50 - assert avatar('jsmith ').include?('size=50') - assert avatar('jsmith ', :size => 24).include?('size=24') - # Non-avatar options should be considered html options - assert avatar('jsmith ', :title => 'John Smith').include?('title="John Smith"') - # The default class of the img tag should be gravatar - assert avatar('jsmith ').include?('class="gravatar"') - assert !avatar('jsmith ', :class => 'picture').include?('class="gravatar"') - assert_nil avatar('jsmith') - assert_nil avatar(nil) + def test_avatar_enabled + with_settings :gravatar_enabled => '1' do + assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) + assert avatar('jsmith ').include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) + # Default size is 50 + assert avatar('jsmith ').include?('size=50') + assert avatar('jsmith ', :size => 24).include?('size=24') + # Non-avatar options should be considered html options + assert avatar('jsmith ', :title => 'John Smith').include?('title="John Smith"') + # The default class of the img tag should be gravatar + assert avatar('jsmith ').include?('class="gravatar"') + assert !avatar('jsmith ', :class => 'picture').include?('class="gravatar"') + assert_nil avatar('jsmith') + assert_nil avatar(nil) + end + end - # turn off avatars - Setting.gravatar_enabled = '0' - assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo')) + def test_avatar_should_use_ssl_if_protocol_is_https + with_settings :gravatar_enabled => '1', :protocol => 'https' do + assert_include 'https://', avatar(User.find_by_mail('jsmith@somenet.foo')) + end + + with_settings :gravatar_enabled => '1', :protocol => 'http' do + assert_include 'http://', avatar(User.find_by_mail('jsmith@somenet.foo')) + end + end + + def test_avatar_disabled + with_settings :gravatar_enabled => '0' do + assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo')) + end end def test_link_to_user