diff options
author | Go MAEDA <maeda@farend.jp> | 2020-05-03 00:44:08 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2020-05-03 00:44:08 +0000 |
commit | e9e0c538da70361ebfbe4f1a21f1818724512943 (patch) | |
tree | f69b678914977addf58537689a61c0e3e37c0164 /test/unit | |
parent | 16789259ccde7a9a42d82e2b803f0d8d097f2777 (diff) | |
download | redmine-e9e0c538da70361ebfbe4f1a21f1818724512943.tar.gz redmine-e9e0c538da70361ebfbe4f1a21f1818724512943.zip |
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
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/default_data_test.rb | 18 | ||||
-rw-r--r-- | test/unit/document_category_test.rb | 4 | ||||
-rw-r--r-- | test/unit/enumeration_test.rb | 2 | ||||
-rw-r--r-- | test/unit/issue_status_test.rb | 4 | ||||
-rw-r--r-- | test/unit/issue_test.rb | 4 | ||||
-rw-r--r-- | test/unit/project_test.rb | 6 | ||||
-rw-r--r-- | test/unit/wiki_redirect_test.rb | 2 |
7 files changed, 20 insertions, 20 deletions
diff --git a/test/unit/default_data_test.rb b/test/unit/default_data_test.rb index ddb92d31c..865a994dc 100644 --- a/test/unit/default_data_test.rb +++ b/test/unit/default_data_test.rb @@ -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 diff --git a/test/unit/document_category_test.rb b/test/unit/document_category_test.rb index ca4d77491..8be12dbe9 100644 --- a/test/unit/document_category_test.rb +++ b/test/unit/document_category_test.rb @@ -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 diff --git a/test/unit/enumeration_test.rb b/test/unit/enumeration_test.rb index 5c897f311..247a3c4c5 100644 --- a/test/unit/enumeration_test.rb +++ b/test/unit/enumeration_test.rb @@ -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 diff --git a/test/unit/issue_status_test.rb b/test/unit/issue_status_test.rb index e4000c14a..7a043aa62 100644 --- a/test/unit/issue_status_test.rb +++ b/test/unit/issue_status_test.rb @@ -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 diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index aea76e34f..d82f6e079 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -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 diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 5fc3743d5..5198d040a 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -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 diff --git a/test/unit/wiki_redirect_test.rb b/test/unit/wiki_redirect_test.rb index cbdca9309..2f78e8c20 100644 --- a/test/unit/wiki_redirect_test.rb +++ b/test/unit/wiki_redirect_test.rb @@ -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 |