summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-03 21:30:10 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-03 21:30:10 +0000
commitea296a109a8655ea48c02c1d0a9bb0d19002d236 (patch)
tree08b5e517e77e341cfdd5a23d649dd1e754074dd4
parenta7023dfa9b8e39e6e0a73e57d22823e8a4260b71 (diff)
downloadredmine-ea296a109a8655ea48c02c1d0a9bb0d19002d236.tar.gz
redmine-ea296a109a8655ea48c02c1d0a9bb0d19002d236.zip
Replaces find(:first/:all) calls.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10931 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/admin_controller.rb5
-rw-r--r--app/controllers/boards_controller.rb19
-rw-r--r--app/controllers/documents_controller.rb2
-rw-r--r--app/controllers/trackers_controller.rb2
-rw-r--r--app/controllers/users_controller.rb5
-rw-r--r--app/controllers/wiki_controller.rb11
-rw-r--r--app/models/query.rb31
-rw-r--r--lib/plugins/acts_as_versioned/lib/acts_as_versioned.rb14
-rw-r--r--lib/tasks/migrate_from_mantis.rake4
-rw-r--r--lib/tasks/migrate_from_trac.rake2
-rw-r--r--test/integration/account_test.rb2
-rw-r--r--test/unit/issue_test.rb4
12 files changed, 56 insertions, 45 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index e8cccca85..a7a1b9a14 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -32,10 +32,9 @@ class AdminController < ApplicationController
def projects
@status = params[:status] || 1
- scope = Project.status(@status)
+ scope = Project.status(@status).order('lft')
scope = scope.like(params[:name]) if params[:name].present?
-
- @projects = scope.all(:order => 'lft')
+ @projects = scope.all
render :action => "projects", :layout => false if request.xhr?
end
diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb
index cea2cd3bd..faf88647c 100644
--- a/app/controllers/boards_controller.rb
+++ b/app/controllers/boards_controller.rb
@@ -43,17 +43,22 @@ class BoardsController < ApplicationController
@topic_count = @board.topics.count
@topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
- @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC").order(sort_clause).all(
- :include => [:author, {:last_reply => :author}],
- :limit => @topic_pages.items_per_page,
- :offset => @topic_pages.current.offset)
+ @topics = @board.topics.
+ reorder("#{Message.table_name}.sticky DESC").
+ includes(:author, {:last_reply => :author}).
+ limit(@topic_pages.items_per_page).
+ offset(@topic_pages.current.offset).
+ order(sort_clause).
+ all
@message = Message.new(:board => @board)
render :action => 'show', :layout => !request.xhr?
}
format.atom {
- @messages = @board.messages.find :all, :order => 'created_on DESC',
- :include => [:author, :board],
- :limit => Setting.feeds_limit.to_i
+ @messages = @board.messages.
+ reorder('created_on DESC').
+ includes(:author, :board).
+ limit(Setting.feeds_limit.to_i).
+ all
render_feed(@messages, :title => "#{@project}: #{@board}")
}
end
diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb
index 979fc6004..cf40d1293 100644
--- a/app/controllers/documents_controller.rb
+++ b/app/controllers/documents_controller.rb
@@ -27,7 +27,7 @@ class DocumentsController < ApplicationController
def index
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
- documents = @project.documents.find :all, :include => [:attachments, :category]
+ documents = @project.documents.includes(:attachments, :category).all
case @sort_by
when 'date'
@grouped = documents.group_by {|d| d.updated_on.to_date }
diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb
index 3c08e30a7..78c907053 100644
--- a/app/controllers/trackers_controller.rb
+++ b/app/controllers/trackers_controller.rb
@@ -36,7 +36,7 @@ class TrackersController < ApplicationController
def new
@tracker ||= Tracker.new(params[:tracker])
- @trackers = Tracker.find :all, :order => 'position'
+ @trackers = Tracker.sorted.all
@projects = Project.all
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 239bd290e..e6702a971 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -47,10 +47,7 @@ class UsersController < ApplicationController
@user_count = scope.count
@user_pages = Paginator.new self, @user_count, @limit, params['page']
@offset ||= @user_pages.current.offset
- @users = scope.find :all,
- :order => sort_clause,
- :limit => @limit,
- :offset => @offset
+ @users = scope.order(sort_clause).limit(@limit).offset(@offset).all
respond_to do |format|
format.html {
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index 5d8d326ba..fd7076024 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -213,11 +213,12 @@ class WikiController < ApplicationController
@version_count = @page.content.versions.count
@version_pages = Paginator.new self, @version_count, per_page_option, params['page']
# don't load text
- @versions = @page.content.versions.find :all,
- :select => "id, author_id, comments, updated_on, version",
- :order => 'version DESC',
- :limit => @version_pages.items_per_page + 1,
- :offset => @version_pages.current.offset
+ @versions = @page.content.versions.
+ select("id, author_id, comments, updated_on, version").
+ reorder('version DESC').
+ limit(@version_pages.items_per_page + 1).
+ offset(@version_pages.current.offset).
+ all
render :layout => false if request.xhr?
end
diff --git a/app/models/query.rb b/app/models/query.rb
index 84f8c3ef6..409095434 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -685,12 +685,14 @@ class Query < ActiveRecord::Base
order_option = [group_by_sort_order, options[:order]].reject {|s| s.blank?}.join(',')
order_option = nil if order_option.blank?
- issues = Issue.visible.scoped(:conditions => options[:conditions]).find :all, :include => ([:status, :project] + (options[:include] || [])).uniq,
- :conditions => statement,
- :order => order_option,
- :joins => joins_for_order_statement(order_option),
- :limit => options[:limit],
- :offset => options[:offset]
+ issues = Issue.visible.where(options[:conditions]).all(
+ :include => ([:status, :project] + (options[:include] || [])).uniq,
+ :conditions => statement,
+ :order => order_option,
+ :joins => joins_for_order_statement(order_option),
+ :limit => options[:limit],
+ :offset => options[:offset]
+ )
if has_column?(:spent_hours)
Issue.load_visible_spent_hours(issues)
@@ -721,11 +723,13 @@ class Query < ActiveRecord::Base
# Returns the journals
# Valid options are :order, :offset, :limit
def journals(options={})
- Journal.visible.find :all, :include => [:details, :user, {:issue => [:project, :author, :tracker, :status]}],
- :conditions => statement,
- :order => options[:order],
- :limit => options[:limit],
- :offset => options[:offset]
+ Journal.visible.all(
+ :include => [:details, :user, {:issue => [:project, :author, :tracker, :status]}],
+ :conditions => statement,
+ :order => options[:order],
+ :limit => options[:limit],
+ :offset => options[:offset]
+ )
rescue ::ActiveRecord::StatementInvalid => e
raise StatementInvalid.new(e.message)
end
@@ -733,7 +737,10 @@ class Query < ActiveRecord::Base
# Returns the versions
# Valid options are :conditions
def versions(options={})
- Version.visible.scoped(:conditions => options[:conditions]).find :all, :include => :project, :conditions => project_statement
+ Version.visible.where(options[:conditions]).all(
+ :include => :project,
+ :conditions => project_statement
+ )
rescue ::ActiveRecord::StatementInvalid => e
raise StatementInvalid.new(e.message)
end
diff --git a/lib/plugins/acts_as_versioned/lib/acts_as_versioned.rb b/lib/plugins/acts_as_versioned/lib/acts_as_versioned.rb
index 3c09310f5..b63c891e4 100644
--- a/lib/plugins/acts_as_versioned/lib/acts_as_versioned.rb
+++ b/lib/plugins/acts_as_versioned/lib/acts_as_versioned.rb
@@ -248,14 +248,16 @@ module ActiveRecord #:nodoc:
def self.reloadable? ; false ; end
# find first version before the given version
def self.before(version)
- find :first, :order => 'version desc',
- :conditions => ["#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version]
+ order('version desc').
+ where("#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version).
+ first
end
# find first version after the given version.
def self.after(version)
- find :first, :order => 'version',
- :conditions => ["#{original_class.versioned_foreign_key} = ? and version > ?", version.send(original_class.versioned_foreign_key), version.version]
+ order('version').
+ where("#{original_class.versioned_foreign_key} = ? and version > ?", version.send(original_class.versioned_foreign_key), version.version).
+ first
end
def previous
@@ -467,9 +469,9 @@ module ActiveRecord #:nodoc:
# Finds versions of a specific model. Takes an options hash like <tt>find</tt>
def find_versions(id, options = {})
- versioned_class.find :all, {
+ versioned_class.all({
:conditions => ["#{versioned_foreign_key} = ?", id],
- :order => 'version' }.merge(options)
+ :order => 'version' }.merge(options))
end
# Returns an array of columns that are versioned. See non_versioned_columns
diff --git a/lib/tasks/migrate_from_mantis.rake b/lib/tasks/migrate_from_mantis.rake
index 02ce9f472..8844da65d 100644
--- a/lib/tasks/migrate_from_mantis.rake
+++ b/lib/tasks/migrate_from_mantis.rake
@@ -30,7 +30,7 @@ task :migrate_from_mantis => :environment do
assigned_status = IssueStatus.find_by_position(2)
resolved_status = IssueStatus.find_by_position(3)
feedback_status = IssueStatus.find_by_position(4)
- closed_status = IssueStatus.find :first, :conditions => { :is_closed => true }
+ closed_status = IssueStatus.where(:is_closed => true).first
STATUS_MAPPING = {10 => DEFAULT_STATUS, # new
20 => feedback_status, # feedback
30 => DEFAULT_STATUS, # acknowledged
@@ -347,7 +347,7 @@ task :migrate_from_mantis => :environment do
bug.bug_files.each do |file|
a = Attachment.new :created_on => file.date_added
a.file = file
- a.author = User.find :first
+ a.author = User.first
a.container = i
a.save
end
diff --git a/lib/tasks/migrate_from_trac.rake b/lib/tasks/migrate_from_trac.rake
index e419775d1..95c4b5560 100644
--- a/lib/tasks/migrate_from_trac.rake
+++ b/lib/tasks/migrate_from_trac.rake
@@ -30,7 +30,7 @@ namespace :redmine do
assigned_status = IssueStatus.find_by_position(2)
resolved_status = IssueStatus.find_by_position(3)
feedback_status = IssueStatus.find_by_position(4)
- closed_status = IssueStatus.find :first, :conditions => { :is_closed => true }
+ closed_status = IssueStatus.where(:is_closed => true).first
STATUS_MAPPING = {'new' => DEFAULT_STATUS,
'reopened' => feedback_status,
'assigned' => assigned_status,
diff --git a/test/integration/account_test.rb b/test/integration/account_test.rb
index 36349cf7d..075301dfb 100644
--- a/test/integration/account_test.rb
+++ b/test/integration/account_test.rb
@@ -45,7 +45,7 @@ class AccountTest < ActionController::IntegrationTest
# User logs in with 'autologin' checked
post '/login', :username => user.login, :password => 'admin', :autologin => 1
assert_redirected_to '/my/page'
- token = Token.find :first
+ token = Token.first
assert_not_nil token
assert_equal user, token.user
assert_equal 'autologin', token.action
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index 2bf748682..1ef94c636 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -877,7 +877,7 @@ class IssueTest < ActiveSupport::TestCase
# Closing issue 1
issue1.init_journal(User.first, "Closing issue1")
- issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true}
+ issue1.status = IssueStatus.where(:is_closed => true).first
assert issue1.save
# 2 and 3 should be also closed
assert issue2.reload.closed?
@@ -896,7 +896,7 @@ class IssueTest < ActiveSupport::TestCase
# Closing issue 2
issue2.init_journal(User.first, "Closing issue2")
- issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true}
+ issue2.status = IssueStatus.where(:is_closed => true).first
assert issue2.save
# 1 should not be also closed
assert !issue1.reload.closed?