Fixes an exception when a has_one association is recursively restored. #118

Closed
wants to merge 1 commit into from

3 participants

@stupergenius

The original implementation would raise a method_missing exception when a has_one association was recursively restored. The pull request first checks to see if the association is a collection before looping through the deleted items.

@radar

Hi @stupergenius, could you please write a regression test for this?

@pobocks

Am I correct in thinking that the case of a nullable single collection should also be handled? i.e., if association_data is nil, currently restore fails.

My additional fix, off the top of my head, probably wrong:

...
association_data = send(association.name)
unless association_data.nil?
  if association_data.paranoid?
    if association.collection?
      association_data.only_deleted.each { |record| record.restore(:recursive => true) }
...
@pobocks

The nil check seems to fix the remaining issue. I've made a new pull request with the combined fix.

#119

@pobocks pobocks added a commit to pobocks/paranoia that referenced this pull request Mar 7, 2014
@pobocks pobocks Regression tests and full fix for #118
  * Based on partial fix by @stupergenius
  * Handles nil case for hasOne associations
acbc916
@pobocks pobocks added a commit to harvard-library/inscriptio that referenced this pull request Mar 7, 2014
@pobocks pobocks Temporarily using custom paranoia because of issue rubysherpas/parano… 847c33f
@radar radar added a commit that referenced this pull request Mar 11, 2014
@pobocks pobocks Regression tests and full fix for #118
  * Based on partial fix by @stupergenius
  * Handles nil case for hasOne associations

Fixes #119
f2c95e9
@radar radar closed this Mar 11, 2014
@radar

Fixed by #119.

@pobocks pobocks added a commit to harvard-library/inscriptio that referenced this pull request Mar 13, 2014
@pobocks pobocks Temporarily using custom paranoia because of issue rubysherpas/parano… 127e888
@pobocks pobocks added a commit to harvard-library/inscriptio that referenced this pull request Apr 7, 2014
@pobocks pobocks Temporarily using custom paranoia because of issue rubysherpas/parano… 1fb822b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment