markbates/mongoid_delorean — pull request #3 by GUI (2013-11-08 04:09:39+00:00)
Title: Fix save(validate: false) not properly skipping validations

`save(validate: false)` on a record wasn't properly working, since there was a plain `save!` always being called inside the `before_save` callback for every record. That callback had the effect of forcing validations on each record's save, since any options you passed into your own save call weren't be honored inside the callback's save call.

This approach fixes the issue by not forcing a save during the `before_save` callback phase. That way the options passed into your own save call still take precedent. An explicit save during the callback phase is still necessary on parent records when saving an embedded record, but that save is now being done without validations turned on (since that save is effectively only updating the `version` attribute on the parent record).

I added tests around the different scenarios I had encountered, and this behavior now seems to match Mongoid's default save and validate behavior, but let me know if you had any different thoughts on how to tackle this.