]> source.dussan.org Git - redmine.git/commitdiff
@principal_icon@ method should accept a Principal as argument (#23980).
authorMarius Balteanu <marius.balteanu@zitec.com>
Sun, 10 Nov 2024 15:31:46 +0000 (15:31 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Sun, 10 Nov 2024 15:31:46 +0000 (15:31 +0000)
git-svn-id: https://svn.redmine.org/redmine/trunk@23230 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
app/helpers/icons_helper.rb
app/views/projects/settings/_members.html.erb
test/helpers/application_helper_test.rb
test/helpers/icons_helper_test.rb

index 806d59da1141dac590fefe36cd32785159fe8b09..bac8da2667c73ce4f6c63b99b73c98fdba61a960 100644 (file)
@@ -76,7 +76,7 @@ module ApplicationHelper
     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
@@ -657,7 +657,7 @@ module ApplicationHelper
           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
index f423a2898235d299fa710f5df0e9c5a04514538a..99006308e5cc3c44d3995ed67040f7b08f15babe 100644 (file)
@@ -45,7 +45,10 @@ module IconsHelper
     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
 
index bd953d2478a4a68d74c018e744b85bb793c6693d..6e13808b6aeef44760f6e1d67aa403d8500952eb 100644 (file)
@@ -20,7 +20,7 @@
   <% 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">
index c7e79cb663173be0ab4db9bd694176d96e40953d..3ffa24281a2f9bf53578e6c0406a98d3034fa068 100644 (file)
@@ -2027,7 +2027,7 @@ class ApplicationHelperTest < Redmine::HelperTest
       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
index 688c6dbac5b0b85ec58da1959fa9ceaa7f4b636a..ab3e743fdeddc61f801fe59e5554d7798b47eace 100644 (file)
@@ -22,6 +22,8 @@ require_relative '../test_helper'
 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')
@@ -98,8 +100,8 @@ class IconsHelperTest < Redmine::HelperTest
   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