rails/activemodel/CHANGELOG.md
Josh Brody 54b1574421 Raise FrozenError for frozen objects when trying to write to a
non-database-backed attribute.

Writing to database-backed attributes after freezing an object would
raise FrozenError, but wouldn't raise FrozenError for user-defined
attributes.

Fixes #37208
2019-09-16 16:59:43 -05:00

763 B

  • Raise FrozenError when trying to write attributes that aren't backed by the database on an object that is frozen:

    class Animal
      include ActiveModel::Attributes  
      attribute :age 
    end
    
    animal = Animal.new
    animal.freeze 
    animal.age = 25 # => FrozenError, "can't modify a frozen Animal"
    
  • Add *_previously_was attribute methods when dirty tracking. Example:

    pirate.update(catchphrase: "Ahoy!")
    pirate.previous_changes["catchphrase"] # => ["Thar She Blows!", "Ahoy!"]
    pirate.catchphrase_previously_was # => "Thar She Blows!"
    

    DHH

Please check 6-0-stable for previous changes.