e7f66fb2 fixed one problem and introduced a new one. Setting timestamps
after clearing_changes_information doesn't work, since using the
created_at and updated_at setters will change the object again. I added
some additional specs for this case (our only spec related to clearing
changes used an object without timestamps).
For the timezone problem, I did a little digging and realized the
casting behavior was actually correct. The reason it was behaving in a
different way than I was expecting is because we had
`time_zone_aware_attributes` set to false, whereas the AR railtie
[sets it to true](54652d886a/activerecord/lib/active_record/railtie.rb (L71)). Setting it to true causes date and datetime attributes
[to get decorated with a TimeZoneConverter](54652d886a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb (L68..L87))
Rather than redefining #created_at and #updated_at, we can use the
existing methods and just set them if there aren't already values
present. We need to do this after clearing changes information,
otherwise the times end up getting converted to the wrong zone.
factory_bot 5 only supports Rails 4.2 and higher,
and #clear_changes_information has been around since then
(66d0a01535).
Fixes#941, since we will are no longer managing any instance variables.
decrement, increment, and toggle do not persist the toggled values, so
there is not reason to disable those methods.
Co-authored-by: Alex Tsui <alextsui05@gmail.com>