adding support for loading through Inherited Resources - closes #23
This commit is contained in:
@@ -74,4 +74,13 @@ describe CanCan::ControllerAdditions do
|
||||
@controller_class.check_authorization(:some_options)
|
||||
}.should_not raise_error(CanCan::AuthorizationNotPerformed)
|
||||
end
|
||||
|
||||
it "cancan_resource_class should be ControllerResource by default" do
|
||||
@controller.class.cancan_resource_class.should == CanCan::ControllerResource
|
||||
end
|
||||
|
||||
it "cancan_resource_class should be InheritedResource when class includes InheritedResources::Actions" do
|
||||
stub(@controller.class).ancestors { ["InheritedResources::Actions"] }
|
||||
@controller.class.cancan_resource_class.should == CanCan::InheritedResource
|
||||
end
|
||||
end
|
||||
|
||||
40
spec/cancan/inherited_resource_spec.rb
Normal file
40
spec/cancan/inherited_resource_spec.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe CanCan::InheritedResource do
|
||||
before(:each) do
|
||||
@params = HashWithIndifferentAccess.new(:controller => "projects")
|
||||
@controller = Object.new # simple stub for now
|
||||
@ability = Ability.new(nil)
|
||||
stub(@controller).params { @params }
|
||||
stub(@controller).current_ability { @ability }
|
||||
end
|
||||
|
||||
it "show should load resource through @controller.resource" do
|
||||
@params[:action] = "show"
|
||||
stub(@controller).resource { :project_resource }
|
||||
CanCan::InheritedResource.new(@controller).load_resource
|
||||
@controller.instance_variable_get(:@project).should == :project_resource
|
||||
end
|
||||
|
||||
it "new should load through @controller.build_resource" do
|
||||
@params[:action] = "new"
|
||||
stub(@controller).build_resource { :project_resource }
|
||||
CanCan::InheritedResource.new(@controller).load_resource
|
||||
@controller.instance_variable_get(:@project).should == :project_resource
|
||||
end
|
||||
|
||||
it "index should load through @controller.parent when parent" do
|
||||
@params[:action] = "index"
|
||||
stub(@controller).parent { :project_resource }
|
||||
CanCan::InheritedResource.new(@controller, :parent => true).load_resource
|
||||
@controller.instance_variable_get(:@project).should == :project_resource
|
||||
end
|
||||
|
||||
it "index should load through @controller.end_of_association_chain" do
|
||||
@params[:action] = "index"
|
||||
stub(Project).accessible_by(@ability) { :projects }
|
||||
stub(@controller).end_of_association_chain { Project }
|
||||
CanCan::InheritedResource.new(@controller).load_resource
|
||||
@controller.instance_variable_get(:@projects).should == :projects
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user