提交 07533a3d 编写于 作者: K Kyohei Toyoda

Add method to confirm rich text content existence by adding ? after content name

This change introduces a rich text object to make
it easier to confirm it context is existing or not.

If we have a class like below.

class Information < ApplicationRecord
  has_rich_text :notes
end

Before:
i = Information.new
i.notes? => NoMethodError
i.notes = "Some sample text"
i.notes.present? => true

After:
i = Information.new
i.notes? => false

i.notes = "Some sample text"
i.notes? => true
上级 ff299f17
* 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:
```ruby
......
......@@ -13,6 +13,7 @@ module Attribute
# end
#
# message = Message.create!(content: "<h1>Funny times!</h1>")
# message.content? #=> true
# message.content.to_s # => "<h1>Funny times!</h1>"
# message.content.to_plain_text # => "Funny times!"
#
......@@ -29,6 +30,10 @@ def #{name}
rich_text_#{name} || build_rich_text_#{name}
end
def #{name}?
rich_text_#{name}.present?
end
def #{name}=(body)
self.#{name}.body = body
end
......
......@@ -18,6 +18,7 @@ class ActionText::ModelTest < ActiveSupport::TestCase
assert message.content.nil?
assert message.content.blank?
assert message.content.empty?
assert_not message.content?
assert_not message.content.present?
end
......@@ -26,6 +27,7 @@ class ActionText::ModelTest < ActiveSupport::TestCase
assert_not message.content.nil?
assert message.content.blank?
assert message.content.empty?
assert_not message.content?
assert_not message.content.present?
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册