diff options
author | Alberto Almagro Sotelo <albertoalmagro@gmail.com> | 2018-10-09 23:10:07 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2018-10-09 14:10:07 -0700 |
commit | 9febb318043e5320d7338f0267c6aef651cd9315 (patch) | |
tree | 883f0f625d689e56e6c78bb46d127bc1e59f452d | |
parent | dc63aa42b075969359699c4076ad233d66d49eec (diff) | |
download | rails-9febb318043e5320d7338f0267c6aef651cd9315.tar.gz rails-9febb318043e5320d7338f0267c6aef651cd9315.tar.bz2 rails-9febb318043e5320d7338f0267c6aef651cd9315.zip |
Prevent rich_text_area from raising when inexistent attribute is passed (#24)
When an inexistent attribute is passed as a parameter to currently
existing Rails' Form Helpers they render an empty tag instead of
raising an exception. This commit confers the same behavior to
`rich_text_area`.
Fixes #19
-rw-r--r-- | app/helpers/action_text/tag_helper.rb | 2 | ||||
-rw-r--r-- | test/template/form_helper_test.rb | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/app/helpers/action_text/tag_helper.rb b/app/helpers/action_text/tag_helper.rb index 103b65eb97..c7ba416880 100644 --- a/app/helpers/action_text/tag_helper.rb +++ b/app/helpers/action_text/tag_helper.rb @@ -45,7 +45,7 @@ module ActionView::Helpers end def editable_value - value.body.try(:to_trix_html) + value&.body.try(:to_trix_html) end end diff --git a/test/template/form_helper_test.rb b/test/template/form_helper_test.rb new file mode 100644 index 0000000000..d7bdbad26c --- /dev/null +++ b/test/template/form_helper_test.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'test_helper' + +class ActionText::FormHelperTest < ActionView::TestCase + tests ActionText::TagHelper + + def form_with(*) + @output_buffer = super + end + + test "rich_text_area doesn't raise when attributes don't exist in the model" do + assert_nothing_raised do + form_with(model: Message.new, scope: :message, id: "create-message") do |form| + form.rich_text_area(:not_an_attribute) + end + end + + assert_match "message[not_an_attribute]", output_buffer + end +end |