From f2a5c1a541342a886ed3de3b9a15ce06b6bdcde5 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Mon, 31 Dec 2018 12:16:21 -0500 Subject: Fix adding a rich_text_area to a form with no model --- .gitignore | 1 + Gemfile.lock | 2 + actiontext.gemspec | 1 + app/helpers/action_text/tag_helper.rb | 2 +- test/template/form_helper_test.rb | 78 ++++++++++++++++++++++------------- 5 files changed, 55 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index d1654bd7a4..8fda56f74b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .bundle/ +.byebug_history log/*.log node_modules/ pkg/ diff --git a/Gemfile.lock b/Gemfile.lock index 32f07b0461..1c5bd96494 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -73,6 +73,7 @@ GEM remote: https://rubygems.org/ specs: builder (3.2.3) + byebug (10.0.2) concurrent-ruby (1.0.5) crass (1.0.4) erubi (1.7.1) @@ -133,6 +134,7 @@ PLATFORMS DEPENDENCIES actiontext! bundler (~> 1.15) + byebug mini_magick rails! sqlite3 diff --git a/actiontext.gemspec b/actiontext.gemspec index 786953878e..c825a71c6b 100644 --- a/actiontext.gemspec +++ b/actiontext.gemspec @@ -22,6 +22,7 @@ Gem::Specification.new do |s| s.add_development_dependency "mini_magick" s.add_development_dependency "sqlite3" s.add_development_dependency "webpacker", "~> 3.2.2" + s.add_development_dependency "byebug" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- test/*`.split("\n") diff --git a/app/helpers/action_text/tag_helper.rb b/app/helpers/action_text/tag_helper.rb index c7ba416880..0be2d2af36 100644 --- a/app/helpers/action_text/tag_helper.rb +++ b/app/helpers/action_text/tag_helper.rb @@ -40,7 +40,7 @@ module ActionView::Helpers def render options = @options.stringify_keys add_default_name_and_id(options) - options["input"] ||= dom_id(object, [options["id"], :trix_input].compact.join("_")) + options["input"] ||= dom_id(object, [options["id"], :trix_input].compact.join("_")) if object @template_object.rich_text_area_tag(options.delete("name"), editable_value, options) end diff --git a/test/template/form_helper_test.rb b/test/template/form_helper_test.rb index 18b5edbee5..cb900ffc36 100644 --- a/test/template/form_helper_test.rb +++ b/test/template/form_helper_test.rb @@ -5,45 +5,67 @@ require 'test_helper' class ActionText::FormHelperTest < ActionView::TestCase tests ActionText::TagHelper - def form_with(*) - @output_buffer = super + test "form with rich text area" do + form_with model: Message.new, scope: :message do |form| + form.rich_text_area :content + end + + assert_dom_equal \ + '
' \ + '' \ + '' \ + '' \ + '' \ + '
', + output_buffer 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 + test "form with rich text area having class" do + form_with model: Message.new, scope: :message do |form| + form.rich_text_area :content, class: "custom-class" end - assert_match "message[not_an_attribute]", output_buffer + assert_dom_equal \ + '
' \ + '' \ + '' \ + '' \ + '' \ + '
', + output_buffer end - test "form with rich_text_area" do - expected = '
'\ - ''\ - ''\ - ''\ - '
' - - form_with(model: Message.new, scope: :message, id: "create-message") do |form| - form.rich_text_area(:content) + test "form with rich text area for non-attribute" do + form_with model: Message.new, scope: :message do |form| + form.rich_text_area :not_an_attribute end - assert_dom_equal expected, output_buffer + assert_dom_equal \ + '
' \ + '' \ + '' \ + '' \ + '' \ + '
', + output_buffer end - test "form with rich_text_area providing class option" do - expected = '
'\ - ''\ - ''\ - ''\ - '
' - - form_with(model: Message.new, scope: :message, id: "create-message") do |form| - form.rich_text_area(:content, class: "custom-class") + test "modelless form with rich text area" do + form_with url: "/messages", scope: :message do |form| + form.rich_text_area :content end - assert_dom_equal expected, output_buffer + assert_dom_equal \ + '
' \ + '' \ + '' \ + '' \ + '' \ + '
', + output_buffer + end + + def form_with(*) + @output_buffer = super end end -- cgit v1.2.3