forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Text database models
- Loading branch information
Showing
6 changed files
with
43 additions
and
7 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
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
class EncryptedMessage < ApplicationRecord | ||
self.table_name = "messages" | ||
|
||
class EncryptedMessage < Message | ||
has_rich_text :content, encrypted: true | ||
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
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class ActionText::TableNameTest < 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" | ||
|
||
@models = [ActionText::RichText, ActionText::EncryptedRichText] | ||
@models.map(&:reset_table_name) | ||
end | ||
|
||
teardown do | ||
ActiveRecord::Base.table_name_prefix = @old_prefix | ||
ActiveRecord::Base.table_name_suffix = @old_suffix | ||
|
||
@models.map(&:reset_table_name) | ||
end | ||
|
||
test "prefix and suffix are added to the Action Text tables' name" do | ||
assert_equal( | ||
"#{@prefix}action_text_rich_texts#{@suffix}", | ||
ActionText::RichText.table_name | ||
) | ||
assert_equal( | ||
"#{@prefix}action_text_rich_texts#{@suffix}", | ||
ActionText::EncryptedRichText.table_name | ||
) | ||
end | ||
end |