end
css_classes += " #{options[:class]}" if css_classes && options[:class].present?
- url ? link_to(principal_icon(principal.class.name.downcase).to_s + name, url, :class => css_classes) : h(name)
+ url ? link_to(principal_icon(principal).to_s + name, url, :class => css_classes) : h(name)
end
# Displays a link to edit group page if current user is admin
check_box_tag(name, principal.id, false, :id => nil) +
(avatar(principal, :size => 16).presence ||
content_tag(
- 'span', principal_icon(principal.class.name.downcase),
+ 'span', principal_icon(principal),
:class => "name icon icon-#{principal.class.name.downcase}"
)
) + principal.to_s
end
end
- def principal_icon(principal_class, **options)
+ def principal_icon(principal, **options)
+ raise ArgumentError, "First argument has to be a Principal, was #{principal.inspect}" unless principal.is_a?(Principal)
+
+ principal_class = principal.class.name.downcase
sprite_icon('group', **options) if ['groupanonymous', 'groupnonmember', 'group'].include?(principal_class)
end
<% next if member.new_record? %>
<tr id="member-<%= member.id %>" class="member">
<td class="name icon icon-<%= member.principal.class.name.downcase %>">
- <%= principal_icon(member.principal.class.name.downcase) %>
+ <%= principal_icon(member.principal) %>
<%= link_to_user member.principal %>
</td>
<td class="roles">
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', principal_icon(principal.class.name.downcase), :class => "name icon icon-#{principal.class.name.downcase}"), tags
+ assert_include content_tag('span', principal_icon(principal), :class => "name icon icon-#{principal.class.name.downcase}"), tags
end
end
end
class IconsHelperTest < Redmine::HelperTest
include IconsHelper
+ fixtures :users
+
def test_sprite_icon_should_return_svg_with_defaults
expected = %r{<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-\w+.svg#icon--edit"></use></svg>$}
icon = sprite_icon('edit')
def test_principal_icon_should_return_group_icon_for_group_classes
expected = %r{<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-\w+.svg#icon--group"></use></svg>}
- %w(groupanonymous groupnonmember group).each do |principal_class|
- assert_match expected, principal_icon(principal_class)
+ [Principal.find(12), Principal.find(13), Principal.find(10)].each do |principal|
+ assert_match expected, principal_icon(principal)
end
end