Skip to content

Instantly share code, notes, and snippets.

@stefanoverna
Created March 7, 2012 15:34
Show Gist options
  • Select an option

  • Save stefanoverna/1993827 to your computer and use it in GitHub Desktop.

Select an option

Save stefanoverna/1993827 to your computer and use it in GitHub Desktop.
require 'spec_helper'
require "cancan/matchers"
describe Ability do
let(:article) { Factory.build(:article) }
let(:reserved_article) { Factory.build(:article, :reserved => true) }
context "on backend" do
subject { Ability.new(user, :admin) }
context "when enabled admin is logged" do
let(:user) { Factory.build(:admin) }
it { should be_able_to :manage, Article }
it { should be_able_to :manage, Category }
it { should be_able_to :manage, ArticleLayout }
it { should be_able_to :manage, Comment }
it { should be_able_to :manage, Page }
it { should be_able_to :manage, Setting }
it { should be_able_to :manage, User }
end
context "when an enabled article writer is logged" do
let(:user) { Factory.build(:article_writer) }
it { should be_able_to :manage, Article }
it { should be_able_to :manage, Category }
it { should be_able_to :manage, ArticleLayout }
it { should be_able_to :manage, Comment }
it { should_not be_able_to :read, Page }
it { should_not be_able_to :read, User }
it { should_not be_able_to :read, Setting }
end
context "when an enabled premium user is logged" do
let(:user) { Factory.build(:premium_user) }
it { should_not be_able_to :read, Article }
it { should_not be_able_to :read, Category }
it { should_not be_able_to :read, ArticleLayout }
it { should_not be_able_to :read, Comment }
it { should_not be_able_to :read, Page }
it { should_not be_able_to :read, Setting }
it { should_not be_able_to :read, User }
end
context "when an enabled premium user is logged" do
let(:user) { Factory.build(:user) }
it { should_not be_able_to :read, Article }
it { should_not be_able_to :read, Category }
it { should_not be_able_to :read, ArticleLayout }
it { should_not be_able_to :read, Comment }
it { should_not be_able_to :read, Page }
it { should_not be_able_to :read, Setting }
it { should_not be_able_to :read, User }
end
context "when disabled user is logged" do
let(:user) { Factory.build(:user, :enabled => false) }
it { should_not be_able_to :read, Article }
it { should_not be_able_to :read, Category }
it { should_not be_able_to :read, ArticleLayout }
it { should_not be_able_to :read, Comment }
it { should_not be_able_to :read, Page }
it { should_not be_able_to :read, Setting }
it { should_not be_able_to :read, User }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment