turning load and authorize resource methods into class methods which set up the before filter so they can accept additional arguments
This commit is contained in:
@@ -27,19 +27,21 @@ describe CanCan::ControllerAdditions do
|
||||
@controller.cannot?(:foo, :bar).should be_true
|
||||
end
|
||||
|
||||
it "should load resource" do
|
||||
mock.instance_of(CanCan::ResourceAuthorization).load_resource
|
||||
@controller.load_resource
|
||||
it "load_and_authorize_resource should setup a before filter which passes call to ResourceAuthorization" do
|
||||
stub(CanCan::ResourceAuthorization).new(@controller, @controller.params, :foo => :bar).mock!.load_and_authorize_resource
|
||||
mock(@controller_class).before_filter { |block| block.call(@controller) }
|
||||
@controller_class.load_and_authorize_resource :foo => :bar
|
||||
end
|
||||
|
||||
it "should authorize resource" do
|
||||
mock.instance_of(CanCan::ResourceAuthorization).authorize_resource
|
||||
@controller.authorize_resource
|
||||
it "authorize_resource should setup a before filter which passes call to ResourceAuthorization" do
|
||||
stub(CanCan::ResourceAuthorization).new(@controller, @controller.params, :foo => :bar).mock!.authorize_resource
|
||||
mock(@controller_class).before_filter { |block| block.call(@controller) }
|
||||
@controller_class.authorize_resource :foo => :bar
|
||||
end
|
||||
|
||||
it "should load and authorize resource in one call through controller" do
|
||||
mock(@controller).load_resource
|
||||
mock(@controller).authorize_resource
|
||||
@controller.load_and_authorize_resource
|
||||
it "load_resource should setup a before filter which passes call to ResourceAuthorization" do
|
||||
stub(CanCan::ResourceAuthorization).new(@controller, @controller.params, :foo => :bar).mock!.load_resource
|
||||
mock(@controller_class).before_filter { |block| block.call(@controller) }
|
||||
@controller_class.load_resource :foo => :bar
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,4 +56,11 @@ describe CanCan::ResourceAuthorization do
|
||||
authorization.authorize_resource
|
||||
}.should raise_error(CanCan::AccessDenied)
|
||||
end
|
||||
|
||||
it "should call load_resource and authorize_resource for load_and_authorize_resource" do
|
||||
authorization = CanCan::ResourceAuthorization.new(@controller, :controller => "abilities", :action => "show")
|
||||
mock(authorization).load_resource
|
||||
mock(authorization).authorize_resource
|
||||
authorization.load_and_authorize_resource
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user