adding basic ability module
This commit is contained in:
40
spec/cancan/ability_spec.rb
Normal file
40
spec/cancan/ability_spec.rb
Normal 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
11
spec/spec_helper.rb
Normal 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
|
||||
Reference in New Issue
Block a user