Replaces find(:first) calls.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10928 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-12-03 18:21:32 +00:00
parent 013c6fe009
commit 31c33f462d
31 changed files with 101 additions and 96 deletions

View 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

View 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

View 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}

View 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

View 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

View 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 =~ /^([^<]+)(<(.*)>)?$/

View 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

View 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

View 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?

View 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

View 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

View 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)

View 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

View 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

View 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

View 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
})

View 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

View 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

View 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?

View 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

View 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

View 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

View 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

View 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

View 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|

View 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

View 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"

View 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)

View 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

View 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="")

View 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