diff options
author | Jean-Baptiste Barth <jeanbaptiste.barth@gmail.com> | 2012-12-07 10:12:47 +0000 |
---|---|---|
committer | Jean-Baptiste Barth <jeanbaptiste.barth@gmail.com> | 2012-12-07 10:12:47 +0000 |
commit | 4896d5c7e83bb3cc7996c5ab09441c90e7cd9ce1 (patch) | |
tree | d3fabb5ab5a156ec53e28ebf938f03ddc165815a /app/models | |
parent | 8201761e7732faa3933899653de5951dcbd6b27c (diff) | |
download | redmine-4896d5c7e83bb3cc7996c5ab09441c90e7cd9ce1.tar.gz redmine-4896d5c7e83bb3cc7996c5ab09441c90e7cd9ce1.zip |
Use lambda form in model scopes (#12499)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10949 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/custom_field.rb | 2 | ||||
-rw-r--r-- | app/models/enumeration.rb | 6 | ||||
-rw-r--r-- | app/models/group.rb | 2 | ||||
-rw-r--r-- | app/models/issue.rb | 6 | ||||
-rw-r--r-- | app/models/issue_status.rb | 2 | ||||
-rw-r--r-- | app/models/principal.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 4 | ||||
-rw-r--r-- | app/models/role.rb | 4 | ||||
-rw-r--r-- | app/models/tracker.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/models/version.rb | 2 | ||||
-rw-r--r-- | app/models/wiki_page.rb | 4 |
12 files changed, 19 insertions, 19 deletions
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 9f17bff02..9d40ebd7a 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -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', diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb index d3454021f..1c4a7a414 100644 --- a/app/models/enumeration.rb +++ b/app/models/enumeration.rb @@ -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 diff --git a/app/models/group.rb b/app/models/group.rb index f8b1ee639..fec5b8a83 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -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', diff --git a/app/models/issue.rb b/app/models/issue.rb index 4b60843c7..7ba0ba207 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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 diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index fe1615706..b66c8d3a1 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -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 diff --git a/app/models/principal.rb b/app/models/principal.rb index dfafe9de9..044f256ad 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 9f4b07d49..5e26bd7f6 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/models/role.rb b/app/models/role.rb index 15ed0e10d..d393582c0 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -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") diff --git a/app/models/tracker.rb b/app/models/tracker.rb index 9b3f6afe6..3b7558701 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 0cf2c9314..32b7d4499 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/version.rb b/app/models/version.rb index dbcd317e9..07d312ab9 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -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)) } diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 115b23d6d..45954a08d 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -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) |