namick/obfuscate_id

Problem reloading objects

dgilperez opened this issue · 7 comments

Hi!

We're trying to use your library within our app. I followed your instructions and added obfuscate_id to my model. Controller / Views seem to work properly but not our test suite. The issue comes while using reloadmethod on any loaded object, giving a lot of errors like ActiveRecord::RecordNotFound: Couldn't find User with id=1084515574

On my console:

u= Model.last

u.id
=> 891

u.reload
=> ActiveRecord::RecordNotFound: Couldn't find Model with id=5084735574

Any ideas?

Hi there, sorry I didn't notice others using this gem until recently.

The ActiveRecord 'reload' method passes in 'id' rather than 'to_param' to its 'find' method. I'll try to get a fix out for this when I get some time.

As a work around in your tests just reload manually:

u = User.last

u.id
=> 891

# Reload from database
u = User.find(u.to_param)
=> #<User id: 891>

This issue still exists, and it affects use of carrierwave with a model object that uses obfuscate_id. I'm trying to find time to fix it...

Sorry about that, pushed from a wrong version of the gem. The second one might be a useful way to fix the reload issue.

Nice, I'll check it out. Wanna make a pull request? I could update the gem

Oh, oops. I thought for some reason you had pull requests disabled, but my brain just stopped working for a sec.

Thanks so much Colin for taking the time to figure out how to fix this issue. Your changes are merged and I'll push out a new gem soon.

Thanks both of you guys!