From ce46a7851c36998974c9f1c9ae28fe46f5408d27 Mon Sep 17 00:00:00 2001 From: Corey Martin Date: Tue, 2 Aug 2016 14:33:18 -0400 Subject: [PATCH] support value in form helper --- lib/trix/form.rb | 2 +- spec/trix_editor_helper_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/trix/form.rb b/lib/trix/form.rb index 77829be9..5d6605d0 100644 --- a/lib/trix/form.rb +++ b/lib/trix/form.rb @@ -36,7 +36,7 @@ def render options = @options.stringify_keys add_default_name_and_id(options) options['input'] ||= dom_id(object, [options['id'], :trix_input].compact.join('_')) - trix_editor_tag(options.delete('name'), value_before_type_cast(object), options) + trix_editor_tag(options.delete('name'), (options['value'] || value_before_type_cast(object)), options) end end end diff --git a/spec/trix_editor_helper_spec.rb b/spec/trix_editor_helper_spec.rb index a0ef4814..1884e53d 100644 --- a/spec/trix_editor_helper_spec.rb +++ b/spec/trix_editor_helper_spec.rb @@ -9,6 +9,20 @@ assign(:blog, blog) expect(helper.trix_editor(:blog, :text)).to include('trix-editor') end + + it 'uses value from object' do + blog = mock_model('Blog', text: 'my_original_value') + + assign(:blog, blog) + expect(helper.trix_editor(:blog, :text)).to include('my_original_value') + end + + it 'uses a provided value instead of value from object' do + blog = mock_model('Blog', text: 'my_original_value') + + assign(:blog, blog) + expect(helper.trix_editor(:blog, :text, value: "my_provided_value")).to include('my_provided_value') + end end describe '#trix_editor_tag' do