adding basic ability module

This commit is contained in:
Ryan Bates
2009-11-16 14:28:52 -08:00
commit 0cfb8c7c41
7 changed files with 184 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
require File.dirname(__FILE__) + '/../spec_helper'
class Ability
include CanCan::Ability
can :read, :all
can :read, Symbol do |sym|
sym
end
can :preview, :all do |object_class, object|
[object_class, object]
end
end
describe CanCan::Ability do
before(:each) do
@ability = Ability.new
end
it "should be able to :read anything" do
@ability.can?(:read, String).should be_true
@ability.can?(:read, 123).should be_true
end
it "should not have permission to do something it doesn't know about" do
@ability.can?(:foodfight, String).should be_false
end
it "should return what block returns on a can call" do
@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.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.can?(:preview, Hash).should == [Hash, nil]
end
end

11
spec/spec_helper.rb Normal file
View File

@@ -0,0 +1,11 @@
require 'rubygems'
require 'spec'
require 'active_support'
require 'active_record'
require 'action_controller'
require 'action_view'
require File.dirname(__FILE__) + '/../lib/cancan.rb'
Spec::Runner.configure do |config|
config.mock_with :rr
end