rails/activemodel/lib
Seb Jacobs 4733e04dfa Reintroduce support for overriding has_secure_password attributes
In Rails 5.2.x calling `has_secure_password` would define attribute
readers and writers on the superclass of the model, which meant that you
could override these attributes in a model and call the superclass for
example:

```
class Dog < ApplicationRecord
  has_secure_password

  def password=(new_password)
    @password_set = new_password.present?
    super
  end
end
```

However this behaviour was broken in Rails 6 when the ability to
customise the name of the attribute was introduced [1] since they are no
longer being defined on the superclass you will now see the following
error:

```
NoMethodError:
super: no superclass method `password=' for #<Dog:0x00007ffbbc7ce290>
Did you mean?  password
```

In order to resolve this issue and retain support for setting a custom
attribute name we can define these attribute readers/writers in a module
and then ensure that the module is included in the inheritance chain.

[1] https://www.github.com/rails/rails/commit/86a48b4da3
    https://www.github.com/rails/rails/commit/9b63bf1dfd
2019-03-22 08:28:13 +00:00
..
active_model Reintroduce support for overriding has_secure_password attributes 2019-03-22 08:28:13 +00:00
active_model.rb Bump license years for 2019 2018-12-31 10:24:38 +07:00