-
Notifications
You must be signed in to change notification settings - Fork 884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't use reset_callbacks
in tests
#895
Don't use reset_callbacks
in tests
#895
Conversation
Failures are due to master, not this PR |
#897 merged, please rebase.
We could continue maintaining PT 5 if we had to, so I think it's fine to drop support for rails 3 in PT 6. If Ben agrees, I'd be happy to make that change. I'll just update the gemspec and drop testing support, for starters. We can clean up the conditionals in the code over time. |
In #895, Sean asked: > .. since it looks like the next version is planned to be 6.0.0, how would > you feel about dropping support for Rails 3 in that version? It has > reached end of life, meaning it no longer receives security patches. We > don't recommend that gem authors continue to support it. To which, I responded: > We could continue maintaining PT 5 if we had to, so I think it's > fine to drop support for rails 3 in PT 6. If Ben agrees, I'd be > happy to make that change. I'll just update the gemspec and drop > testing support, for starters. We can clean up the conditionals in > the code over time.
The test suite attempts to modify a model, and then call `reset_callbacks` to clean up after itself. However, `reset_callbacks` removes *all* callbacks from a class, including those that Active Record defines internally. Calling `reset_callbacks` on a class like this basically blows away a lot of our internals. What specifically Active Record uses callbacks for is not public API that can be depended on, but a guarantee that it does make is that user defined callbacks will occur after Active Record defined ones (with some caveats like associations which are just in definition order). Callbacks in Rails 3 were... interesting. I could not for the life of me get it to properly clean up, and the code required to do it well would be horrendous, so I've just left that version alone.
a772437
to
52471bf
Compare
In #895, Sean asked: > .. since it looks like the next version is planned to be 6.0.0, how would > you feel about dropping support for Rails 3 in that version? It has > reached end of life, meaning it no longer receives security patches. We > don't recommend that gem authors continue to support it. To which, I responded: > We could continue maintaining PT 5 if we had to, so I think it's > fine to drop support for rails 3 in PT 6. If Ben agrees, I'd be > happy to make that change. I'll just update the gemspec and drop > testing support, for starters. We can clean up the conditionals in > the code over time.
@jaredbeck CI is green. If this is good to merge I can push up the Rails 5.1 support PR. |
Great. I'll merge this to keep the ball rolling, but if we do decide to drop AR3 support (in #898) then we should come back to this and remove the AR3 branch of your conditional. |
Thanks for this, by the way. I always thought that our use of |
Yeah, the reason I did lexical scope instead of an instance variable was to avoid having to deal with namespace collisions and/or any sort of weirdness with a hash. In theory if you wanted to do something like context "foo" do
reset_callbacks(Foo, :bar)
setup do
Foo.before_bar { baz }
end
context "nested" do
reset_callbacks(Foo, :bar)
setup do
Foo.before_bar { more_baz }
end
end
end you could, which you couldn't do if you assumed a 1-to-1 mapping between callback chain and reset. Of course at that point the tests can just go die in a fire, but yeah it was just simpler. |
In paper-trail-gem#895, Sean asked: > .. since it looks like the next version is planned to be 6.0.0, how would > you feel about dropping support for Rails 3 in that version? It has > reached end of life, meaning it no longer receives security patches. We > don't recommend that gem authors continue to support it. To which, I responded: > We could continue maintaining PT 5 if we had to, so I think it's > fine to drop support for rails 3 in PT 6. If Ben agrees, I'd be > happy to make that change. I'll just update the gemspec and drop > testing support, for starters. We can clean up the conditionals in > the code over time.
The test suite attempts to modify a model, and then call
reset_callbacks
to clean up after itself. However,reset_callbacks
removes all callbacks from a class, including those that Active Record
defines internally. Calling
reset_callbacks
on a class like thisbasically blows away a lot of our internals.
What specifically Active Record uses callbacks for is not public API
that can be depended on, but a guarantee that it does make is that user
defined callbacks will occur after Active Record defined ones (with some
caveats like associations which are just in definition order).
Callbacks in Rails 3 were... interesting. I could not for the life of me
get it to properly clean up, and the code required to do it well would
be horrendous, so I've just left that version alone.
On that same note, since it looks like the next version is planned to be 6.0.0, how would you feel about dropping support for Rails 3 in that version? It has reached end of life, meaning it no longer receives security patches. We don't recommend that gem authors continue to support it. Users stuck on 3.2 for whatever reason can continue to use versions of
paper_trail
that are already released.This would simplify this patch, as well as the 5.1 compatibility code.