Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

@_cancan_skipper should be inherited #683

Closed
wants to merge 1 commit into from

3 participants

@jpmckinney

If a superclass controller has:

load_and_authorize_resource
skip_load_resource :only => :index

A subclass will not skip the loading of the resource on the index action.

I've added a failing test to illustrate this behavior.

Potential fix would be to use class_attribute from Rails: http://apidock.com/rails/Class/class_attribute

@jaredbeck

Can you try the most recent version of cancan (currently 1.6.10) to see if your issue has been resolved?

This is one of the oldest CanCan issues with no discussion. CanCan is struggling right now to implement support for rails 4, and the issue count is nearing 200. It would be a big help if we could close a few old issues and get the issue count down. Thanks!

@jpmckinney

And this is my third-oldest open pull request among my 165 total!

Kind of crazy that the tests only pass on 1.8.7 and that Travis only tests 1.8.7, too. You know it's been retired?

Anyway, this issue is not resolved. I ran the spec that this pull request adds in master, and it still fails, so the bug still exists.

@xhoy

Thanks for your submission! The ryanb/cancan repository has been inactive since Sep 06, 2013.
Since only Ryan himself has commit permissions, the CanCan project is on a standstill.

CanCan has many open issues, including missing support for Rails 4. To keep CanCan alive, an active fork exists at cancancommunity/cancancan. The new gem is cancancan. More info is available at #994.

If your pull request or issue is still applicable, it would be really appreciated if you resubmit it to CanCanCan.

We hope to see you on the other side!

@jpmckinney jpmckinney referenced this pull request in CanCanCommunity/cancancan
Open

@_cancan_skipper should be inherited: add failing test #88

@jpmckinney jpmckinney closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 0 deletions.
  1. +21 −0 spec/cancan/controller_additions_spec.rb
View
21 spec/cancan/controller_additions_spec.rb
@@ -134,4 +134,25 @@
@controller_class.cancan_skipper[:load][:project].should == {:only => [:index, :show]}
@controller_class.cancan_skipper[:authorize][:project].should == {:only => [:index, :show]}
end
+
+ describe "when inheriting" do
+ before(:each) do
+ @super_controller_class = Class.new
+ @super_controller = @super_controller_class.new
+ mock(@super_controller_class).helper_method(:can?, :cannot?, :current_ability)
+ @super_controller_class.send(:include, CanCan::ControllerAdditions)
+ @super_controller_class.send(:skip_load_and_authorize_resource, :only => [:index, :show])
+
+ @sub_controller_class = Class.new(@super_controller_class)
+ @sub_controller = @sub_controller_class.new
+ end
+
+ it "sub_classes should skip the same behaviors and actions as super_classes" do
+ @super_controller_class.cancan_skipper[:load][nil].should == {:only => [:index, :show]}
+ @super_controller_class.cancan_skipper[:authorize][nil].should == {:only => [:index, :show]}
+
+ @sub_controller_class.cancan_skipper[:load][nil].should == {:only => [:index, :show]}
+ @sub_controller_class.cancan_skipper[:authorize][nil].should == {:only => [:index, :show]}
+ end
+ end
end
Something went wrong with that request. Please try again.