Reverted r10184 (#9365).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10186 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-08-10 16:35:58 +00:00
parent 8b12702ebe
commit 02b2a61e15
2 changed files with 19 additions and 31 deletions

View File

@ -1134,7 +1134,7 @@ module ApplicationHelper
# +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>') # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
def avatar(user, options = { }) def avatar(user, options = { })
if Setting.gravatar_enabled? if Setting.gravatar_enabled?
options.merge!({:ssl => (Setting.protocol == 'https'), :default => Setting.gravatar_default}) options.merge!({:ssl => (request && request.ssl?), :default => Setting.gravatar_default})
email = nil email = nil
if user.respond_to?(:mail) if user.respond_to?(:mail)
email = user.mail email = user.mail

View File

@ -970,37 +970,25 @@ RAW
end end
end end
def test_avatar_enabled def test_avatar
with_settings :gravatar_enabled => '1' do # turn on avatars
assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) Setting.gravatar_enabled = '1'
assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
# Default size is 50 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
assert avatar('jsmith <jsmith@somenet.foo>').include?('size=50') # Default size is 50
assert avatar('jsmith <jsmith@somenet.foo>', :size => 24).include?('size=24') assert avatar('jsmith <jsmith@somenet.foo>').include?('size=50')
# Non-avatar options should be considered html options assert avatar('jsmith <jsmith@somenet.foo>', :size => 24).include?('size=24')
assert avatar('jsmith <jsmith@somenet.foo>', :title => 'John Smith').include?('title="John Smith"') # Non-avatar options should be considered html options
# The default class of the img tag should be gravatar assert avatar('jsmith <jsmith@somenet.foo>', :title => 'John Smith').include?('title="John Smith"')
assert avatar('jsmith <jsmith@somenet.foo>').include?('class="gravatar"') # The default class of the img tag should be gravatar
assert !avatar('jsmith <jsmith@somenet.foo>', :class => 'picture').include?('class="gravatar"') assert avatar('jsmith <jsmith@somenet.foo>').include?('class="gravatar"')
assert_nil avatar('jsmith') assert !avatar('jsmith <jsmith@somenet.foo>', :class => 'picture').include?('class="gravatar"')
assert_nil avatar(nil) assert_nil avatar('jsmith')
end assert_nil avatar(nil)
end
def test_avatar_should_use_ssl_if_protocol_is_https # turn off avatars
with_settings :gravatar_enabled => '1', :protocol => 'https' do Setting.gravatar_enabled = '0'
assert_include 'https://', avatar(User.find_by_mail('jsmith@somenet.foo')) assert_equal '', 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 end
def test_link_to_user def test_link_to_user