copasetickid / draftsman

Ruby gem that lets you create draft versions of your database records.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception on draft_destroy when has_one association is nil

npafundi opened this issue · comments

If a model's has_one association is nil, draft_destroy will throw an exception.

For example, if I have a Parent which has_one :child, but the child doesn't exist yet (so the association is nil), a draft_destroy will throw a NoMethodError.

NoMethodError - undefined method `draft?' for nil:NilClass:
  <path>/draftsman/lib/draftsman/model.rb:282:in `block (4 levels) in draft_destroy'
  <path>/draftsman/lib/draftsman/model.rb:279:in `block (3 levels) in draft_destroy'
  <path>/draftsman/lib/draftsman/model.rb:270:in `block (2 levels) in draft_destroy'

This will occur in traditional and polymorphic has_one associations.

Edit: By simply adding a has_one association to the Parent class in the current dummy specs, you'll find that 29 specs fail.