use-exists-instead-of-first.patch

Go MAEDA, 2020-04-29 11:03

Download (6.67 KB)

View differences:

test/functional/workflows_controller_test.rb
145 145
    assert_response 302
146 146

  
147 147
    assert_equal 3, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count
148
    assert_not_nil  WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first
149
    assert_nil      WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4).first
148
    assert          WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).exists?
149
    assert_not      WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4).exists?
150 150
  end
151 151

  
152 152
  def test_post_edit_with_allowed_statuses_for_new_issues
test/unit/default_data_test.rb
36 36
  def test_load
37 37
    clear_data
38 38
    assert Redmine::DefaultData::Loader::load('en')
39
    assert_not_nil DocumentCategory.first
40
    assert_not_nil IssuePriority.first
41
    assert_not_nil TimeEntryActivity.first
42
    assert_not_nil WorkflowTransition.first
43
    assert_not_nil Query.first
39
    assert DocumentCategory.exists?
40
    assert IssuePriority.exists?
41
    assert TimeEntryActivity.exists?
42
    assert WorkflowTransition.exists?
43
    assert Query.exists?
44 44
  end
45 45

  
46 46
  def test_load_for_all_language
......
48 48
      clear_data
49 49
      begin
50 50
        assert Redmine::DefaultData::Loader::load(lang, :workflow => false)
51
        assert_not_nil DocumentCategory.first
52
        assert_not_nil IssuePriority.first
53
        assert_not_nil TimeEntryActivity.first
54
        assert_not_nil Query.first
51
        assert DocumentCategory.exists?
52
        assert IssuePriority.exists?
53
        assert TimeEntryActivity.exists?
54
        assert Query.exists?
55 55
      rescue ActiveRecord::RecordInvalid => e
56 56
        assert false, ":#{lang} default data is invalid (#{e.message})."
57 57
      end
test/unit/document_category_test.rb
40 40
  end
41 41

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

  
49 49
  def test_force_default
50
    assert_nil DocumentCategory.where(:is_default => true).first
50
    assert_not DocumentCategory.where(:is_default => true).exists?
51 51
    assert_equal 1, DocumentCategory.default.id
52 52
  end
53 53
end
test/unit/enumeration_test.rb
92 92

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

  
test/unit/issue_status_test.rb
49 49
    assert_difference 'IssueStatus.count', -1 do
50 50
      assert status.destroy
51 51
    end
52
    assert_nil WorkflowTransition.where(:old_status_id => status.id).first
53
    assert_nil WorkflowTransition.where(:new_status_id => status.id).first
52
    assert_not WorkflowTransition.where(:old_status_id => status.id).exists?
53
    assert_not WorkflowTransition.where(:new_status_id => status.id).exists?
54 54
  end
55 55

  
56 56
  def test_destroy_status_in_use
test/unit/issue_test.rb
248 248
  def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_default
249 249
    Role.anonymous.update!(:issues_visibility => 'default')
250 250
    issue = Issue.generate!(:author => User.anonymous, :is_private => true)
251
    assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first
251
    assert_not Issue.where(:id => issue.id).visible(User.anonymous).exists?
252 252
    assert !issue.visible?(User.anonymous)
253 253
  end
254 254

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

  
test/unit/project_test.rb
237 237
    # make sure that the project non longer exists
238 238
    assert_raise(ActiveRecord::RecordNotFound) {Project.find(@ecookbook.id)}
239 239
    # make sure related data was removed
240
    assert_nil Member.where(:project_id => @ecookbook.id).first
241
    assert_nil Board.where(:project_id => @ecookbook.id).first
242
    assert_nil Issue.where(:project_id => @ecookbook.id).first
240
    assert_not Member.where(:project_id => @ecookbook.id).exists?
241
    assert_not Board.where(:project_id => @ecookbook.id).exists?
242
    assert_not Issue.where(:project_id => @ecookbook.id).exists?
243 243
  end
244 244

  
245 245
  def test_destroy_should_destroy_subtasks
test/unit/wiki_redirect_test.rb
95 95
    assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
96 96

  
97 97
    @original.destroy
98
    assert_nil @wiki.redirects.first
98
    assert_not @wiki.redirects.exists?
99 99
  end
100 100
end