Created
February 9, 2012 20:25
-
-
Save justincampbell/1782830 to your computer and use it in GitHub Desktop.
CanCan Ability Spec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Ability do | |
let(:admin_user) { mock AdminUser } | |
it { Ability.should include(CanCan::Ability) } | |
it { Ability.should respond_to(:new).with(1).argument } | |
context "admin" do | |
before :each do | |
admin_user.stub!(:role).and_return("admin") | |
end | |
it "can manage all" do | |
Ability.any_instance.should_receive(:can).with(:manage, :all) | |
Ability.new admin_user | |
end | |
end | |
context "editor" do | |
before :each do | |
admin_user.stub!(:role).and_return("editor") | |
end | |
it "can not manage all" do | |
Ability.any_instance.should_not_receive(:can).with(:manage, :all) | |
Ability.new admin_user | |
end | |
it "can create and edit models" do | |
[Thing, Widget].each do |model| | |
Ability.any_instance.should_receive(:can).with([:read, :update], model) | |
end | |
Ability.new admin_user | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!