Since the documentation clearly states that the parameter must be a hash, I
don't think a check should be done on the type of the parameter.

Thousands of methods in rails expect hashes without raising an exception if
the parameter is not a hash.

I even think that throwing a NoMethodError when nil is passed might be a
good thing.

--
Adrien Siami
On Mar 22, 2013 12:33 AM, "John J. Wang" <notifications@github.com> wrote:

> In activerecord/lib/active_record/attribute_assignment.rb:
>
> > @@ -12,7 +12,11 @@ module AttributeAssignment
> >      # of this method is +false+ an <tt>ActiveModel::ForbiddenAttributesError</tt>
> >      # exception is raised.
> >      def assign_attributes(new_attributes)
> > -      return if new_attributes.blank?
> > +      if !new_attributes
> > +        raise ArgumentError, "Must pass a non-nil hash as an argument when assigning attributes."
> > +      elsif new_attributes.empty?
>
> That's true. I think this test is outdated. It was originally added here:
> 786342e<https://github.com/rails/rails/commit/786342e17f42799ef889cf6127fe97e9598272e0>.
> Which brings me to a second discussion, should we be raising an
> ArgumentError when the input is not a hash?
>
> It seems like this second check will ensure that all arguments are correct
> and valid, and that stringify_keys will never throw a NoMethodError if we
> are sure that a new_attributes is a hash.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/rails/rails/pull/9860/files#r3482868>
> .
>