Skip to content

Commit

Permalink
Experimental support for CanCan
Browse files Browse the repository at this point in the history
  • Loading branch information
gregbell committed May 31, 2011
1 parent 09c5eaa commit 32d522b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/active_admin.rb
Expand Up @@ -3,6 +3,7 @@
require 'will_paginate'
require 'sass'
require 'active_admin/arbre'
require 'active_admin/cancan'

module ActiveAdmin

Expand Down
22 changes: 22 additions & 0 deletions lib/active_admin/cancan.rb
@@ -0,0 +1,22 @@
# Support for CanCan within Active Admin

module ActiveAdmin
module CanCan
if defined?(::CanCan)

class ControllerResource < ::CanCan::InheritedResource
def resource_base
@controller.send :collection
end
end

module ControllerAdditions
def cancan_resource_class
::ActiveAdmin::CanCan::ControllerResource
end
end

ActiveAdmin::ResourceController.send :include, ControllerAdditions
end
end
end
2 changes: 1 addition & 1 deletion lib/active_admin/resource_controller/collection.rb
Expand Up @@ -126,7 +126,7 @@ def setup_pagination_for_csv
end

def paginate(chain)
chain.paginate(:page => params[:page], :per_page => @per_page || ActiveAdmin.default_per_page)
@paginated_collection = chain.paginate(:page => params[:page], :per_page => @per_page || ActiveAdmin.default_per_page)
end
end

Expand Down
22 changes: 22 additions & 0 deletions spec/unit/cancan_spec.rb
@@ -0,0 +1,22 @@
# Mock out CanCan
module CanCan
class InheritedResource
def initialize(controller)
@controller = controller
end
end
end

require 'spec_helper'

describe ActiveAdmin::CanCan do

describe ActiveAdmin::CanCan::ControllerResource do
it "should return the collection for cancan to use" do
controller = mock("MockController")
controller.should_receive(:collection)
ActiveAdmin::CanCan::ControllerResource.new(controller).resource_base
end
end

end

0 comments on commit 32d522b

Please sign in to comment.