Browse Source

Use more efficient "exists?" instead of "first" in tests when checking the existence of rows (#33367).

Patch by Go MAEDA.


git-svn-id: http://svn.redmine.org/redmine/trunk@19746 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/4.2.0
Go MAEDA 4 years ago
parent
commit
e9e0c538da

+ 2
- 2
test/functional/workflows_controller_test.rb View File

@@ -145,8 +145,8 @@ class WorkflowsControllerTest < Redmine::ControllerTest
assert_response 302

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
assert WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).exists?
assert_not WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4).exists?
end

def test_post_edit_with_allowed_statuses_for_new_issues

+ 9
- 9
test/unit/default_data_test.rb View File

@@ -36,11 +36,11 @@ class DefaultDataTest < ActiveSupport::TestCase
def test_load
clear_data
assert Redmine::DefaultData::Loader::load('en')
assert_not_nil DocumentCategory.first
assert_not_nil IssuePriority.first
assert_not_nil TimeEntryActivity.first
assert_not_nil WorkflowTransition.first
assert_not_nil Query.first
assert DocumentCategory.exists?
assert IssuePriority.exists?
assert TimeEntryActivity.exists?
assert WorkflowTransition.exists?
assert Query.exists?
end

def test_load_for_all_language
@@ -48,10 +48,10 @@ class DefaultDataTest < ActiveSupport::TestCase
clear_data
begin
assert Redmine::DefaultData::Loader::load(lang, :workflow => false)
assert_not_nil DocumentCategory.first
assert_not_nil IssuePriority.first
assert_not_nil TimeEntryActivity.first
assert_not_nil Query.first
assert DocumentCategory.exists?
assert IssuePriority.exists?
assert TimeEntryActivity.exists?
assert Query.exists?
rescue ActiveRecord::RecordInvalid => e
assert false, ":#{lang} default data is invalid (#{e.message})."
end

+ 2
- 2
test/unit/document_category_test.rb View File

@@ -40,14 +40,14 @@ class DocumentCategoryTest < ActiveSupport::TestCase
end

def test_default
assert_nil DocumentCategory.where(:is_default => true).first
assert_not DocumentCategory.where(:is_default => true).exists?
e = Enumeration.find_by_name('Technical documentation')
e.update(:is_default => true)
assert_equal 3, DocumentCategory.default.id
end

def test_force_default
assert_nil DocumentCategory.where(:is_default => true).first
assert_not DocumentCategory.where(:is_default => true).exists?
assert_equal 1, DocumentCategory.default.id
end
end

+ 1
- 1
test/unit/enumeration_test.rb View File

@@ -92,7 +92,7 @@ class EnumerationTest < ActiveSupport::TestCase

def test_destroy_with_reassign
Enumeration.find(4).destroy(Enumeration.find(6))
assert_nil Issue.where(:priority_id => 4).first
assert_not Issue.where(:priority_id => 4).exists?
assert_equal 6, Enumeration.find(6).objects_count
end


+ 2
- 2
test/unit/issue_status_test.rb View File

@@ -49,8 +49,8 @@ class IssueStatusTest < ActiveSupport::TestCase
assert_difference 'IssueStatus.count', -1 do
assert status.destroy
end
assert_nil WorkflowTransition.where(:old_status_id => status.id).first
assert_nil WorkflowTransition.where(:new_status_id => status.id).first
assert_not WorkflowTransition.where(:old_status_id => status.id).exists?
assert_not WorkflowTransition.where(:new_status_id => status.id).exists?
end

def test_destroy_status_in_use

+ 2
- 2
test/unit/issue_test.rb View File

@@ -248,14 +248,14 @@ class IssueTest < ActiveSupport::TestCase
def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_default
Role.anonymous.update!(:issues_visibility => 'default')
issue = Issue.generate!(:author => User.anonymous, :is_private => true)
assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first
assert_not Issue.where(:id => issue.id).visible(User.anonymous).exists?
assert !issue.visible?(User.anonymous)
end

def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_own
assert Role.anonymous.update!(:issues_visibility => 'own')
issue = Issue.generate!(:author => User.anonymous, :is_private => true)
assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first
assert_not Issue.where(:id => issue.id).visible(User.anonymous).exists?
assert !issue.visible?(User.anonymous)
end


+ 3
- 3
test/unit/project_test.rb View File

@@ -237,9 +237,9 @@ class ProjectTest < ActiveSupport::TestCase
# make sure that the project non longer exists
assert_raise(ActiveRecord::RecordNotFound) {Project.find(@ecookbook.id)}
# make sure related data was removed
assert_nil Member.where(:project_id => @ecookbook.id).first
assert_nil Board.where(:project_id => @ecookbook.id).first
assert_nil Issue.where(:project_id => @ecookbook.id).first
assert_not Member.where(:project_id => @ecookbook.id).exists?
assert_not Board.where(:project_id => @ecookbook.id).exists?
assert_not Issue.where(:project_id => @ecookbook.id).exists?
end

def test_destroy_should_destroy_subtasks

+ 1
- 1
test/unit/wiki_redirect_test.rb View File

@@ -95,6 +95,6 @@ class WikiRedirectTest < ActiveSupport::TestCase
assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')

@original.destroy
assert_nil @wiki.redirects.first
assert_not @wiki.redirects.exists?
end
end

Loading…
Cancel
Save