]> source.dussan.org Git - redmine.git/commitdiff
Code cleanup.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 15 Jul 2012 14:28:18 +0000 (14:28 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 15 Jul 2012 14:28:18 +0000 (14:28 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9981 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue_status.rb
test/unit/issue_status_test.rb

index 2d09d5e8850917b7d05e8063bd1f1a765c1c6efc..1562d049a24719125b95c79f7de136510d9c29fe 100644 (file)
@@ -28,23 +28,22 @@ class IssueStatus < ActiveRecord::Base
   validates_length_of :name, :maximum => 30
   validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
 
-  scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+  scope :named, lambda {|arg| where(["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip])}
 
   def update_default
-    IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default?
+    IssueStatus.update_all({:is_default => false}, ['id <> ?', id]) if self.is_default?
   end
 
   # Returns the default status for new issues
   def self.default
-    find(:first, :conditions =>["is_default=?", true])
+    where(:is_default => true).first
   end
 
   # Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+
   def self.update_issue_done_ratios
     if Issue.use_status_for_done_ratio?
-      IssueStatus.find(:all, :conditions => ["default_done_ratio >= 0"]).each do |status|
-        Issue.update_all(["done_ratio = ?", status.default_done_ratio],
-                         ["status_id = ?", status.id])
+      IssueStatus.where("default_done_ratio >= 0").all.each do |status|
+        Issue.update_all({:done_ratio => status.default_done_ratio}, {:status_id => status.id})
       end
     end
 
@@ -61,7 +60,7 @@ class IssueStatus < ActiveRecord::Base
         w.tracker_id == tracker.id &&
         ((!w.author && !w.assignee) || (author && w.author) || (assignee && w.assignee))
       end
-      transitions.collect{|w| w.new_status}.compact.sort
+      transitions.map(&:new_status).compact.sort
     else
       []
     end
@@ -75,12 +74,12 @@ class IssueStatus < ActiveRecord::Base
       conditions << " OR author = :true" if author
       conditions << " OR assignee = :true" if assignee
 
-      workflows.find(:all,
-        :include => :new_status,
-        :conditions => ["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})",
+      workflows.
+        includes(:new_status).
+        where(["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})",
           {:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false}
-          ]
-        ).collect{|w| w.new_status}.compact.sort
+          ]).all.
+        map(&:new_status).compact.sort
     else
       []
     end
@@ -92,9 +91,10 @@ class IssueStatus < ActiveRecord::Base
 
   def to_s; name end
 
-private
+  private
+
   def check_integrity
-    raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id])
+    raise "Can't delete status" if Issue.where(:status_id => id).any?
   end
 
   # Deletes associated workflows
index f12fbdd3dde8f812734847262eff39bdcf2006cd..5d3b6a11213fff41924c2288bf0cefec5095d9ad 100644 (file)
@@ -111,4 +111,10 @@ class IssueStatusTest < ActiveSupport::TestCase
       assert_equal [50], issues.map {|issue| issue.read_attribute(:done_ratio)}.uniq
     end
   end
+
+  def test_named_scope
+    status = IssueStatus.named("resolved").first
+    assert_not_nil status
+    assert_equal "Resolved", status.name
+  end
 end