未验证 提交 1add7387 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #37951 from t0yohei/add-missing-action-to-action-text

Action Text: Add method to confirm rich text content existence by adding ? after content name
* Add method to confirm rich text content existence by adding `?` after content name.
*Kyohei Toyoda*
* The `fill_in_rich_text_area` system test helper locates a Trix editor and fills it in with the given HTML: * The `fill_in_rich_text_area` system test helper locates a Trix editor and fills it in with the given HTML:
```ruby ```ruby
......
...@@ -13,6 +13,7 @@ module Attribute ...@@ -13,6 +13,7 @@ module Attribute
# end # end
# #
# message = Message.create!(content: "<h1>Funny times!</h1>") # message = Message.create!(content: "<h1>Funny times!</h1>")
# message.content? #=> true
# message.content.to_s # => "<h1>Funny times!</h1>" # message.content.to_s # => "<h1>Funny times!</h1>"
# message.content.to_plain_text # => "Funny times!" # message.content.to_plain_text # => "Funny times!"
# #
...@@ -29,6 +30,10 @@ def #{name} ...@@ -29,6 +30,10 @@ def #{name}
rich_text_#{name} || build_rich_text_#{name} rich_text_#{name} || build_rich_text_#{name}
end end
def #{name}?
rich_text_#{name}.present?
end
def #{name}=(body) def #{name}=(body)
self.#{name}.body = body self.#{name}.body = body
end end
......
...@@ -18,6 +18,7 @@ class ActionText::ModelTest < ActiveSupport::TestCase ...@@ -18,6 +18,7 @@ class ActionText::ModelTest < ActiveSupport::TestCase
assert message.content.nil? assert message.content.nil?
assert message.content.blank? assert message.content.blank?
assert message.content.empty? assert message.content.empty?
assert_not message.content?
assert_not message.content.present? assert_not message.content.present?
end end
...@@ -26,6 +27,7 @@ class ActionText::ModelTest < ActiveSupport::TestCase ...@@ -26,6 +27,7 @@ class ActionText::ModelTest < ActiveSupport::TestCase
assert_not message.content.nil? assert_not message.content.nil?
assert message.content.blank? assert message.content.blank?
assert message.content.empty? assert message.content.empty?
assert_not message.content?
assert_not message.content.present? assert_not message.content.present?
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册