Skip to content

Commit

Permalink
Take AR affixes into account for Action Text database models
Browse files Browse the repository at this point in the history
  • Loading branch information
chaadow committed Dec 9, 2023
1 parent 049c951 commit c3b821e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
5 changes: 5 additions & 0 deletions actiontext/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Fix all Action Text database related models to respect
`ActiveRecord::Base.table_name_prefix` configuration.

*Chedli Bourguiba*

* Compile ESM package that can be used directly in the browser as actiontext.esm.js

*Matias Grunberg*
Expand Down
2 changes: 0 additions & 2 deletions actiontext/app/models/action_text/encrypted_rich_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

module ActionText
class EncryptedRichText < RichText
self.table_name = "action_text_rich_texts"

encrypts :body
end
end
Expand Down
2 changes: 0 additions & 2 deletions actiontext/app/models/action_text/rich_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ module ActionText
# message.content.to_s # => "<div>safeunsafe</div>"
# message.content.to_plain_text # => "safeunsafe"
class RichText < Record
self.table_name = "action_text_rich_texts"

##
# :method: to_s
#
Expand Down
4 changes: 1 addition & 3 deletions actiontext/test/dummy/app/models/encrypted_message.rb
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
3 changes: 3 additions & 0 deletions actiontext/test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class Application < Rails::Application
# For compatibility with applications that use this config
config.action_controller.include_all_helpers = false

config.active_record.table_name_prefix = 'prefix_'
config.active_record.table_name_suffix = '_suffix'

# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
Expand Down
34 changes: 34 additions & 0 deletions actiontext/test/models/table_name_test.rb
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

0 comments on commit c3b821e

Please sign in to comment.