Permalink
Browse files

moving class dependency inline in specs

  • Loading branch information...
1 parent 0b8b51b commit d5f6e0570cda28f5048096b27ca26082fa4e70ec @ryanb committed Nov 16, 2009
Showing with 25 additions and 32 deletions.
  1. +25 −32 spec/cancan/ability_spec.rb
@@ -1,37 +1,14 @@
require File.dirname(__FILE__) + '/../spec_helper'
-class Ability
- include CanCan::Ability
- alias_action :update, :destroy, :to => :modify
-
- can :read, :all
- can :read, Symbol do |sym|
- sym
- end
- can :preview, :all do |object_class, object|
- [object_class, object]
- end
- can :manage, Array do |action, object|
- [action, object]
- end
- can :modify, :all do |object_class, object|
- :modify_called
- end
-end
-
-class AdminAbility
- include CanCan::Ability
- can :manage, :all do |action, object_class, object|
- [action, object_class, object]
- end
-end
-
-describe Ability do
+describe CanCan::Ability do
before(:each) do
- @ability = Ability.new
+ @ability_class = Class.new
+ @ability_class.send(:include, CanCan::Ability)
+ @ability = @ability_class.new
end
it "should be able to :read anything" do
+ @ability_class.can :read, :all
@ability.can?(:read, String).should be_true
@ability.can?(:read, 123).should be_true
end
@@ -41,32 +18,48 @@ class AdminAbility
end
it "should return what block returns on a can call" do
+ @ability_class.can :read, Symbol do |sym|
+ sym
+ end
@ability.can?(:read, Symbol).should be_nil
@ability.can?(:read, :some_symbol).should == :some_symbol
end
it "should pass class with object if :all objects are accepted" do
+ @ability_class.can :preview, :all do |object_class, object|
+ [object_class, object]
+ end
@ability.can?(:preview, 123).should == [Fixnum, 123]
end
it "should pass class with no object if :all objects are accepted and class is passed directly" do
+ @ability_class.can :preview, :all do |object_class, object|
+ [object_class, object]
+ end
@ability.can?(:preview, Hash).should == [Hash, nil]
end
it "should pass action and object for global manage actions" do
+ @ability_class.can :manage, Array do |action, object|
+ [action, object]
+ end
@ability.can?(:stuff, [1, 2]).should == [:stuff, [1, 2]]
@ability.can?(:stuff, Array).should == [:stuff, nil]
end
it "should alias update or destroy actions to modify action" do
+ @ability_class.alias_action :update, :destroy, :to => :modify
+ @ability_class.can :modify, :all do |object_class, object|
+ :modify_called
+ end
@ability.can?(:update, 123).should == :modify_called
@ability.can?(:destroy, 123).should == :modify_called
end
-end
-
-describe AdminAbility do
+
it "should return block result for action, object_class, and object for any action" do
- @ability = AdminAbility.new
+ @ability_class.can :manage, :all do |action, object_class, object|
+ [action, object_class, object]
+ end
@ability.can?(:foo, 123).should == [:foo, Fixnum, 123]
@ability.can?(:bar, Fixnum).should == [:bar, Fixnum, nil]
end

0 comments on commit d5f6e05

Please sign in to comment.