Project

General

Profile

Defect #38458 ยป test-for-38458-note-2.patch

Go MAEDA, 2023-05-01 08:51

View differences:

app/helpers/watchers_helper.rb
48 48
  def watchers_list(object)
49 49
    remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
50 50
    content = ''.html_safe
51
    lis = object.watcher_users.collect do |user|
51
    lis = object.watcher_users.sorted.collect do |user|
52 52
      s = ''.html_safe
53 53
      s << avatar(user, :size => "16").to_s
54 54
      s << link_to_principal(user, class: user.class.to_s.downcase)
test/helpers/watchers_helper_test.rb
21 21

  
22 22
class WatchersHelperTest < Redmine::HelperTest
23 23
  include WatchersHelper
24
  include AvatarsHelper
25
  include ERB::Util
24 26
  include Rails.application.routes.url_helpers
25 27

  
26 28
  fixtures :users, :issues
......
66 68
    )
67 69
    assert_equal expected, watcher_link(Issue.find(1), User.find(1))
68 70
  end
71

  
72
  def test_watchers_list_should_be_sorted_by_user_name
73
    issue = Issue.find(1)
74
    [1, 2, 3].shuffle.each do |user_id|
75
      Watcher.create!(:watchable => issue, :user => User.find(user_id))
76
    end
77

  
78
    with_settings user_format: 'firstname_lastname' do
79
      result1 = watchers_list(issue)
80
      assert_select_in result1, 'ul.watchers' do
81
        assert_select 'li', 3
82
        assert_select 'li:nth-of-type(1)>a[href=?]', '/users/3', text: 'Dave Lopper'
83
        assert_select 'li:nth-of-type(2)>a[href=?]', '/users/2', text: 'John Smith'
84
        assert_select 'li:nth-of-type(3)>a[href=?]', '/users/1', text: 'Redmine Admin'
85
      end
86
    end
87

  
88
    with_settings user_format: 'lastname_firstname' do
89
      result2 = watchers_list(issue)
90
      assert_select_in result2, 'ul.watchers' do
91
        assert_select 'li', 3
92
        assert_select 'li:nth-of-type(1)>a[href=?]', '/users/1', text: 'Admin Redmine'
93
        assert_select 'li:nth-of-type(2)>a[href=?]', '/users/3', text: 'Lopper Dave'
94
        assert_select 'li:nth-of-type(3)>a[href=?]', '/users/2', text: 'Smith John'
95
      end
96
    end
97
  end
69 98
end
    (1-1/1)