Adding callbacks for draft creation, update, and destroy #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey @chrisdpeters -- I had a few situations where I needed ActiveRecord-style callbacks to run on draft content, e.g.
before_draft_creation
rather than ActiveRecord'sbefore_create
.This pull request includes support for nine callbacks:
(before | around | after)_draft_creation
(before | around | after)_draft_update
(before | around | after)_draft_destroy
I've included multiple tests for each of these callbacks -- 25 in total.
For the most part, I haven't changed how draftsman works (and the current specs all pass). The
draft_creation
,draft_update
, anddraft_destroy
methods are basically just wrapped by the callbacks. There is one change to model.rb#L225 -- I've moved the 'return' outside of the callbacks to make sure they always have a chance to run (unless there is an exception).Thought you (or others) might find this useful. Let me know if you have questions, or if you'd like me to modify how I'm doing anything.
Thanks!