def principals_check_box_tags(name, principals)
s = +''
principals.each do |principal|
- s << "<label>#{ check_box_tag name, principal.id, false, :id => nil } <span class='name icon icon-#{principal.class.name.downcase}'></span>#{h principal}</label>\n"
+ s << content_tag('label',
+ check_box_tag(name, principal.id, false, :id => nil) +
+ (avatar(principal, :size => 16).presence || content_tag('span', nil, :class => "name icon icon-#{principal.class.name.downcase}")) +
+ principal)
end
s.html_safe
end
class ApplicationHelperTest < Redmine::HelperTest
include ERB::Util
include Rails.application.routes.url_helpers
+ include AvatarsHelper
fixtures :projects, :enabled_modules,
:users, :email_addresses,
end
end
+ def test_principals_check_box_tag_with_avatar
+ principals = [User.find(1), Group.find(10)]
+ with_settings :gravatar_enabled => '1' do
+ tags = principals_check_box_tags("watcher[user_ids][]", principals)
+ principals.each do |principal|
+ assert_include avatar(principal, :size => 16), tags
+ assert_not_include content_tag('span', nil, :class => "name icon icon-#{principal.class.name.downcase}"), tags
+ end
+ end
+ end
+
+ def test_principals_check_box_tag_without_avatar
+ principals = [User.find(1), Group.find(10)]
+ Setting.gravatar_enabled = '1'
+ avatar_tags = principals.collect{|p| avatar(p, :size => 16) }
+
+ with_settings :gravatar_enabled => '0' do
+ tags = principals_check_box_tags(name, principals)
+ principals.each_with_index do |principal, i|
+ assert_not_include avatar_tags[i], tags
+ assert_include content_tag('span', nil, :class => "name icon icon-#{principal.class.name.downcase}"), tags
+ end
+ end
+ end
+
def test_principals_options_for_select_with_users
User.current = nil
users = [User.find(2), User.find(4)]