-
Notifications
You must be signed in to change notification settings - Fork 21.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Take AR affixes into account for Action Mailbox database models
- Loading branch information
Showing
5 changed files
with
46 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
* Fix all Action Mailbox database related models to respect | ||
`ActiveRecord::Base.table_name_prefix` configuration. | ||
|
||
*Chedli Bourguiba* | ||
|
||
Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/actionmailbox/CHANGELOG.md) for previous changes. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class ActionMailbox::RecordTest < ActiveSupport::TestCase | ||
setup do | ||
@old_prefix = ActiveRecord::Base.table_name_prefix | ||
@old_suffix = ActiveRecord::Base.table_name_suffix | ||
|
||
ActiveRecord::Base.table_name_prefix = @prefix = "abc_" | ||
ActiveRecord::Base.table_name_suffix = @suffix = "_xyz" | ||
|
||
@descendants = ActionMailbox::Record.descendants | ||
@descendants.map(&:reset_table_name) | ||
end | ||
|
||
test "prefix and suffix are added to the Action Mailbox tables' name" do | ||
ActionMailbox::Record.descendants.each do |model| | ||
assert_equal( | ||
"#{@prefix}action_mailbox_#{table_name_without_affixes(model)}#{@suffix}", | ||
model.table_name | ||
) | ||
end | ||
ensure | ||
ActiveRecord::Base.table_name_prefix = @old_prefix | ||
ActiveRecord::Base.table_name_suffix = @old_suffix | ||
@descendants.map(&:reset_table_name) | ||
end | ||
|
||
private | ||
def table_name_without_affixes(model) | ||
model.table_name | ||
.dup | ||
.tap { _1.delete_prefix!(model.table_name_prefix) } | ||
.tap { _1.delete_prefix!("action_mailbox_") } | ||
.tap { _1.delete_suffix!(model.table_name_suffix) } | ||
end | ||
end |