Commit f15193c360fd93acabfe9bb5d1c34ee6d18f0ccb

Authored by Daniela Feitosa
2 parents cf53d339 6a3caadd

Merge branch 'ActionItem2909-SortUsersAlphabetically' of https://gitlab.com/unb-…

…gama/noosfero into ActionItem2909-SortUsersAlphabetically
app/controllers/my_profile/profile_members_controller.rb
@@ -2,7 +2,7 @@ class ProfileMembersController < MyProfileController @@ -2,7 +2,7 @@ class ProfileMembersController < MyProfileController
2 protect 'manage_memberships', :profile 2 protect 'manage_memberships', :profile
3 3
4 def index 4 def index
5 - @members = profile.members 5 + @members = profile.members_by_name
6 @member_role = environment.roles.find_by_name('member') 6 @member_role = environment.roles.find_by_name('member')
7 end 7 end
8 8
app/controllers/public/profile_controller.rb
@@ -67,7 +67,7 @@ class ProfileController < PublicController @@ -67,7 +67,7 @@ class ProfileController < PublicController
67 67
68 def members 68 def members
69 if is_cache_expired?(profile.members_cache_key(params)) 69 if is_cache_expired?(profile.members_cache_key(params))
70 - @members = profile.members.includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage]) 70 + @members = profile.members_by_name.includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage])
71 end 71 end
72 end 72 end
73 73
app/models/profile.rb
@@ -88,6 +88,10 @@ class Profile < ActiveRecord::Base @@ -88,6 +88,10 @@ class Profile < ActiveRecord::Base
88 ScopeTool.union *scopes 88 ScopeTool.union *scopes
89 end 89 end
90 90
  91 + def members_by_name
  92 + members.order(:name)
  93 + end
  94 +
91 def members_count 95 def members_count
92 members.count 96 members.count
93 end 97 end
app/views/profile_members/_members_list.rhtml
1 -<% collection = @collection == :profile_admins ? profile.admins : profile.members %> 1 +<% collection = @collection == :profile_admins ? profile.admins : profile.members_by_name %>
2 <% title = @title ? @title : _('Current members') %> 2 <% title = @title ? @title : _('Current members') %>
3 <% remove_action = @remove_action ? @remove_action : {:action => 'unassociate'} %> 3 <% remove_action = @remove_action ? @remove_action : {:action => 'unassociate'} %>
4 4
test/unit/profile_test.rb
@@ -1692,6 +1692,30 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1692,6 +1692,30 @@ class ProfileTest &lt; ActiveSupport::TestCase
1692 assert_equal 1, community.members_count 1692 assert_equal 1, community.members_count
1693 end 1693 end
1694 1694
  1695 + should 'order members by name alphabetically considering special characters' do
  1696 + community = fast_create(Community)
  1697 +
  1698 + community.add_member(create_user('José').person)
  1699 + community.add_member(create_user('João').person)
  1700 + community.add_member(create_user('Mariana').person)
  1701 + members = community.members_by_name
  1702 +
  1703 + assert_equal "João", members.first.name
  1704 + assert_equal "Mariana", members.last.name
  1705 + end
  1706 +
  1707 + should 'order members by name alphabetically considering upper and lower cases' do
  1708 + community = fast_create(Community)
  1709 +
  1710 + community.add_member(create_user('mariana').person)
  1711 + community.add_member(create_user('João').person)
  1712 + community.add_member(create_user('guest').person)
  1713 + members = community.members_by_name
  1714 +
  1715 + assert_equal "guest", members.first.name
  1716 + assert_equal "mariana", members.last.name
  1717 + end
  1718 +
1695 should 'know if url is the profile homepage' do 1719 should 'know if url is the profile homepage' do
1696 profile = fast_create(Profile) 1720 profile = fast_create(Profile)
1697 1721