diff app/models/enumeration.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42
line wrap: on
line diff
--- a/app/models/enumeration.rb	Wed Jun 27 14:54:18 2012 +0100
+++ b/app/models/enumeration.rb	Mon Jan 07 12:01:42 2013 +0000
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2011  Jean-Philippe Lang
+# Copyright (C) 2006-2012  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -16,6 +16,8 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 class Enumeration < ActiveRecord::Base
+  include Redmine::SubclassFactory
+
   default_scope :order => "#{Enumeration.table_name}.position ASC"
 
   belongs_to :project
@@ -27,23 +29,26 @@
   before_destroy :check_integrity
   before_save    :check_default
 
+  attr_protected :type
+
   validates_presence_of :name
   validates_uniqueness_of :name, :scope => [:type, :project_id]
   validates_length_of :name, :maximum => 30
 
-  named_scope :shared, :conditions => { :project_id => nil }
-  named_scope :active, :conditions => { :active => true }
-  named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+  scope :shared, where(:project_id => nil)
+  scope :sorted, order("#{table_name}.position ASC")
+  scope :active, where(:active => true)
+  scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
 
   def self.default
     # Creates a fake default scope so Enumeration.default will check
     # it's type.  STI subclasses will automatically add their own
     # types to the finder.
     if self.descends_from_active_record?
-      find(:first, :conditions => { :is_default => true, :type => 'Enumeration' })
+      where(:is_default => true, :type => 'Enumeration').first
     else
       # STI classes are
-      find(:first, :conditions => { :is_default => true })
+      where(:is_default => true).first
     end
   end
 
@@ -54,7 +59,7 @@
 
   def check_default
     if is_default? && is_default_changed?
-      Enumeration.update_all("is_default = #{connection.quoted_false}", {:type => type})
+      Enumeration.update_all({:is_default => false}, {:type => type})
     end
   end
 
@@ -94,7 +99,7 @@
   #
   # Note: subclasses is protected in ActiveRecord
   def self.get_subclasses
-    @@subclasses[Enumeration]
+    subclasses
   end
 
   # Does the +new+ Hash override the previous Enumeration?