diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 08c66b57b..9f17bff02 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -258,7 +258,7 @@ class CustomField < ActiveRecord::Base # to move in project_custom_field def self.for_all - find(:all, :conditions => ["is_for_all=?", true], :order => 'position') + where(:is_for_all => true).order('position').all end def type_name diff --git a/app/models/group.rb b/app/models/group.rb index 0eba591b5..f8b1ee639 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -62,8 +62,11 @@ class Group < Principal def user_removed(user) members.each do |member| - MemberRole.find(:all, :include => :member, - :conditions => ["#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids]).each(&:destroy) + MemberRole. + includes(:member). + where("#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids). + all. + each(&:destroy) end end diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index b87fbeda4..3ea251e8b 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -281,7 +281,7 @@ class MailHandler < ActionMailer::Base if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project) addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase} unless addresses.empty? - watchers = User.active.find(:all, :conditions => ['LOWER(mail) IN (?)', addresses]) + watchers = User.active.where('LOWER(mail) IN (?)', addresses).all watchers.each {|w| obj.add_watcher(w)} end end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 9c19438a7..9e9673dc7 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -252,7 +252,7 @@ class Mailer < ActionMailer::Base # Mailer.account_activation_request(user).deliver => sends an email to all active administrators def account_activation_request(user) # Send the email to all active administrators - recipients = User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact + recipients = User.active.where(:admin => true).all.collect { |u| u.mail }.compact @user = user @url = url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, diff --git a/app/models/member_role.rb b/app/models/member_role.rb index a5de3a91d..f5789b325 100644 --- a/app/models/member_role.rb +++ b/app/models/member_role.rb @@ -54,7 +54,7 @@ class MemberRole < ActiveRecord::Base end def remove_role_from_group_users - MemberRole.find(:all, :conditions => { :inherited_from => id }).group_by(&:member).each do |member, member_roles| + MemberRole.where(:inherited_from => id).all.group_by(&:member).each do |member, member_roles| member_roles.each(&:destroy) if member && member.user Watcher.prune(:user => member.user, :project => member.project) diff --git a/app/models/project.rb b/app/models/project.rb index fbc189c0c..d1d89636e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -138,7 +138,7 @@ class Project < ActiveRecord::Base # returns latest created projects # non public projects will be returned only if user is a member of those def self.latest(user=nil, count=5) - visible(user).find(:all, :limit => count, :order => "created_on DESC") + visible(user).limit(count).order("created_on DESC").all end # Returns true if the project is visible to +user+ or to the current user. @@ -338,7 +338,7 @@ class Project < ActiveRecord::Base # by the current user def allowed_parents return @allowed_parents if @allowed_parents - @allowed_parents = Project.find(:all, :conditions => Project.allowed_to_condition(User.current, :add_subprojects)) + @allowed_parents = Project.where(Project.allowed_to_condition(User.current, :add_subprojects)).all @allowed_parents = @allowed_parents - self_and_descendants if User.current.allowed_to?(:add_project, nil, :global => true) || (!new_record? && parent.nil?) @allowed_parents << nil @@ -415,7 +415,7 @@ class Project < ActiveRecord::Base # Closes open and locked project versions that are completed def close_completed_versions Version.transaction do - versions.find(:all, :conditions => {:status => %w(open locked)}).each do |version| + versions.where(:status => %w(open locked)).all.each do |version| if version.completed? version.update_attribute(:status, 'closed') end @@ -452,7 +452,7 @@ class Project < ActiveRecord::Base # Returns a hash of project users grouped by role def users_by_role - members.find(:all, :include => [:user, :roles]).inject({}) do |h, m| + members.includes(:user, :roles).all.inject({}) do |h, m| m.roles.each do |r| h[r] ||= [] h[r] << m.user @@ -786,7 +786,7 @@ class Project < ActiveRecord::Base # Get issues sorted by root_id, lft so that parent issues # get copied before their children - project.issues.find(:all, :order => 'root_id, lft').each do |issue| + project.issues.reorder('root_id, lft').all.each do |issue| new_issue = Issue.new new_issue.copy_from(issue, :subtasks => false, :link => false) new_issue.project = self @@ -929,13 +929,11 @@ class Project < ActiveRecord::Base def system_activities_and_project_overrides(include_inactive=false) if include_inactive return TimeEntryActivity.shared. - find(:all, - :conditions => ["id NOT IN (?)", self.time_entry_activities.collect(&:parent_id)]) + + where("id NOT IN (?)", self.time_entry_activities.collect(&:parent_id)).all + self.time_entry_activities else return TimeEntryActivity.shared.active. - find(:all, - :conditions => ["id NOT IN (?)", self.time_entry_activities.collect(&:parent_id)]) + + where("id NOT IN (?)", self.time_entry_activities.collect(&:parent_id)).all + self.time_entry_activities.active end end diff --git a/app/models/query.rb b/app/models/query.rb index 0f6ae3a1d..84f8c3ef6 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -218,7 +218,7 @@ class Query < ActiveRecord::Base end def trackers - @trackers ||= project.nil? ? Tracker.find(:all, :order => 'position') : project.rolled_up_trackers + @trackers ||= project.nil? ? Tracker.sorted.all : project.rolled_up_trackers end # Returns a hash of localized labels for all filter operators @@ -231,7 +231,7 @@ class Query < ActiveRecord::Base @available_filters = { "status_id" => { :type => :list_status, :order => 0, - :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } + :values => IssueStatus.sorted.all.collect{|s| [s.name, s.id.to_s] } }, "tracker_id" => { :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] } @@ -344,12 +344,7 @@ class Query < ActiveRecord::Base } } end - add_custom_fields_filters( - IssueCustomField.find(:all, - :conditions => { - :is_filter => true, - :is_for_all => true - })) + add_custom_fields_filters(IssueCustomField.where(:is_filter => true, :is_for_all => true).all) end add_associations_custom_fields_filters :project, :author, :assigned_to, :fixed_version if User.current.allowed_to?(:set_issues_private, nil, :global => true) || @@ -455,7 +450,7 @@ class Query < ActiveRecord::Base @available_columns = ::Query.available_columns.dup @available_columns += (project ? project.all_issue_custom_fields : - IssueCustomField.find(:all) + IssueCustomField.all ).collect {|cf| QueryCustomFieldColumn.new(cf) } if User.current.allowed_to?(:view_time_entries, project, :global => true) diff --git a/app/models/repository.rb b/app/models/repository.rb index 838984158..e31bc3557 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -337,7 +337,7 @@ class Repository < ActiveRecord::Base # scan changeset comments to find related and fixed issues for all repositories def self.scan_changesets_for_issue_ids - find(:all).each(&:scan_changesets_for_issue_ids) + all.each(&:scan_changesets_for_issue_ids) end def self.scm_name diff --git a/app/models/repository/mercurial.rb b/app/models/repository/mercurial.rb index 54262d9a6..ac10e064c 100644 --- a/app/models/repository/mercurial.rb +++ b/app/models/repository/mercurial.rb @@ -92,11 +92,12 @@ class Repository::Mercurial < Repository # Sqlite3 and PostgreSQL pass. # Is this MySQL bug? def latest_changesets(path, rev, limit=10) - changesets.find(:all, - :include => :user, - :conditions => latest_changesets_cond(path, rev, limit), - :limit => limit, - :order => "#{Changeset.table_name}.id DESC") + changesets. + includes(:user). + where(latest_changesets_cond(path, rev, limit)). + limit(limit). + order("#{Changeset.table_name}.id DESC"). + all end def latest_changesets_cond(path, rev, limit) diff --git a/app/models/watcher.rb b/app/models/watcher.rb index d9ce65fb6..2f5841bb5 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -29,7 +29,7 @@ class Watcher < ActiveRecord::Base prune_single_user(options[:user], options) else pruned = 0 - User.find(:all, :conditions => "id IN (SELECT DISTINCT user_id FROM #{table_name})").each do |user| + User.where("id IN (SELECT DISTINCT user_id FROM #{table_name})").all.each do |user| pruned += prune_single_user(user, options) end pruned @@ -47,7 +47,7 @@ class Watcher < ActiveRecord::Base def self.prune_single_user(user, options={}) return unless user.is_a?(User) pruned = 0 - find(:all, :conditions => {:user_id => user.id}).each do |watcher| + where(:user_id => user.id).all.each do |watcher| next if watcher.watchable.nil? if options.has_key?(:project) diff --git a/app/views/groups/_memberships.html.erb b/app/views/groups/_memberships.html.erb index 295f7fc3d..8880c12a0 100644 --- a/app/views/groups/_memberships.html.erb +++ b/app/views/groups/_memberships.html.erb @@ -1,5 +1,5 @@ <% roles = Role.find_all_givable %> -<% projects = Project.active.find(:all, :order => 'lft') %> +<% projects = Project.active.all %>
<%= setting_text_field :commit_fix_keywords, :size => 30 %> <%= l(:label_applied_status) %>: <%= setting_select :commit_fix_status_id, [["", 0]] + - IssueStatus.find(:all).collect{ + IssueStatus.sorted.all.collect{ |status| [status.name, status.id.to_s] }, :label => false %> diff --git a/app/views/users/_memberships.html.erb b/app/views/users/_memberships.html.erb index 9a8241cb1..5f61d2ce2 100644 --- a/app/views/users/_memberships.html.erb +++ b/app/views/users/_memberships.html.erb @@ -1,5 +1,5 @@ <% roles = Role.find_all_givable %> -<% projects = Project.active.find(:all, :order => 'lft') %> +<% projects = Project.active.all %>
#{result}
", textilizable(text, :attachments => attachments) } end diff --git a/test/unit/issue_nested_set_test.rb b/test/unit/issue_nested_set_test.rb index d796edf94..25f02c5bc 100644 --- a/test/unit/issue_nested_set_test.rb +++ b/test/unit/issue_nested_set_test.rb @@ -367,7 +367,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase c.reload assert_equal 5, c.issues.count - ic1, ic2, ic3, ic4, ic5 = c.issues.find(:all, :order => 'subject') + ic1, ic2, ic3, ic4, ic5 = c.issues.order('subject').all assert ic1.root? assert_equal ic1, ic2.parent assert_equal ic1, ic3.parent diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 30b3f0d6a..28a478e60 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -183,7 +183,7 @@ class ProjectTest < ActiveSupport::TestCase # 2 active members assert_equal 2, @ecookbook.members.size # and 1 is locked - assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size + assert_equal 3, Member.where('project_id = ?', @ecookbook.id).all.size # some boards assert @ecookbook.boards.any? @@ -693,7 +693,7 @@ class ProjectTest < ActiveSupport::TestCase def test_activities_should_use_the_system_activities project = Project.find(1) - assert_equal project.activities, TimeEntryActivity.find(:all, :conditions => {:active => true} ) + assert_equal project.activities, TimeEntryActivity.where(:active => true).all end diff --git a/test/unit/repository_bazaar_test.rb b/test/unit/repository_bazaar_test.rb index 656161a74..94ed9858e 100644 --- a/test/unit/repository_bazaar_test.rb +++ b/test/unit/repository_bazaar_test.rb @@ -105,7 +105,7 @@ class RepositoryBazaarTest < ActiveSupport::TestCase @project.reload assert_equal NUM_REV, @repository.changesets.count # Remove changesets with revision > 5 - @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} + @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 2} @project.reload assert_equal 2, @repository.changesets.count diff --git a/test/unit/repository_cvs_test.rb b/test/unit/repository_cvs_test.rb index b718246b2..05f59d8a6 100644 --- a/test/unit/repository_cvs_test.rb +++ b/test/unit/repository_cvs_test.rb @@ -116,7 +116,7 @@ class RepositoryCvsTest < ActiveSupport::TestCase assert_equal CHANGESETS_NUM, @repository.changesets.count # Remove changesets with revision > 3 - @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3} + @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 3} @project.reload assert_equal 3, @repository.changesets.count assert_equal %w|3 2 1|, @repository.changesets.all.collect(&:revision) diff --git a/test/unit/repository_darcs_test.rb b/test/unit/repository_darcs_test.rb index 53c91abb3..b1007580e 100644 --- a/test/unit/repository_darcs_test.rb +++ b/test/unit/repository_darcs_test.rb @@ -79,7 +79,7 @@ class RepositoryDarcsTest < ActiveSupport::TestCase assert_equal NUM_REV, @repository.changesets.count # Remove changesets with revision > 3 - @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3} + @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 3} @project.reload assert_equal 3, @repository.changesets.count diff --git a/test/unit/repository_mercurial_test.rb b/test/unit/repository_mercurial_test.rb index f64300748..00201efc2 100644 --- a/test/unit/repository_mercurial_test.rb +++ b/test/unit/repository_mercurial_test.rb @@ -102,7 +102,7 @@ class RepositoryMercurialTest < ActiveSupport::TestCase @project.reload assert_equal NUM_REV, @repository.changesets.count # Remove changesets with revision > 2 - @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} + @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 2} @project.reload assert_equal 3, @repository.changesets.count diff --git a/test/unit/repository_subversion_test.rb b/test/unit/repository_subversion_test.rb index e2550453a..0783b16e6 100644 --- a/test/unit/repository_subversion_test.rb +++ b/test/unit/repository_subversion_test.rb @@ -47,7 +47,7 @@ class RepositorySubversionTest < ActiveSupport::TestCase assert_equal NUM_REV, @repository.changesets.count # Remove changesets with revision > 5 - @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5} + @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 5} @project.reload assert_equal 5, @repository.changesets.count