]> source.dussan.org Git - redmine.git/commitdiff
Replaces find(:first) calls.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 3 Dec 2012 18:21:32 +0000 (18:21 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 3 Dec 2012 18:21:32 +0000 (18:21 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10928 e93f8b46-1217-0410-a6f0-8f06a7374b81

31 files changed:
app/controllers/auth_sources_controller.rb
app/helpers/application_helper.rb
app/models/document.rb
app/models/mail_handler.rb
app/models/project.rb
app/models/repository.rb
app/models/user.rb
lib/redmine/default_data/loader.rb
lib/tasks/migrate_from_trac.rake
test/functional/enumerations_controller_test.rb
test/functional/files_controller_test.rb
test/functional/issue_categories_controller_test.rb
test/functional/issue_statuses_controller_test.rb
test/functional/issues_controller_test.rb
test/functional/messages_controller_test.rb
test/functional/project_enumerations_controller_test.rb
test/functional/welcome_controller_test.rb
test/functional/workflows_controller_test.rb
test/integration/account_test.rb
test/unit/document_category_test.rb
test/unit/enumeration_test.rb
test/unit/issue_test.rb
test/unit/journal_observer_test.rb
test/unit/journal_test.rb
test/unit/mailer_test.rb
test/unit/news_test.rb
test/unit/project_test.rb
test/unit/repository_cvs_test.rb
test/unit/repository_test.rb
test/unit/version_test.rb
test/unit/wiki_redirect_test.rb

index 8b8ee8d05f3c27096a45cbaee5269cf481acc859..c850bc83d3e2e3c260b6b72f5b6d644cdc5d5844 100644 (file)
@@ -67,7 +67,7 @@ class AuthSourcesController < ApplicationController
 
   def destroy
     @auth_source = AuthSource.find(params[:id])
-    unless @auth_source.users.find(:first)
+    unless @auth_source.users.exists?
       @auth_source.destroy
       flash[:notice] = l(:notice_successful_delete)
     end
index 2eaee8b22d355daef065415883a310a242b65d82..8173bdb44b48ea62a1d6bbbcbaf4565a10a6e11e 100644 (file)
@@ -799,7 +799,7 @@ module ApplicationHelper
                 repository = project.repository
               end
               if prefix == 'commit'
-                if repository && (changeset = Changeset.visible.find(:first, :conditions => ["repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%"]))
+                if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first)
                   link = link_to h("#{project_prefix}#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.identifier},
                                                :class => 'changeset',
                                                :title => truncate_single_line(h(changeset.comments), :length => 100)
@@ -824,7 +824,7 @@ module ApplicationHelper
                                                      :class => 'attachment'
             end
           when 'project'
-            if p = Project.visible.find(:first, :conditions => ["identifier = :s OR LOWER(name) = :s", {:s => name.downcase}])
+            if p = Project.visible.where("identifier = :s OR LOWER(name) = :s", :s => name.downcase).first
               link = link_to_project(p, {:only_path => only_path}, :class => 'project')
             end
           end
index 0eaf171edf52f3f9e921337f6652be88f5e21e86..3fd43e1c0c139363b0d4f5e3f27c03af646183a4 100644 (file)
@@ -23,7 +23,7 @@ class Document < ActiveRecord::Base
 
   acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
   acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
-                :author => Proc.new {|o| (a = o.attachments.find(:first, :order => "#{Attachment.table_name}.created_on ASC")) ? a.author : nil },
+                :author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) },
                 :url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
   acts_as_activity_provider :find_options => {:include => :project}
 
index 3ea251e8bd4d8707cb0619acb36c2cc2d440bea7..3b72ef2840978ca9785243b6a4e6744a990a12ea 100644 (file)
@@ -355,7 +355,7 @@ class MailHandler < ActionMailer::Base
     }.delete_if {|k, v| v.blank? }
 
     if issue.new_record? && attrs['tracker_id'].nil?
-      attrs['tracker_id'] = issue.project.trackers.find(:first).try(:id)
+      attrs['tracker_id'] = issue.project.trackers.first.try(:id)
     end
 
     attrs
index 5a8ba855b885c90d029be12327be238722ac6259..174f63c3ada2cd2c07ade5641b670a5fc2b20fce 100644 (file)
@@ -308,9 +308,12 @@ class Project < ActiveRecord::Base
     # Check that there is no issue of a non descendant project that is assigned
     # to one of the project or descendant versions
     v_ids = self_and_descendants.collect {|p| p.version_ids}.flatten
-    if v_ids.any? && Issue.find(:first, :include => :project,
-                                        :conditions => ["(#{Project.table_name}.lft < ? OR #{Project.table_name}.rgt > ?)" +
-                                                        " AND #{Issue.table_name}.fixed_version_id IN (?)", lft, rgt, v_ids])
+    if v_ids.any? &&
+      Issue.
+        includes(:project).
+        where("#{Project.table_name}.lft < ? OR #{Project.table_name}.rgt > ?", lft, rgt).
+        where("#{Issue.table_name}.fixed_version_id IN (?)", v_ids).
+        exists?
       return false
     end
     Project.transaction do
@@ -655,7 +658,7 @@ class Project < ActiveRecord::Base
 
   # Returns an auto-generated project identifier based on the last identifier used
   def self.next_identifier
-    p = Project.find(:first, :order => 'created_on DESC')
+    p = Project.order('created_on DESC').first
     p.nil? ? nil : p.identifier.to_s.succ
   end
 
index e31bc355788b0d74a80b6011137238397c6d8816..a8e967d0d16e28068c5bf65d43eea7b6921adea7 100644 (file)
@@ -234,12 +234,15 @@ class Repository < ActiveRecord::Base
   def find_changeset_by_name(name)
     return nil if name.blank?
     s = name.to_s
-    changesets.find(:first, :conditions => (s.match(/^\d*$/) ?
-          ["revision = ?", s] : ["revision LIKE ?", s + '%']))
+    if s.match(/^\d*$/)
+      changesets.where("revision = ?", s).first
+    else
+      changesets.where("revision LIKE ?", s + '%').first
+    end
   end
 
   def latest_changeset
-    @latest_changeset ||= changesets.find(:first)
+    @latest_changeset ||= changesets.first
   end
 
   # Returns the latest changesets for +path+
@@ -301,7 +304,7 @@ class Repository < ActiveRecord::Base
       return @found_committer_users[committer] if @found_committer_users.has_key?(committer)
 
       user = nil
-      c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user)
+      c = changesets.where(:committer => committer).includes(:user).first
       if c && c.user
         user = c.user
       elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/
index 9a432fc2e8a62740fc3fde4dc93d4eff9c2d8d03..0cf2c931407370b90e461dd41841ed42b6d2154a 100644 (file)
@@ -686,7 +686,7 @@ class AnonymousUser < User
 
   def validate_anonymous_uniqueness
     # There should be only one AnonymousUser in the database
-    errors.add :base, 'An anonymous user already exists.' if AnonymousUser.find(:first)
+    errors.add :base, 'An anonymous user already exists.' if AnonymousUser.exists?
   end
 
   def available_custom_fields
index 70629e9d36112115862b0902a0d3135b1a2a3c2b..20ba6eabb9b6370cda59b1fef549522c7533e405 100644 (file)
@@ -26,10 +26,10 @@ module Redmine
         # Returns true if no data is already loaded in the database
         # otherwise false
         def no_data?
-          !Role.find(:first, :conditions => {:builtin => 0}) &&
-            !Tracker.find(:first) &&
-            !IssueStatus.find(:first) &&
-            !Enumeration.find(:first)
+          !Role.where(:builtin => 0).exists? &&
+            !Tracker.exists? &&
+            !IssueStatus.exists? &&
+            !Enumeration.exists?
         end
 
         # Loads the default data
index 1c7b7bb381881b45d381b48acf6842fcee069c0b..e419775d18e81e444acdc67d538faa518dd79893 100644 (file)
@@ -257,7 +257,7 @@ namespace :redmine do
           u.password = 'trac'
           u.admin = true if TracPermission.find_by_username_and_action(username, 'admin')
           # finally, a default user is used if the new user is not valid
-          u = User.find(:first) unless u.save
+          u = User.first unless u.save
         end
         # Make sure he is a member of the project
         if project_member && !u.member_of?(@target_project)
@@ -450,7 +450,7 @@ namespace :redmine do
         puts
 
         # Trac 'resolution' field as a Redmine custom field
-        r = IssueCustomField.find(:first, :conditions => { :name => "Resolution" })
+        r = IssueCustomField.where(:name => "Resolution").first
         r = IssueCustomField.new(:name => 'Resolution',
                                  :field_format => 'list',
                                  :is_filter => true) if r.nil?
index dba0720d6d23a6a55c711e714df5a6c6041f8f7b..29e3eb1ec948502ad4017457bfa61ea430705d89 100644 (file)
@@ -117,7 +117,7 @@ class EnumerationsControllerTest < ActionController::TestCase
   end
 
   def test_destroy_enumeration_in_use_with_reassignment
-    issue = Issue.find(:first, :conditions => {:priority_id => 4})
+    issue = Issue.where(:priority_id => 4).first
     assert_difference 'IssuePriority.count', -1 do
       delete :destroy, :id => 4, :reassign_to_id => 6
     end
index 5e3c9d68b9656c73e198ece5b2b1d93caf0974e7..8691a18180880efca979bba8de79b34bd22cee9b 100644 (file)
@@ -68,7 +68,7 @@ class FilesControllerTest < ActionController::TestCase
       end
     end
     assert_redirected_to '/projects/ecookbook/files'
-    a = Attachment.find(:first, :order => 'created_on DESC')
+    a = Attachment.order('created_on DESC').first
     assert_equal 'testfile.txt', a.filename
     assert_equal Project.find(1), a.container
 
@@ -88,7 +88,7 @@ class FilesControllerTest < ActionController::TestCase
       assert_response :redirect
     end
     assert_redirected_to '/projects/ecookbook/files'
-    a = Attachment.find(:first, :order => 'created_on DESC')
+    a = Attachment.order('created_on DESC').first
     assert_equal 'testfile.txt', a.filename
     assert_equal Version.find(2), a.container
   end
index 33141f4635c7487ab2fe56d8949a0d7a405c164a..6f45cf1a69c1da1755b31cc7eaea06e5226b4b8e 100644 (file)
@@ -133,7 +133,7 @@ class IssueCategoriesControllerTest < ActionController::TestCase
   end
 
   def test_destroy_category_in_use_with_reassignment
-    issue = Issue.find(:first, :conditions => {:category_id => 1})
+    issue = Issue.where(:category_id => 1).first
     delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
     assert_redirected_to '/projects/ecookbook/settings/categories'
     assert_nil IssueCategory.find_by_id(1)
@@ -142,7 +142,7 @@ class IssueCategoriesControllerTest < ActionController::TestCase
   end
 
   def test_destroy_category_in_use_without_reassignment
-    issue = Issue.find(:first, :conditions => {:category_id => 1})
+    issue = Issue.where(:category_id => 1).first
     delete :destroy, :id => 1, :todo => 'nullify'
     assert_redirected_to '/projects/ecookbook/settings/categories'
     assert_nil IssueCategory.find_by_id(1)
index bfed246b6622bf72b4708065ef52df2f5bc4601c..1662413e0c5b502424a875b8227ec73aa69bcee7 100644 (file)
@@ -45,7 +45,7 @@ class IssueStatusesControllerTest < ActionController::TestCase
       post :create, :issue_status => {:name => 'New status'}
     end
     assert_redirected_to :action => 'index'
-    status = IssueStatus.find(:first, :order => 'id DESC')
+    status = IssueStatus.order('id DESC').first
     assert_equal 'New status', status.name
   end
 
index 69545bf92a1c9e07b0dc06bcd319d5d9972b9b30..03e2b52c5d2445fe5c842e6fda9b236211a96eab 100644 (file)
@@ -1709,7 +1709,7 @@ class IssuesControllerTest < ActionController::TestCase
     assert_equal 2, issue.status_id
     assert_equal Date.parse('2010-11-07'), issue.start_date
     assert_nil issue.estimated_hours
-    v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
+    v = issue.custom_values.where(:custom_field_id => 2).first
     assert_not_nil v
     assert_equal 'Value for field 2', v.value
   end
@@ -2817,7 +2817,7 @@ class IssuesControllerTest < ActionController::TestCase
     assert_redirected_to :action => 'show', :id => '1'
     issue.reload
     assert_equal 2, issue.status_id
-    j = Journal.find(:first, :order => 'id DESC')
+    j = Journal.order('id DESC').first
     assert_equal 'Assigned to dlopper', j.notes
     assert_equal 2, j.details.size
 
@@ -2834,7 +2834,7 @@ class IssuesControllerTest < ActionController::TestCase
          :id => 1,
          :issue => { :notes => notes }
     assert_redirected_to :action => 'show', :id => '1'
-    j = Journal.find(:first, :order => 'id DESC')
+    j = Journal.order('id DESC').first
     assert_equal notes, j.notes
     assert_equal 0, j.details.size
     assert_equal User.anonymous, j.user
@@ -2890,7 +2890,7 @@ class IssuesControllerTest < ActionController::TestCase
 
     issue = Issue.find(1)
 
-    j = Journal.find(:first, :order => 'id DESC')
+    j = Journal.order('id DESC').first
     assert_equal '2.5 hours added', j.notes
     assert_equal 0, j.details.size
 
@@ -2915,7 +2915,7 @@ class IssuesControllerTest < ActionController::TestCase
     end
 
     assert_redirected_to :action => 'show', :id => '1'
-    j = Issue.find(1).journals.find(:first, :order => 'id DESC')
+    j = Issue.find(1).journals.reorder('id DESC').first
     assert j.notes.blank?
     assert_equal 1, j.details.size
     assert_equal 'testfile.txt', j.details.first.value
@@ -3278,7 +3278,7 @@ class IssuesControllerTest < ActionController::TestCase
     assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
 
     issue = Issue.find(1)
-    journal = issue.journals.find(:first, :order => 'created_on DESC')
+    journal = issue.journals.reorder('created_on DESC').first
     assert_equal '125', issue.custom_value_for(2).value
     assert_equal 'Bulk editing', journal.notes
     assert_equal 1, journal.details.size
@@ -3313,7 +3313,7 @@ class IssuesControllerTest < ActionController::TestCase
     assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
 
     issue = Issue.find(1)
-    journal = issue.journals.find(:first, :order => 'created_on DESC')
+    journal = issue.journals.reorder('created_on DESC').first
     assert_equal '125', issue.custom_value_for(2).value
     assert_equal 'Bulk editing', journal.notes
     assert_equal 1, journal.details.size
@@ -3438,7 +3438,7 @@ class IssuesControllerTest < ActionController::TestCase
     assert_response 302
 
     issue = Issue.find(1)
-    journal = issue.journals.find(:first, :order => 'created_on DESC')
+    journal = issue.journals.reorder('created_on DESC').first
     assert_equal '777', issue.custom_value_for(2).value
     assert_equal 1, journal.details.size
     assert_equal '125', journal.details.first.old_value
index 4bf8ff90f3d6f733d8228ffa9b166504a7b3de08..0276928e2d81422debe8e3dbc6d29fcc0adb41ec 100644 (file)
@@ -159,7 +159,7 @@ class MessagesControllerTest < ActionController::TestCase
   def test_reply
     @request.session[:user_id] = 2
     post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
-    reply = Message.find(:first, :order => 'id DESC')
+    reply = Message.order('id DESC').first
     assert_redirected_to "/boards/1/topics/1?r=#{reply.id}"
     assert Message.find_by_subject('Test reply')
   end
index 9d9a8fed23e121ecd94fc81f594cbe1c38544781..a50f7968f4cf82ee23146a50068d5e0a7f41a95f 100644 (file)
@@ -75,14 +75,14 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase
 
     project_activity = TimeEntryActivity.new({
                                                :name => 'Project Specific',
-                                               :parent => TimeEntryActivity.find(:first),
+                                               :parent => TimeEntryActivity.first,
                                                :project => Project.find(1),
                                                :active => true
                                              })
     assert project_activity.save
     project_activity_two = TimeEntryActivity.new({
                                                    :name => 'Project Specific Two',
-                                                   :parent => TimeEntryActivity.find(:last),
+                                                   :parent => TimeEntryActivity.last,
                                                    :project => Project.find(1),
                                                    :active => true
                                                  })
@@ -156,14 +156,14 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase
     @request.session[:user_id] = 2 # manager
     project_activity = TimeEntryActivity.new({
                                                :name => 'Project Specific',
-                                               :parent => TimeEntryActivity.find(:first),
+                                               :parent => TimeEntryActivity.first,
                                                :project => Project.find(1),
                                                :active => true
                                              })
     assert project_activity.save
     project_activity_two = TimeEntryActivity.new({
                                                    :name => 'Project Specific Two',
-                                                   :parent => TimeEntryActivity.find(:last),
+                                                   :parent => TimeEntryActivity.last,
                                                    :project => Project.find(1),
                                                    :active => true
                                                  })
index 79c7855885e537552209231739b81fd61e9087f5..5502773a48f8e710c1ce3b112e7fd60b207f1e8b 100644 (file)
@@ -37,7 +37,7 @@ class WelcomeControllerTest < ActionController::TestCase
     assert_template 'index'
     assert_not_nil assigns(:news)
     assert_not_nil assigns(:projects)
-    assert !assigns(:projects).include?(Project.find(:first, :conditions => {:is_public => false}))
+    assert !assigns(:projects).include?(Project.where(:is_public => false).first)
   end
 
   def test_browser_language
index 6ec74316172588337650dae359bc330324044f42..97387489b2cccd7e80727e255b6e929ab432d06d 100644 (file)
@@ -102,9 +102,9 @@ class WorkflowsControllerTest < ActionController::TestCase
       }
     assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1'
 
-    assert_equal 3, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2})
-    assert_not_nil  WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
-    assert_nil      WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4})
+    assert_equal 3, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count
+    assert_not_nil  WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first
+    assert_nil      WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4).first
   end
 
   def test_post_edit_with_additional_transitions
@@ -115,18 +115,18 @@ class WorkflowsControllerTest < ActionController::TestCase
       }
     assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1'
 
-    assert_equal 4, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2})
+    assert_equal 4, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count
 
-    w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5})
+    w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5).first
     assert ! w.author
     assert ! w.assignee
-    w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1})
+    w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1).first
     assert w.author
     assert ! w.assignee
-    w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
+    w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first
     assert ! w.author
     assert w.assignee
-    w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4})
+    w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4).first
     assert w.author
     assert w.assignee
   end
index e16cda96b510bcf4805b02e8d7bb6817c6b8ebf6..36349cf7d65c2efab6a369e425ad5f8718119fdc 100644 (file)
@@ -79,7 +79,7 @@ class AccountTest < ActionController::IntegrationTest
     post "account/lost_password", :mail => 'jSmith@somenet.foo'
     assert_redirected_to "/login"
 
-    token = Token.find(:first)
+    token = Token.first
     assert_equal 'recovery', token.action
     assert_equal 'jsmith@somenet.foo', token.user.mail
     assert !token.expired?
@@ -137,7 +137,7 @@ class AccountTest < ActionController::IntegrationTest
     assert_redirected_to '/login'
     assert !User.find_by_login('newuser').active?
 
-    token = Token.find(:first)
+    token = Token.first
     assert_equal 'register', token.action
     assert_equal 'newuser@foo.bar', token.user.mail
     assert !token.expired?
index 03fa1b947e22211bafcaabb7458418a2cbd3e422..8a474a098f6305201ece95be83399f270cc7f1df 100644 (file)
@@ -34,14 +34,14 @@ class DocumentCategoryTest < ActiveSupport::TestCase
   end
 
   def test_default
-    assert_nil DocumentCategory.find(:first, :conditions => { :is_default => true })
+    assert_nil DocumentCategory.where(:is_default => true).first
     e = Enumeration.find_by_name('Technical documentation')
     e.update_attributes(:is_default => true)
     assert_equal 3, DocumentCategory.default.id
   end
 
   def test_force_default
-    assert_nil DocumentCategory.find(:first, :conditions => { :is_default => true })
+    assert_nil DocumentCategory.where(:is_default => true).first
     assert_equal 1, DocumentCategory.default.id
   end
 end
index bd098a13b9dccf7171f04a37c6e45e53a12aa7ca..48cd028933a007923322d7a83245f63af4e862e1 100644 (file)
@@ -86,7 +86,7 @@ class EnumerationTest < ActiveSupport::TestCase
 
   def test_destroy_with_reassign
     Enumeration.find(4).destroy(Enumeration.find(6))
-    assert_nil Issue.find(:first, :conditions => {:priority_id => 4})
+    assert_nil Issue.where(:priority_id => 4).first
     assert_equal 6, Enumeration.find(6).objects_count
   end
 
index 655edb53c85358594886fe4f73e0b76df3b3faa4..2bf748682d7a586201a79ea58a029db7e089da50 100644 (file)
@@ -876,7 +876,7 @@ class IssueTest < ActiveSupport::TestCase
     assert issue1.reload.duplicates.include?(issue2)
 
     # Closing issue 1
-    issue1.init_journal(User.find(:first), "Closing issue1")
+    issue1.init_journal(User.first, "Closing issue1")
     issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true}
     assert issue1.save
     # 2 and 3 should be also closed
@@ -895,7 +895,7 @@ class IssueTest < ActiveSupport::TestCase
     assert !issue2.reload.duplicates.include?(issue1)
 
     # Closing issue 2
-    issue2.init_journal(User.find(:first), "Closing issue2")
+    issue2.init_journal(User.first, "Closing issue2")
     issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true}
     assert issue2.save
     # 1 should not be also closed
@@ -1431,8 +1431,7 @@ class IssueTest < ActiveSupport::TestCase
     assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue?
     assert !Issue.new(:due_date => nil).overdue?
     assert !Issue.new(:due_date => 1.day.ago.to_date,
-                      :status => IssueStatus.find(:first,
-                                                  :conditions => {:is_closed => true})
+                      :status => IssueStatus.where(:is_closed => true).first
                       ).overdue?
   end
 
@@ -1630,7 +1629,7 @@ class IssueTest < ActiveSupport::TestCase
   end
 
   def test_saving_twice_should_not_duplicate_journal_details
-    i = Issue.find(:first)
+    i = Issue.first
     i.init_journal(User.find(2), 'Some notes')
     # initial changes
     i.subject = 'New subject'
@@ -1639,7 +1638,7 @@ class IssueTest < ActiveSupport::TestCase
       assert i.save
     end
     # 1 more change
-    i.priority = IssuePriority.find(:first, :conditions => ["id <> ?", i.priority_id])
+    i.priority = IssuePriority.where("id <> ?", i.priority_id).first
     assert_no_difference 'Journal.count' do
       assert_difference 'JournalDetail.count', 1 do
         i.save
index e9049ac8e3ead67dd05625c8c0b88ae3cf9ed33d..d54228210b5bc83355003b5a0200fd38ca03bc4c 100644 (file)
@@ -29,8 +29,8 @@ class JournalObserverTest < ActiveSupport::TestCase
 
   # context: issue_updated notified_events
   def test_create_should_send_email_notification_with_issue_updated
-    issue = Issue.find(:first)
-    user = User.find(:first)
+    issue = Issue.first
+    user = User.first
     journal = issue.init_journal(user, issue)
 
     with_settings :notified_events => %w(issue_updated) do
@@ -40,8 +40,8 @@ class JournalObserverTest < ActiveSupport::TestCase
   end
 
   def test_create_should_not_send_email_notification_with_notify_set_to_false
-    issue = Issue.find(:first)
-    user = User.find(:first)
+    issue = Issue.first
+    user = User.first
     journal = issue.init_journal(user, issue)
     journal.notify = false
 
@@ -52,8 +52,8 @@ class JournalObserverTest < ActiveSupport::TestCase
   end
 
   def test_create_should_not_send_email_notification_without_issue_updated
-    issue = Issue.find(:first)
-    user = User.find(:first)
+    issue = Issue.first
+    user = User.first
     journal = issue.init_journal(user, issue)
 
     with_settings :notified_events => [] do
@@ -64,8 +64,8 @@ class JournalObserverTest < ActiveSupport::TestCase
 
   # context: issue_note_added notified_events
   def test_create_should_send_email_notification_with_issue_note_added
-    issue = Issue.find(:first)
-    user = User.find(:first)
+    issue = Issue.first
+    user = User.first
     journal = issue.init_journal(user, issue)
     journal.notes = 'This update has a note'
 
@@ -76,8 +76,8 @@ class JournalObserverTest < ActiveSupport::TestCase
   end
 
   def test_create_should_not_send_email_notification_without_issue_note_added
-    issue = Issue.find(:first)
-    user = User.find(:first)
+    issue = Issue.first
+    user = User.first
     journal = issue.init_journal(user, issue)
     journal.notes = 'This update has a note'
 
@@ -89,8 +89,8 @@ class JournalObserverTest < ActiveSupport::TestCase
 
   # context: issue_status_updated notified_events
   def test_create_should_send_email_notification_with_issue_status_updated
-    issue = Issue.find(:first)
-    user = User.find(:first)
+    issue = Issue.first
+    user = User.first
     issue.init_journal(user, issue)
     issue.status = IssueStatus.last
 
@@ -101,8 +101,8 @@ class JournalObserverTest < ActiveSupport::TestCase
   end
 
   def test_create_should_not_send_email_notification_without_issue_status_updated
-    issue = Issue.find(:first)
-    user = User.find(:first)
+    issue = Issue.first
+    user = User.first
     issue.init_journal(user, issue)
     issue.status = IssueStatus.last
 
@@ -114,8 +114,8 @@ class JournalObserverTest < ActiveSupport::TestCase
 
   # context: issue_priority_updated notified_events
   def test_create_should_send_email_notification_with_issue_priority_updated
-    issue = Issue.find(:first)
-    user = User.find(:first)
+    issue = Issue.first
+    user = User.first
     issue.init_journal(user, issue)
     issue.priority = IssuePriority.last
 
@@ -126,8 +126,8 @@ class JournalObserverTest < ActiveSupport::TestCase
   end
 
   def test_create_should_not_send_email_notification_without_issue_priority_updated
-    issue = Issue.find(:first)
-    user = User.find(:first)
+    issue = Issue.first
+    user = User.first
     issue.init_journal(user, issue)
     issue.priority = IssuePriority.last
 
index 315ea51cfe8548134ef7309808ec0d5ead42105c..bec497f466ab0c081cc4b9ad88fcc48d948f504f 100644 (file)
@@ -41,8 +41,8 @@ class JournalTest < ActiveSupport::TestCase
 
   def test_create_should_send_email_notification
     ActionMailer::Base.deliveries.clear
-    issue = Issue.find(:first)
-    user = User.find(:first)
+    issue = Issue.first
+    user = User.first
     journal = issue.init_journal(user, issue)
 
     assert journal.save
index a92f738a79ba8589892065c7f78eb7fc951161e5..d6c9b7e0f1dd3a671a601b011a3e0e64e097bf6e 100644 (file)
@@ -210,7 +210,7 @@ class MailerTest < ActiveSupport::TestCase
   end
 
   def test_should_not_send_email_without_recipient
-    news = News.find(:first)
+    news = News.first
     user = news.author
     # Remove members except news author
     news.project.memberships.each {|m| m.destroy unless m.user == user}
@@ -402,7 +402,7 @@ class MailerTest < ActiveSupport::TestCase
   end
 
   def test_news_added
-    news = News.find(:first)
+    news = News.first
     valid_languages.each do |lang|
       Setting.default_language = lang.to_s
       assert Mailer.news_added(news).deliver
@@ -418,7 +418,7 @@ class MailerTest < ActiveSupport::TestCase
   end
 
   def test_message_posted
-    message = Message.find(:first)
+    message = Message.first
     recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
     recipients = recipients.compact.uniq
     valid_languages.each do |lang|
index 94054e5a73550993b1f400482f864d67219e2152..2ad90ce4072772eda4202248bdca74a6f50f7be4 100644 (file)
@@ -21,7 +21,7 @@ class NewsTest < ActiveSupport::TestCase
   fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news
 
   def valid_news
-    { :title => 'Test news', :description => 'Lorem ipsum etc', :author => User.find(:first) }
+    { :title => 'Test news', :description => 'Lorem ipsum etc', :author => User.first }
   end
 
   def setup
index 28a478e60471825f08b1ded1cc387850ac76b0b3..4c144174778d69a4851f48c05034268ce6042e70 100644 (file)
@@ -707,7 +707,7 @@ class ProjectTest < ActiveSupport::TestCase
 
   def test_activities_should_not_include_the_inactive_project_specific_activities
     project = Project.find(1)
-    overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false})
+    overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.first, :active => false})
     assert overridden_activity.save!
 
     assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found"
@@ -722,7 +722,7 @@ class ProjectTest < ActiveSupport::TestCase
   end
 
   def test_activities_should_handle_nils
-    overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.find(:first)})
+    overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.first})
     TimeEntryActivity.delete_all
 
     # No activities
@@ -737,7 +737,7 @@ class ProjectTest < ActiveSupport::TestCase
 
   def test_activities_should_override_system_activities_with_project_activities
     project = Project.find(1)
-    parent_activity = TimeEntryActivity.find(:first)
+    parent_activity = TimeEntryActivity.first
     overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity})
     assert overridden_activity.save!
 
@@ -747,7 +747,7 @@ class ProjectTest < ActiveSupport::TestCase
 
   def test_activities_should_include_inactive_activities_if_specified
     project = Project.find(1)
-    overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false})
+    overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.first, :active => false})
     assert overridden_activity.save!
 
     assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found"
index 05f59d8a61f9f209fc61e15bafbd9a96f353a37c..ff34d017eafb34a0ebc50b2f93e00b22df439008 100644 (file)
@@ -121,7 +121,7 @@ class RepositoryCvsTest < ActiveSupport::TestCase
       assert_equal 3, @repository.changesets.count
       assert_equal %w|3 2 1|, @repository.changesets.all.collect(&:revision)
 
-      rev3_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
+      rev3_commit = @repository.changesets.reorder('committed_on DESC').first
       assert_equal '3', rev3_commit.revision
        # 2007-12-14 01:27:22 +0900
       rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
index 56663c165ec729aa7fb40e2c25a1f7d619a1870e..d6e00d2b5b2dd8f2d59c4493adba57189cf49953 100644 (file)
@@ -209,7 +209,7 @@ class RepositoryTest < ActiveSupport::TestCase
     assert_equal [101], fixed_issue.changeset_ids
 
     # issue change
-    journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
+    journal = fixed_issue.journals.reorder('created_on desc').first
     assert_equal User.find_by_login('dlopper'), journal.user
     assert_equal 'Applied in changeset r2.', journal.notes
 
index 807ff32b772588fd36b6167996210441f0afc2ba..ad4c0e0ca831ca29c555dad87832855dad650fdc 100644 (file)
@@ -61,7 +61,7 @@ class VersionTest < ActiveSupport::TestCase
 
   def test_progress_should_be_100_with_closed_assigned_issues
     project = Project.find(1)
-    status = IssueStatus.find(:first, :conditions => {:is_closed => true})
+    status = IssueStatus.where(:is_closed => true).first
     v = Version.create!(:project => project, :name => 'Progress')
     add_issue(v, :status => status)
     add_issue(v, :status => status, :done_ratio => 20)
@@ -86,7 +86,7 @@ class VersionTest < ActiveSupport::TestCase
     v = Version.create!(:project => project, :name => 'Progress')
     add_issue(v)
     add_issue(v, :done_ratio => 20)
-    add_issue(v, :status => IssueStatus.find(:first, :conditions => {:is_closed => true}))
+    add_issue(v, :status => IssueStatus.where(:is_closed => true).first)
     assert_progress_equal (0.0 + 20.0 + 100.0)/3, v.completed_pourcent
     assert_progress_equal (100.0)/3, v.closed_pourcent
   end
@@ -97,7 +97,7 @@ class VersionTest < ActiveSupport::TestCase
     add_issue(v, :estimated_hours => 10)
     add_issue(v, :estimated_hours => 20, :done_ratio => 30)
     add_issue(v, :estimated_hours => 40, :done_ratio => 10)
-    add_issue(v, :estimated_hours => 25, :status => IssueStatus.find(:first, :conditions => {:is_closed => true}))
+    add_issue(v, :estimated_hours => 25, :status => IssueStatus.where(:is_closed => true).first)
     assert_progress_equal (10.0*0 + 20.0*0.3 + 40*0.1 + 25.0*1)/95.0*100, v.completed_pourcent
     assert_progress_equal 25.0/95.0*100, v.closed_pourcent
   end
@@ -106,7 +106,7 @@ class VersionTest < ActiveSupport::TestCase
     project = Project.find(1)
     v = Version.create!(:project => project, :name => 'Progress')
     add_issue(v, :done_ratio => 20)
-    add_issue(v, :status => IssueStatus.find(:first, :conditions => {:is_closed => true}))
+    add_issue(v, :status => IssueStatus.where(:is_closed => true).first)
     add_issue(v, :estimated_hours => 10, :done_ratio => 30)
     add_issue(v, :estimated_hours => 40, :done_ratio => 10)
     assert_progress_equal (25.0*0.2 + 25.0*1 + 10.0*0.3 + 40.0*0.1)/100.0*100, v.completed_pourcent
@@ -242,8 +242,8 @@ class VersionTest < ActiveSupport::TestCase
     Issue.create!({:project => version.project,
                    :fixed_version => version,
                    :subject => 'Test',
-                   :author => User.find(:first),
-                   :tracker => version.project.trackers.find(:first)}.merge(attributes))
+                   :author => User.first,
+                   :tracker => version.project.trackers.first}.merge(attributes))
   end
 
   def assert_progress_equal(expected_float, actual_float, message="")
index 5e09ac70102f8d69b88d25a1628f8f82b31bbff6..3e256e35db77c947c02bcc18e5806a0c0cd3444c 100644 (file)
@@ -69,6 +69,6 @@ class WikiRedirectTest < ActiveSupport::TestCase
     assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
 
     @original.destroy
-    assert !@wiki.redirects.find(:first)
+    assert_nil @wiki.redirects.first
   end
 end