@@ -26,11 +26,11 class Role < ActiveRecord::Base | |||
|
26 | 26 | ['own', :label_issues_visibility_own] |
|
27 | 27 | ] |
|
28 | 28 | |
|
29 |
scope :sorted, |
|
|
30 | scope :givable, { :conditions => "builtin = 0", :order => 'position' } | |
|
29 | scope :sorted, order("#{table_name}.builtin ASC, #{table_name}.position ASC") | |
|
30 | scope :givable, order("#{table_name}.position ASC").where(:builtin => 0) | |
|
31 | 31 | scope :builtin, lambda { |*args| |
|
32 |
compare = |
|
|
33 |
|
|
|
32 | compare = (args.first == true ? 'not' : '') | |
|
33 | where("#{compare} builtin = 0") | |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | before_destroy :check_deletable |
@@ -87,7 +87,15 class Role < ActiveRecord::Base | |||
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | def <=>(role) |
|
90 | role ? position <=> role.position : -1 | |
|
90 | if role | |
|
91 | if builtin == role.builtin | |
|
92 | position <=> role.position | |
|
93 | else | |
|
94 | builtin <=> role.builtin | |
|
95 | end | |
|
96 | else | |
|
97 | -1 | |
|
98 | end | |
|
91 | 99 | end |
|
92 | 100 | |
|
93 | 101 | def to_s |
@@ -134,7 +142,7 class Role < ActiveRecord::Base | |||
|
134 | 142 | |
|
135 | 143 | # Find all the roles that can be given to a project member |
|
136 | 144 | def self.find_all_givable |
|
137 | find(:all, :conditions => {:builtin => 0}, :order => 'position') | |
|
145 | Role.givable.all | |
|
138 | 146 | end |
|
139 | 147 | |
|
140 | 148 | # Return the builtin 'non member' role. If the role doesn't exist, |
@@ -165,7 +173,7 private | |||
|
165 | 173 | end |
|
166 | 174 | |
|
167 | 175 | def self.find_or_create_system_role(builtin, name) |
|
168 |
role = |
|
|
176 | role = where(:builtin => builtin).first | |
|
169 | 177 | if role.nil? |
|
170 | 178 | role = create(:name => name, :position => 0) do |r| |
|
171 | 179 | r.builtin = builtin |
@@ -25,8 +25,8 class Workflow < ActiveRecord::Base | |||
|
25 | 25 | # Returns workflow transitions count by tracker and role |
|
26 | 26 | def self.count_by_tracker_and_role |
|
27 | 27 | counts = connection.select_all("SELECT role_id, tracker_id, count(id) AS c FROM #{Workflow.table_name} GROUP BY role_id, tracker_id") |
|
28 | roles = Role.find(:all, :order => 'builtin, position') | |
|
29 |
trackers = Tracker. |
|
|
28 | roles = Role.sorted.all | |
|
29 | trackers = Tracker.sorted.all | |
|
30 | 30 | |
|
31 | 31 | result = [] |
|
32 | 32 | trackers.each do |tracker| |
@@ -20,6 +20,19 require File.expand_path('../../test_helper', __FILE__) | |||
|
20 | 20 | class RoleTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :roles, :workflows |
|
22 | 22 | |
|
23 | def test_sorted_scope | |
|
24 | assert_equal Role.all.sort, Role.sorted.all | |
|
25 | end | |
|
26 | ||
|
27 | def test_givable_scope | |
|
28 | assert_equal Role.all.reject(&:builtin?).sort, Role.givable.all | |
|
29 | end | |
|
30 | ||
|
31 | def test_builtin_scope | |
|
32 | assert_equal Role.all.select(&:builtin?).sort, Role.builtin(true).all.sort | |
|
33 | assert_equal Role.all.reject(&:builtin?).sort, Role.builtin(false).all.sort | |
|
34 | end | |
|
35 | ||
|
23 | 36 | def test_copy_workflows |
|
24 | 37 | source = Role.find(1) |
|
25 | 38 | assert_equal 90, source.workflows.size |
@@ -57,6 +70,10 class RoleTest < ActiveSupport::TestCase | |||
|
57 | 70 | assert_equal 'Non membre', Role.non_member.name |
|
58 | 71 | end |
|
59 | 72 | |
|
73 | def test_find_all_givable | |
|
74 | assert_equal Role.all.reject(&:builtin?).sort, Role.find_all_givable | |
|
75 | end | |
|
76 | ||
|
60 | 77 | context "#anonymous" do |
|
61 | 78 | should "return the anonymous role" do |
|
62 | 79 | role = Role.anonymous |
General Comments 0
You need to be logged in to leave comments.
Login now