File: destroy_association_async_job_test.rb

package info (click to toggle)
rails 2%3A7.2.2.1%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 43,352 kB
  • sloc: ruby: 349,799; javascript: 30,703; yacc: 46; sql: 43; sh: 29; makefile: 27
file content (62 lines) | stat: -rw-r--r-- 2,313 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true

require "cases/helper"

class UndefinedConstantAsync < ActiveRecord::Base
  self.destroy_association_async_job = "UndefinedConstantJob"
end

autoload :UnloadableBaseJob, "activejob/unloadable_base_job"
class UnloadableBaseAsync < ActiveRecord::Base
  self.destroy_association_async_job = "UnloadableBaseJob"
end

class UnusedBelongsToAsync < ActiveRecord::Base
  self.destroy_association_async_job = nil
end

class UnusedHasOneAsync < ActiveRecord::Base
  self.destroy_association_async_job = nil
end

class UnusedHasManyAsync < ActiveRecord::Base
  self.destroy_association_async_job = nil
end


class DestroyAssociationAsyncJobTest < ActiveRecord::TestCase
  test "destroy_association_async_job requires valid job class" do
    error = assert_raises NameError do
      UndefinedConstantAsync.belongs_to :essay_destroy_async, dependent: :destroy_async
    end
    assert_match %r/destroy_association_async_job: uninitialized constant UndefinedConstantJob/, error.message
  end

  test "destroy_association_async_job error shows a missing parent job class, as if ActiveJob were missing" do
    error = assert_raises NameError do
      UnloadableBaseAsync.belongs_to :essay_destroy_async, dependent: :destroy_async
    end
    assert_match %r/destroy_association_async_job: uninitialized constant PretendActiveJobIsNotPresent/, error.message
  end

  test "belongs_to dependent destroy_async requires destroy_association_async_job" do
    error = assert_raises ActiveRecord::ConfigurationError do
      UnusedBelongsToAsync.belongs_to :essay_destroy_async, dependent: :destroy_async
    end
    assert_match %r/destroy_association_async_job/, error.message
  end

  test "has_one dependent destroy_async requires destroy_association_async_job" do
    error = assert_raises ActiveRecord::ConfigurationError do
      UnusedHasOneAsync.has_one :essay_destroy_async, dependent: :destroy_async
    end
    assert_match %r/destroy_association_async_job/, error.message
  end

  test "has_many dependent destroy_async requires destroy_association_async_job" do
    error = assert_raises ActiveRecord::ConfigurationError do
      UnusedHasManyAsync.has_many :essay_destroy_asyncs, dependent: :destroy_async
    end
    assert_match %r/destroy_association_async_job/, error.message
  end
end