Skip to content

Commit

Permalink
add missing convert_to_model method, and do not create @response object
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieujobin committed Oct 31, 2023
1 parent 5e9f2e4 commit 1047db1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/action_view/helpers/dynamic_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def form(record_name, options = {})
contents.safe_concat('</form>')
end

def convert_to_model(object)
object.respond_to?(:to_model) ? object.to_model : object
end

# Returns a string containing the error message attached to the +method+ on the +object+ if one exists.
# This error message is wrapped in a <tt>DIV</tt> tag by default or with <tt>:html_tag</tt> if specified,
# which can be extended to include a <tt>:prepend_text</tt> and/or <tt>:append_text</tt> (to properly explain
Expand Down
4 changes: 1 addition & 3 deletions test/dynamic_form_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def setup
super
setup_post
setup_user

@response = ActionController::TestResponse.new
end

def url_for(options)
Expand Down Expand Up @@ -370,7 +368,7 @@ def test_default_form_builder_no_instance_variable

assert_dom_equal expected, output_buffer
end

def test_error_messages_without_prefixed_attribute_name
error = error_messages_for(@post)
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>),
Expand Down

0 comments on commit 1047db1

Please sign in to comment.