airblade/paper_trail — Issue #105: Test bleeding due to info_for_paper_trail
Author: ordinaryzelig
Created: 2011-11-08 16:38:46+00:00
State: open

I recently had a nasty bug that I couldn't figure out. When using RSpec, all my model specs passed UNLESS I ran controller specs BEFORE them. It drove me crazy until I figured ou the problem. The results of ApplicationController#info_for_paper_trail are cached in PaperTrail.controller_info and persists until it is set to something else. So in a controller test, info_for_paper_trail may be set to something, then a model spec that gets run after that inherits the same data from PaperTrail.controller_info. I worked around it by declaring a before(:each) block that resets it:
```ruby
RSpec.configure do |config|
config.before :each do
PaperTrail.controller_info = {}
end
end
```
Now each and every test starts with a fresh, pristine PaperTrail environment.

Maybe there is a better solution for this? Or may I suggest at least noting this in the README?