title: Factory Girl before safe callback
body: <p>I have a very specific use-case. I need to each time before saving a factory instance "deleted_user" to assign it <code>ID</code> that is free in the "users" table in order the "restore" to work.</p>
  
  <pre><code>class DeletedUser &lt; ActiveRecord::Base
    def restore
     User.create!(attributes) # ID here is included and is important to be. We want a user with the same ID that it was before deleting!
    end
  end
  
  FactoryGirl.register :deleted_user do
    # need to plug before save and assign ID that never will be used for user ID.
  end
  </code></pre>
  
  <p>And There are different ways to persist a factory instance:</p>
  
  <ol>
  <li><code>FactoryGirl.create :deleted_user</code></li>
  <li><code>FactoryGirl.create_list(:deleted_user)</code></li>
  <li><code>FactoryGirl.build(:deleted_user).save</code></li>
  <li><code>FactoryGirl.build(:deleted_user).save!</code></li>
  <li><code>FactoryGirl.build_list(:deleted_user, 2).map(&amp;:save)</code></li>
  <li><code>FactoryGirl.build_list(:deleted_user, 2).map(&amp;:save!)</code></li>
  </ol>
  
  <p>As I see Factory Girl doesn't have a before save callback but only <code>before(:create)</code> and <code>on_creation</code>, but they are triggered only for <code>1, 2</code> of the above invocations.</p>
  
  <p>Do you know a way to use custom <code>before(:save)</code> callback elegantly?</p>
  
  <p>NOTE: My FactoryGirl is <code>4.5.0</code></p>