Skip to content

Commit

Permalink
Deprecate passing nil as model arg instead of raising ArgumentError (r…
Browse files Browse the repository at this point in the history
  • Loading branch information
cjilbert504 authored and Ridhwana committed Mar 5, 2024
1 parent 35e8650 commit 730d33d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion actionview/CHANGELOG.md
Expand Up @@ -17,7 +17,7 @@

*Sean Doyle*

* Raise `ArgumentError` when `nil` is passed as `model:` argument value to the `form_with` method.
* Deprecate passing `nil` as value for the `model:` argument to the `form_with` method.

*Collin Jilbert*

Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/helpers/form_helper.rb
Expand Up @@ -754,7 +754,7 @@ def apply_form_for_options!(object, options) # :nodoc:
# form_with(**options.merge(builder: LabellingFormBuilder), &block)
# end
def form_with(model: false, scope: nil, url: nil, format: nil, **options, &block)
raise ArgumentError, "The :model argument cannot be nil" if model.nil?
ActionView.deprecator.warn("Passing nil to the :model argument is deprecated and will raise in Rails 7.3") if model.nil?

options = { allow_method_names_outside_object: true, skip_default_ids: !form_with_generates_ids }.merge!(options)

Expand Down
3 changes: 1 addition & 2 deletions actionview/test/template/form_helper/form_with_test.rb
Expand Up @@ -340,11 +340,10 @@ def url_for(object)
end

def test_form_with_when_given_nil_model_argument
error = assert_raises(ArgumentError) do
assert_deprecated(ActionView.deprecator) do
form_with(model: nil) do
end
end
assert_equal "The :model argument cannot be nil", error.message
end

def test_form_with
Expand Down

0 comments on commit 730d33d

Please sign in to comment.