-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Defer constant loading of ActiveRecord::DestroyAssociationAsyncJob
via a String instead of a class constant
#45476
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
activerecord/test/activejob/destroy_association_async_job_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# 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 "deprecation of rescuing ActiveJobRequiredError which has been replaced by a NameError" do | ||
assert_deprecated { ActiveRecord::ActiveJobRequiredError } | ||
end | ||
|
||
test "belong_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 |
31 changes: 0 additions & 31 deletions
31
activerecord/test/activejob/destroy_async_job_not_present_test.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
class UnloadableBaseJob < PretendActiveJobIsNotPresent; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2666,12 +2666,12 @@ class ::DummySerializer < ActiveJob::Serializers::ObjectSerializer; end | |
assert_equal ActiveRecord::DestroyAssociationAsyncJob, ActiveRecord::Base.destroy_association_async_job | ||
end | ||
|
||
test "ActiveRecord::Base.destroy_association_async_job can be configured via config.active_record.destroy_association_job" do | ||
test "ActiveRecord::Base.destroy_association_async_job can be configured via config.active_record.destroy_association_async_job" do | ||
class ::DummyDestroyAssociationAsyncJob; end | ||
|
||
app_file "config/environments/test.rb", <<-RUBY | ||
Rails.application.configure do | ||
config.active_record.destroy_association_async_job = DummyDestroyAssociationAsyncJob | ||
config.active_record.destroy_association_async_job = "DummyDestroyAssociationAsyncJob" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! 👍 |
||
end | ||
RUBY | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to remove this exception we need to deprecate first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a deprecation:
https://github.com/rails/rails/pull/45476/files#diff-805517f2e613a421493817fa15ecd42e583caf1b4f6f6972ec6e8103f41e04a2R12
...and a test:
https://github.com/rails/rails/pull/45476/files#diff-0045b3212d324439c6e30bef62094dcf2654863b9ccd93ef2367cec9f135e044R42-R49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a deprecation:
https://github.com/rails/rails/pull/45476/files#diff-805517f2e613a421493817fa15ecd42e583caf1b4f6f6972ec6e8103f41e04a2R12
...and a test:
https://github.com/rails/rails/pull/45476/files#diff-0045b3212d324439c6e30bef62094dcf2654863b9ccd93ef2367cec9f135e044R42-R49