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
|