aq1018/mongoid-history — pull request #70 by johnnyshields (2013-06-01 21:40:02+00:00)
Title: Trackable#tracked_fields + fixes for Tracker#tracked_changes + Tracker#trackable_parent_class

@dblock apologies for bombarding you with pull requests. I'm integrating this gem into my app and gradually finding a more loose-ends.

This commit includes:

1. `Trackable`: Add class-level #tracked_field? and #tracked_fields methods and refactor logic to determine whether a field is tracked. There's two caveats here:

* I understand Mongoid has a "freeform mode" where you can willy-nilly define any value on an object. This commit will prevent such values from being tracked, though I don't see any tests currently for that case.

* Previously delete was tracking all fields, regardless of whether the user specified they should be tracked (I suspect maybe users want "Undo" on a delete to restore all fields?) I've changed this so that delete undo only restores the tracked fields.

2. Added some fixes and additional tests for previously added #tracked_changes and #tracked_edits, as there's a pre-existing hack described in Issue #69 which requires us to flip-flop the :from and :to values for the specifically for :destroy action

3. Refactor and test #trackable_parent_class method, which returns the parent class of the trackable regardless of whether the trackable itself has been destroyed.