@@ -65,14 +65,14 class ProjectsController < ApplicationController | |||||
65 |
|
65 | |||
66 | def new |
|
66 | def new | |
67 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
67 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
68 | @trackers = Tracker.all |
|
68 | @trackers = Tracker.sorted.all | |
69 | @project = Project.new |
|
69 | @project = Project.new | |
70 | @project.safe_attributes = params[:project] |
|
70 | @project.safe_attributes = params[:project] | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def create |
|
73 | def create | |
74 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
74 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
75 | @trackers = Tracker.all |
|
75 | @trackers = Tracker.sorted.all | |
76 | @project = Project.new |
|
76 | @project = Project.new | |
77 | @project.safe_attributes = params[:project] |
|
77 | @project.safe_attributes = params[:project] | |
78 |
|
78 | |||
@@ -105,7 +105,7 class ProjectsController < ApplicationController | |||||
105 |
|
105 | |||
106 | def copy |
|
106 | def copy | |
107 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
107 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
108 | @trackers = Tracker.all |
|
108 | @trackers = Tracker.sorted.all | |
109 | @root_projects = Project.find(:all, |
|
109 | @root_projects = Project.find(:all, | |
110 | :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", |
|
110 | :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", | |
111 | :order => 'name') |
|
111 | :order => 'name') | |
@@ -175,7 +175,7 class ProjectsController < ApplicationController | |||||
175 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
175 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
176 | @issue_category ||= IssueCategory.new |
|
176 | @issue_category ||= IssueCategory.new | |
177 | @member ||= @project.members.new |
|
177 | @member ||= @project.members.new | |
178 | @trackers = Tracker.all |
|
178 | @trackers = Tracker.sorted.all | |
179 | @wiki ||= @project.wiki |
|
179 | @wiki ||= @project.wiki | |
180 | end |
|
180 | end | |
181 |
|
181 |
@@ -29,7 +29,7 class TrackersController < ApplicationController | |||||
29 | render :action => "index", :layout => false if request.xhr? |
|
29 | render :action => "index", :layout => false if request.xhr? | |
30 | } |
|
30 | } | |
31 | format.api { |
|
31 | format.api { | |
32 | @trackers = Tracker.all |
|
32 | @trackers = Tracker.sorted.all | |
33 | } |
|
33 | } | |
34 | end |
|
34 | end | |
35 | end |
|
35 | end |
@@ -121,7 +121,7 class Project < ActiveRecord::Base | |||||
121 | self.enabled_module_names = Setting.default_projects_modules |
|
121 | self.enabled_module_names = Setting.default_projects_modules | |
122 | end |
|
122 | end | |
123 | if !initialized.key?('trackers') && !initialized.key?('tracker_ids') |
|
123 | if !initialized.key?('trackers') && !initialized.key?('tracker_ids') | |
124 | self.trackers = Tracker.all |
|
124 | self.trackers = Tracker.sorted.all | |
125 | end |
|
125 | end | |
126 | end |
|
126 | end | |
127 |
|
127 |
@@ -32,7 +32,8 class Tracker < ActiveRecord::Base | |||||
32 | validates_uniqueness_of :name |
|
32 | validates_uniqueness_of :name | |
33 | validates_length_of :name, :maximum => 30 |
|
33 | validates_length_of :name, :maximum => 30 | |
34 |
|
34 | |||
35 | scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} |
|
35 | scope :sorted, order("#{table_name}.position ASC") | |
|
36 | scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} | |||
36 |
|
37 | |||
37 | def to_s; name end |
|
38 | def to_s; name end | |
38 |
|
39 | |||
@@ -40,10 +41,6 class Tracker < ActiveRecord::Base | |||||
40 | position <=> tracker.position |
|
41 | position <=> tracker.position | |
41 | end |
|
42 | end | |
42 |
|
43 | |||
43 | def self.all |
|
|||
44 | find(:all, :order => 'position') |
|
|||
45 | end |
|
|||
46 |
|
||||
47 | # Returns an array of IssueStatus that are used |
|
44 | # Returns an array of IssueStatus that are used | |
48 | # in the tracker's workflows |
|
45 | # in the tracker's workflows | |
49 | def issue_statuses |
|
46 | def issue_statuses | |
@@ -63,6 +60,6 class Tracker < ActiveRecord::Base | |||||
63 |
|
60 | |||
64 | private |
|
61 | private | |
65 | def check_integrity |
|
62 | def check_integrity | |
66 |
raise "Can't delete tracker" if Issue. |
|
63 | raise Exception.new("Can't delete tracker") if Issue.where(:tracker_id => self.id).any? | |
67 | end |
|
64 | end | |
68 | end |
|
65 | end |
@@ -50,7 +50,7 class Workflow < ActiveRecord::Base | |||||
50 | target_trackers = [target_trackers].flatten.compact |
|
50 | target_trackers = [target_trackers].flatten.compact | |
51 | target_roles = [target_roles].flatten.compact |
|
51 | target_roles = [target_roles].flatten.compact | |
52 |
|
52 | |||
53 | target_trackers = Tracker.all if target_trackers.empty? |
|
53 | target_trackers = Tracker.sorted.all if target_trackers.empty? | |
54 | target_roles = Role.all if target_roles.empty? |
|
54 | target_roles = Role.all if target_roles.empty? | |
55 |
|
55 | |||
56 | target_trackers.each do |target_tracker| |
|
56 | target_trackers.each do |target_tracker| |
@@ -89,7 +89,7 function toggle_custom_field_format() { | |||||
89 | when "IssueCustomField" %> |
|
89 | when "IssueCustomField" %> | |
90 |
|
90 | |||
91 | <fieldset><legend><%=l(:label_tracker_plural)%></legend> |
|
91 | <fieldset><legend><%=l(:label_tracker_plural)%></legend> | |
92 | <% Tracker.all.each do |tracker| %> |
|
92 | <% Tracker.sorted.all.each do |tracker| %> | |
93 | <%= check_box_tag "custom_field[tracker_ids][]", |
|
93 | <%= check_box_tag "custom_field[tracker_ids][]", | |
94 | tracker.id, |
|
94 | tracker.id, | |
95 | (@custom_field.trackers.include? tracker), |
|
95 | (@custom_field.trackers.include? tracker), |
@@ -18,7 +18,15 | |||||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class TrackerTest < ActiveSupport::TestCase |
|
20 | class TrackerTest < ActiveSupport::TestCase | |
21 | fixtures :trackers, :workflows, :issue_statuses, :roles |
|
21 | fixtures :trackers, :workflows, :issue_statuses, :roles, :issues | |
|
22 | ||||
|
23 | def test_sorted_scope | |||
|
24 | assert_equal Tracker.all.sort, Tracker.sorted.all | |||
|
25 | end | |||
|
26 | ||||
|
27 | def test_named_scope | |||
|
28 | assert_equal Tracker.find_by_name('Feature'), Tracker.named('feature').first | |||
|
29 | end | |||
22 |
|
30 | |||
23 | def test_copy_workflows |
|
31 | def test_copy_workflows | |
24 | source = Tracker.find(1) |
|
32 | source = Tracker.find(1) | |
@@ -57,4 +65,25 class TrackerTest < ActiveSupport::TestCase | |||||
57 |
|
65 | |||
58 | assert_equal [b, a], [a, b].sort |
|
66 | assert_equal [b, a], [a, b].sort | |
59 | end |
|
67 | end | |
|
68 | ||||
|
69 | def test_destroying_a_tracker_without_issues_should_not_raise_an_error | |||
|
70 | tracker = Tracker.find(1) | |||
|
71 | Issue.delete_all :tracker_id => tracker.id | |||
|
72 | ||||
|
73 | assert_difference 'Tracker.count', -1 do | |||
|
74 | assert_nothing_raised do | |||
|
75 | tracker.destroy | |||
|
76 | end | |||
|
77 | end | |||
|
78 | end | |||
|
79 | ||||
|
80 | def test_destroying_a_tracker_with_issues_should_raise_an_error | |||
|
81 | tracker = Tracker.find(1) | |||
|
82 | ||||
|
83 | assert_no_difference 'Tracker.count' do | |||
|
84 | assert_raise Exception do | |||
|
85 | tracker.destroy | |||
|
86 | end | |||
|
87 | end | |||
|
88 | end | |||
60 | end |
|
89 | end |
General Comments 0
You need to be logged in to leave comments.
Login now