moiristo/deep_cloneable — pull request #27 by mikecmpbll (2013-07-10 13:27:29+00:00)
Title: Added HABTM duplication as an option.

Deep_cloneable doesn't dup HABTM associated objects, only the associations themselves.

This patch introduces an option `:dup_habtm`, which if set to true simply calls `dup` on all the associated objects, too. It doesn't do the reverse association that it normally does because that will generate two join records in the join table when you save the dupped object.

# without :dup_habtm (same as before)
s = Student.first.dup include: :klasses
s.klasses.any?(&:new_record?)
=> false

# with :dup_habtm
s = Student.first.dup include: :klasses, dup_habtm: true
s.klasses.all?(&:new_record?)
=> true

Added a test for this option. All tests pass in my Ruby 2.0.0 environment.

I needed this so thought it might be useful for others, too.