diff options
author | Lachlan Sylvester <lachlan.sylvester@blake.com.au> | 2018-12-21 12:04:30 +1100 |
---|---|---|
committer | Lachlan Sylvester <lachlan.sylvester@blake.com.au> | 2018-12-21 12:04:30 +1100 |
commit | ecfada837a464df1ffa50789d4e555ffde6108f4 (patch) | |
tree | c0073013b39c77d2b1edd4d70ec0a81472ad4d9b | |
parent | 18974137be2c4027dfcf430668edd712e7ec011b (diff) | |
download | rails-ecfada837a464df1ffa50789d4e555ffde6108f4.tar.gz rails-ecfada837a464df1ffa50789d4e555ffde6108f4.tar.bz2 rails-ecfada837a464df1ffa50789d4e555ffde6108f4.zip |
use plain test to determine present/blank/empty as the html version will always contain content
-rw-r--r-- | app/models/action_text/rich_text.rb | 8 | ||||
-rw-r--r-- | test/unit/model_test.rb | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/app/models/action_text/rich_text.rb b/app/models/action_text/rich_text.rb index 1f8ac0e7f7..d44046e863 100644 --- a/app/models/action_text/rich_text.rb +++ b/app/models/action_text/rich_text.rb @@ -8,8 +8,12 @@ class ActionText::RichText < ActiveRecord::Base self.table_name = "action_text_rich_texts" serialize :body, ActionText::Content - delegate :to_s, :to_plain_text, :nil?, to: :body - delegate :blank?, :empty?, :present?, to: :to_s + delegate :to_s, :nil?, to: :body + delegate :blank?, :empty?, :present?, to: :to_plain_text + + def to_plain_text + body&.to_plain_text.to_s + end belongs_to :record, polymorphic: true, touch: true has_many_attached :embeds diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index 99a249946a..43da9c7a73 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -21,6 +21,14 @@ class ActionText::ModelTest < ActiveSupport::TestCase assert_not message.content.present? end + test "with blank content" do + message = Message.create!(subject: "Greetings", content: "") + assert_not message.content.nil? + assert message.content.blank? + assert message.content.empty? + assert_not message.content.present? + end + test "embed extraction" do blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpg") message = Message.create!(subject: "Greetings", content: ActionText::Content.new("Hello world").append_attachables(blob)) |