scope :active, lambda { joins(:principal).where(:users => {:status => Principal::STATUS_ACTIVE})}
+ # Sort by first role and principal
+ scope :sorted, lambda {
+ includes(:member_roles, :roles, :principal).
+ reorder("#{Role.table_name}.position").
+ order(Principal.fields_for_order_statement)
+ }
+
alias :base_reload :reload
def reload(*args)
@managed_roles = nil
<% roles = Role.find_all_givable
- members = @project.memberships.active.includes(:member_roles, :roles, :principal).to_a.sort %>
+ members = @project.memberships.active.sorted.to_a %>
<p><%= link_to l(:label_member_new), new_project_membership_path(@project), :remote => true, :class => "icon icon-add" %></p>
@jsmith = Member.find(1)
end
+ def test_sorted_scope_on_project_members
+ members = Project.find(1).members.sorted.to_a
+ roles = members.map {|m| m.roles.sort.first}
+ assert_equal roles, roles.sort
+ end
+
def test_create
member = Member.new(:project_id => 1, :user_id => 4, :role_ids => [1, 2])
assert member.save