adding 'cannot?' method which performs opposite check of 'can?' - closes #1

This commit is contained in:
Ryan Bates
2009-11-17 10:46:16 -08:00
parent df276536ab
commit 0f49b5478f
6 changed files with 27 additions and 8 deletions

View File

@@ -81,4 +81,8 @@ describe CanCan::Ability do
it "should not respond to prepare (now using initialize)" do
@ability.should_not respond_to(:prepare)
end
it "should offer cannot? method which is simply invert of can?" do
@ability.cannot?(:tie, String).should be_true
end
end

View File

@@ -11,7 +11,7 @@ describe CanCan::ControllerAdditions do
before(:each) do
@controller_class = Class.new
@controller = @controller_class.new
mock(@controller_class).helper_method(:can?)
mock(@controller_class).helper_method(:can?, :cannot?)
@controller_class.send(:include, CanCan::ControllerAdditions)
end
@@ -26,10 +26,11 @@ describe CanCan::ControllerAdditions do
@controller.current_ability.should be_kind_of(Ability)
end
it "should provide a can? method which goes through the current ability" do
it "should provide a can? and cannot? methods which go through the current ability" do
stub(@controller).current_user { :current_user }
@controller.current_ability.should be_kind_of(Ability)
@controller.can?(:foo, :bar).should be_false
@controller.cannot?(:foo, :bar).should be_true
end
it "should load the resource if params[:id] is specified" do