CanCanCommunity/cancancan — pull request #39 by tdg5 (2014-04-02 13:28:28+00:00)
Title: Fixes #26 - If available, add references for ActiveRecord join tables

This fixes https://github.com/CanCanCommunity/cancancan/issues/26

This handles the deprecation warnings issued by Rails 4 when a join is implicit by adding references to the join tables if the references method is available. If references is not available, the previous behavior is maintained, thereby continuing to support Rails 3.

I used :references instead of :joins, as suggested by #26, because the behavior of :references is more inline with the behavior of :includes.

I don't get the impression that my solution is the preferred way of handling this, but perhaps it is useful until appraisals against Rails 4 are ready to go.

With this change the ActiveRecord Rails 3 tests still pass for me and a Rails 4 app I have that uses cancancan no longer issues the implicit join warnings.

I'm very open to writing a test for this if you can point me to where it'd be best for me to do that.