Code cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9714 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
221585c7b5
commit
59cbc68dde
|
@ -65,14 +65,14 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||||
@trackers = Tracker.all
|
@trackers = Tracker.sorted.all
|
||||||
@project = Project.new
|
@project = Project.new
|
||||||
@project.safe_attributes = params[:project]
|
@project.safe_attributes = params[:project]
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||||
@trackers = Tracker.all
|
@trackers = Tracker.sorted.all
|
||||||
@project = Project.new
|
@project = Project.new
|
||||||
@project.safe_attributes = params[:project]
|
@project.safe_attributes = params[:project]
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
def copy
|
def copy
|
||||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||||
@trackers = Tracker.all
|
@trackers = Tracker.sorted.all
|
||||||
@root_projects = Project.find(:all,
|
@root_projects = Project.find(:all,
|
||||||
:conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
|
:conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
|
||||||
:order => 'name')
|
:order => 'name')
|
||||||
|
@ -175,7 +175,7 @@ class ProjectsController < ApplicationController
|
||||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||||
@issue_category ||= IssueCategory.new
|
@issue_category ||= IssueCategory.new
|
||||||
@member ||= @project.members.new
|
@member ||= @project.members.new
|
||||||
@trackers = Tracker.all
|
@trackers = Tracker.sorted.all
|
||||||
@wiki ||= @project.wiki
|
@wiki ||= @project.wiki
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ class TrackersController < ApplicationController
|
||||||
render :action => "index", :layout => false if request.xhr?
|
render :action => "index", :layout => false if request.xhr?
|
||||||
}
|
}
|
||||||
format.api {
|
format.api {
|
||||||
@trackers = Tracker.all
|
@trackers = Tracker.sorted.all
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -121,7 +121,7 @@ class Project < ActiveRecord::Base
|
||||||
self.enabled_module_names = Setting.default_projects_modules
|
self.enabled_module_names = Setting.default_projects_modules
|
||||||
end
|
end
|
||||||
if !initialized.key?('trackers') && !initialized.key?('tracker_ids')
|
if !initialized.key?('trackers') && !initialized.key?('tracker_ids')
|
||||||
self.trackers = Tracker.all
|
self.trackers = Tracker.sorted.all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@ class Tracker < ActiveRecord::Base
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
|
|
||||||
scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
|
scope :sorted, order("#{table_name}.position ASC")
|
||||||
|
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
|
||||||
|
|
||||||
def to_s; name end
|
def to_s; name end
|
||||||
|
|
||||||
|
@ -40,10 +41,6 @@ class Tracker < ActiveRecord::Base
|
||||||
position <=> tracker.position
|
position <=> tracker.position
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.all
|
|
||||||
find(:all, :order => 'position')
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns an array of IssueStatus that are used
|
# Returns an array of IssueStatus that are used
|
||||||
# in the tracker's workflows
|
# in the tracker's workflows
|
||||||
def issue_statuses
|
def issue_statuses
|
||||||
|
@ -63,6 +60,6 @@ class Tracker < ActiveRecord::Base
|
||||||
|
|
||||||
private
|
private
|
||||||
def check_integrity
|
def check_integrity
|
||||||
raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id])
|
raise Exception.new("Can't delete tracker") if Issue.where(:tracker_id => self.id).any?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Workflow < ActiveRecord::Base
|
||||||
target_trackers = [target_trackers].flatten.compact
|
target_trackers = [target_trackers].flatten.compact
|
||||||
target_roles = [target_roles].flatten.compact
|
target_roles = [target_roles].flatten.compact
|
||||||
|
|
||||||
target_trackers = Tracker.all if target_trackers.empty?
|
target_trackers = Tracker.sorted.all if target_trackers.empty?
|
||||||
target_roles = Role.all if target_roles.empty?
|
target_roles = Role.all if target_roles.empty?
|
||||||
|
|
||||||
target_trackers.each do |target_tracker|
|
target_trackers.each do |target_tracker|
|
||||||
|
|
|
@ -89,7 +89,7 @@ function toggle_custom_field_format() {
|
||||||
when "IssueCustomField" %>
|
when "IssueCustomField" %>
|
||||||
|
|
||||||
<fieldset><legend><%=l(:label_tracker_plural)%></legend>
|
<fieldset><legend><%=l(:label_tracker_plural)%></legend>
|
||||||
<% Tracker.all.each do |tracker| %>
|
<% Tracker.sorted.all.each do |tracker| %>
|
||||||
<%= check_box_tag "custom_field[tracker_ids][]",
|
<%= check_box_tag "custom_field[tracker_ids][]",
|
||||||
tracker.id,
|
tracker.id,
|
||||||
(@custom_field.trackers.include? tracker),
|
(@custom_field.trackers.include? tracker),
|
||||||
|
|
|
@ -18,7 +18,15 @@
|
||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../test_helper', __FILE__)
|
||||||
|
|
||||||
class TrackerTest < ActiveSupport::TestCase
|
class TrackerTest < ActiveSupport::TestCase
|
||||||
fixtures :trackers, :workflows, :issue_statuses, :roles
|
fixtures :trackers, :workflows, :issue_statuses, :roles, :issues
|
||||||
|
|
||||||
|
def test_sorted_scope
|
||||||
|
assert_equal Tracker.all.sort, Tracker.sorted.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_named_scope
|
||||||
|
assert_equal Tracker.find_by_name('Feature'), Tracker.named('feature').first
|
||||||
|
end
|
||||||
|
|
||||||
def test_copy_workflows
|
def test_copy_workflows
|
||||||
source = Tracker.find(1)
|
source = Tracker.find(1)
|
||||||
|
@ -57,4 +65,25 @@ class TrackerTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
assert_equal [b, a], [a, b].sort
|
assert_equal [b, a], [a, b].sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_destroying_a_tracker_without_issues_should_not_raise_an_error
|
||||||
|
tracker = Tracker.find(1)
|
||||||
|
Issue.delete_all :tracker_id => tracker.id
|
||||||
|
|
||||||
|
assert_difference 'Tracker.count', -1 do
|
||||||
|
assert_nothing_raised do
|
||||||
|
tracker.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_destroying_a_tracker_with_issues_should_raise_an_error
|
||||||
|
tracker = Tracker.find(1)
|
||||||
|
|
||||||
|
assert_no_difference 'Tracker.count' do
|
||||||
|
assert_raise Exception do
|
||||||
|
tracker.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue