Use lambda form in model scopes (#12499)

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10949 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Baptiste Barth 2012-12-07 10:12:47 +00:00
parent 8201761e77
commit 4896d5c7e8
12 changed files with 19 additions and 19 deletions

View File

@ -30,7 +30,7 @@ class CustomField < ActiveRecord::Base
validate :validate_custom_field
before_validation :set_searchable
scope :sorted, order("#{table_name}.position ASC")
scope :sorted, lambda { order("#{table_name}.position ASC") }
CUSTOM_FIELDS_TABS = [
{:name => 'IssueCustomField', :partial => 'custom_fields/index',

View File

@ -35,9 +35,9 @@ class Enumeration < ActiveRecord::Base
validates_uniqueness_of :name, :scope => [:type, :project_id]
validates_length_of :name, :maximum => 30
scope :shared, where(:project_id => nil)
scope :sorted, order("#{table_name}.position ASC")
scope :active, where(:active => true)
scope :shared, lambda { where(:project_id => nil) }
scope :sorted, lambda { order("#{table_name}.position ASC") }
scope :active, lambda { where(:active => true) }
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
def self.default

View File

@ -29,7 +29,7 @@ class Group < Principal
before_destroy :remove_references_before_destroy
scope :sorted, order("#{table_name}.lastname ASC")
scope :sorted, lambda { order("#{table_name}.lastname ASC") }
safe_attributes 'name',
'user_ids',

View File

@ -79,9 +79,9 @@ class Issue < ActiveRecord::Base
{:conditions => ["#{IssueStatus.table_name}.is_closed = ?", is_closed], :include => :status}
}
scope :recently_updated, :order => "#{Issue.table_name}.updated_on DESC"
scope :on_active_project, :include => [:status, :project, :tracker],
:conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
scope :recently_updated, lambda { { :order => "#{Issue.table_name}.updated_on DESC" } }
scope :on_active_project, lambda { { :include => [:status, :project, :tracker],
:conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"] } }
before_create :default_assign
before_save :close_duplicates, :update_done_ratio_from_issue_status, :force_updated_on_change

View File

@ -28,7 +28,7 @@ class IssueStatus < ActiveRecord::Base
validates_length_of :name, :maximum => 30
validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
scope :sorted, order("#{table_name}.position ASC")
scope :sorted, lambda { order("#{table_name}.position ASC") }
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
def update_default

View File

@ -24,7 +24,7 @@ class Principal < ActiveRecord::Base
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
# Groups and active users
scope :active, :conditions => "#{Principal.table_name}.status = 1"
scope :active, lambda { { :conditions => "#{Principal.table_name}.status = 1" } }
scope :like, lambda {|q|
q = q.to_s

View File

@ -85,9 +85,9 @@ class Project < ActiveRecord::Base
before_destroy :delete_all_members
scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
scope :active, lambda { { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}" } }
scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
scope :all_public, { :conditions => { :is_public => true } }
scope :all_public, lambda { { :conditions => { :is_public => true } } }
scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
scope :allowed_to, lambda {|*args|
user = User.current

View File

@ -39,8 +39,8 @@ class Role < ActiveRecord::Base
['own', :label_issues_visibility_own]
]
scope :sorted, order("#{table_name}.builtin ASC, #{table_name}.position ASC")
scope :givable, order("#{table_name}.position ASC").where(:builtin => 0)
scope :sorted, lambda { order("#{table_name}.builtin ASC, #{table_name}.position ASC") }
scope :givable, lambda { order("#{table_name}.position ASC").where(:builtin => 0) }
scope :builtin, lambda { |*args|
compare = (args.first == true ? 'not' : '')
where("#{compare} builtin = 0")

View File

@ -41,7 +41,7 @@ class Tracker < ActiveRecord::Base
validates_uniqueness_of :name
validates_length_of :name, :maximum => 30
scope :sorted, order("#{table_name}.position ASC")
scope :sorted, lambda { order("#{table_name}.position ASC") }
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
def to_s; name end

View File

@ -82,7 +82,7 @@ class User < Principal
has_one :api_token, :class_name => 'Token', :conditions => "action='api'"
belongs_to :auth_source
scope :logged, :conditions => "#{User.table_name}.status <> #{STATUS_ANONYMOUS}"
scope :logged, lambda { { :conditions => "#{User.table_name}.status <> #{STATUS_ANONYMOUS}" } }
scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
acts_as_customizable

View File

@ -36,7 +36,7 @@ class Version < ActiveRecord::Base
validate :validate_version
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
scope :open, where(:status => 'open')
scope :open, lambda { where(:status => 'open') }
scope :visible, lambda {|*args|
includes(:project).where(Project.allowed_to_condition(args.first || User.current, :view_issues))
}

View File

@ -49,10 +49,10 @@ class WikiPage < ActiveRecord::Base
before_save :handle_redirects
# eager load information about last updates, without loading text
scope :with_updated_on, {
scope :with_updated_on, lambda { {
:select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on, #{WikiContent.table_name}.version",
:joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id"
}
} }
# Wiki pages that are protected by default
DEFAULT_PROTECTED_PAGES = %w(sidebar)