Merge pull request #564 from AyuntamientoMadrid/ability-split

Splits ability.rb and specs into several smaller files
This commit is contained in:
Raimond Garcia
2015-09-28 17:36:10 +02:00
13 changed files with 459 additions and 384 deletions

View File

@@ -0,0 +1,37 @@
module Abilities
class Administrator
include CanCan::Ability
def initialize(user)
self.merge Abilities::Moderation.new(user)
can :restore, Comment
cannot :restore, Comment, hidden_at: nil
can :restore, Debate
cannot :restore, Debate, hidden_at: nil
can :restore, Proposal
cannot :restore, Proposal, hidden_at: nil
can :restore, User
cannot :restore, User, hidden_at: nil
can :confirm_hide, Comment
cannot :confirm_hide, Comment, hidden_at: nil
can :confirm_hide, Debate
cannot :confirm_hide, Debate, hidden_at: nil
can :confirm_hide, Proposal
cannot :confirm_hide, Proposal, hidden_at: nil
can :confirm_hide, User
cannot :confirm_hide, User, hidden_at: nil
can :comment_as_administrator, [Debate, Comment, Proposal]
can [:search, :create, :index, :destroy], ::Moderator
end
end
end

View File

@@ -0,0 +1,44 @@
module Abilities
class Common
include CanCan::Ability
def initialize(user)
self.merge Abilities::Everyone.new(user)
can [:read, :update], User, id: user.id
can :read, Debate
can :update, Debate do |debate|
debate.editable_by?(user)
end
can :read, Proposal
can :update, Proposal do |proposal|
proposal.editable_by?(user)
end
can :create, Comment
can :create, Debate
can :create, Proposal
can [:flag, :unflag], Comment
cannot [:flag, :unflag], Comment, user_id: user.id
can [:flag, :unflag], Debate
cannot [:flag, :unflag], Debate, author_id: user.id
can [:flag, :unflag], Proposal
cannot [:flag, :unflag], Proposal, author_id: user.id
unless user.organization?
can :vote, Debate
can :vote, Comment
end
if user.level_two_or_three_verified?
can :vote, Proposal
end
end
end
end

View File

@@ -0,0 +1,10 @@
module Abilities
class Everyone
include CanCan::Ability
def initialize(user)
can :read, Debate
can :read, Proposal
end
end
end

View File

@@ -0,0 +1,48 @@
module Abilities
class Moderation
include CanCan::Ability
def initialize(user)
self.merge Abilities::Common.new(user)
can :read, Organization
can(:verify, Organization){ |o| !o.verified? }
can(:reject, Organization){ |o| !o.rejected? }
can :read, Comment
can :hide, Comment, hidden_at: nil
cannot :hide, Comment, user_id: user.id
can :ignore_flag, Comment, ignored_flag_at: nil, hidden_at: nil
cannot :ignore_flag, Comment, user_id: user.id
can :moderate, Comment
cannot :moderate, Comment, user_id: user.id
can :hide, Debate, hidden_at: nil
cannot :hide, Debate, author_id: user.id
can :ignore_flag, Debate, ignored_flag_at: nil, hidden_at: nil
cannot :ignore_flag, Debate, author_id: user.id
can :moderate, Debate
cannot :moderate, Debate, author_id: user.id
can :hide, Proposal, hidden_at: nil
cannot :hide, Proposal, author_id: user.id
can :ignore_flag, Proposal, ignored_flag_at: nil, hidden_at: nil
cannot :ignore_flag, Proposal, author_id: user.id
can :moderate, Proposal
cannot :moderate, Proposal, author_id: user.id
can :hide, User
cannot :hide, User, id: user.id
can :block, User
cannot :block, User, id: user.id
end
end
end

View File

@@ -0,0 +1,11 @@
module Abilities
class Moderator
include CanCan::Ability
def initialize(user)
self.merge Abilities::Moderation.new(user)
can :comment_as_moderator, [Debate, Comment, Proposal]
end
end
end

View File

@@ -2,124 +2,20 @@ class Ability
include CanCan::Ability
def initialize(user)
# If someone can hide something, he can also hide it
# from the moderation screen
alias_action :hide_in_moderation_screen, to: :hide
# Not logged in users
can :read, Debate
can :read, Proposal
if user # logged-in users
can [:read, :update], User, id: user.id
can :read, Debate
can :update, Debate do |debate|
debate.editable_by?(user)
end
can :read, Proposal
can :update, Proposal do |proposal|
proposal.editable_by?(user)
end
can :create, Comment
can :create, Debate
can :create, Proposal
can [:flag, :unflag], Comment
cannot [:flag, :unflag], Comment, user_id: user.id
can [:flag, :unflag], Debate
cannot [:flag, :unflag], Debate, author_id: user.id
can [:flag, :unflag], Proposal
cannot [:flag, :unflag], Proposal, author_id: user.id
unless user.organization?
can :vote, Debate
can :vote, Comment
end
if user.level_two_or_three_verified?
can :vote, Proposal
end
if user.moderator? || user.administrator?
can :read, Organization
can(:verify, Organization){ |o| !o.verified? }
can(:reject, Organization){ |o| !o.rejected? }
can :read, Comment
can :hide, Comment, hidden_at: nil
cannot :hide, Comment, user_id: user.id
can :ignore_flag, Comment, ignored_flag_at: nil, hidden_at: nil
cannot :ignore_flag, Comment, user_id: user.id
can :moderate, Comment
cannot :moderate, Comment, user_id: user.id
can :hide, Debate, hidden_at: nil
cannot :hide, Debate, author_id: user.id
can :ignore_flag, Debate, ignored_flag_at: nil, hidden_at: nil
cannot :ignore_flag, Debate, author_id: user.id
can :moderate, Debate
cannot :moderate, Debate, author_id: user.id
can :hide, Proposal, hidden_at: nil
cannot :hide, Proposal, author_id: user.id
can :ignore_flag, Proposal, ignored_flag_at: nil, hidden_at: nil
cannot :ignore_flag, Proposal, author_id: user.id
can :moderate, Proposal
cannot :moderate, Proposal, author_id: user.id
can :hide, User
cannot :hide, User, id: user.id
can :block, User
cannot :block, User, id: user.id
end
if user.moderator?
can :comment_as_moderator, [Debate, Comment, Proposal]
end
if user.administrator?
can :restore, Comment
cannot :restore, Comment, hidden_at: nil
can :restore, Debate
cannot :restore, Debate, hidden_at: nil
can :restore, Proposal
cannot :restore, Proposal, hidden_at: nil
can :restore, User
cannot :restore, User, hidden_at: nil
can :confirm_hide, Comment
cannot :confirm_hide, Comment, hidden_at: nil
can :confirm_hide, Debate
cannot :confirm_hide, Debate, hidden_at: nil
can :confirm_hide, Proposal
cannot :confirm_hide, Proposal, hidden_at: nil
can :confirm_hide, User
cannot :confirm_hide, User, hidden_at: nil
can :comment_as_administrator, [Debate, Comment, Proposal]
can :manage, Moderator
self.merge Abilities::Administrator.new(user)
elsif user.moderator?
self.merge Abilities::Moderator.new(user)
else
self.merge Abilities::Common.new(user)
end
else
self.merge Abilities::Everyone.new(user)
end
end

View File

@@ -2,21 +2,20 @@ require 'rails_helper'
feature 'Admin moderators' do
background do
@admin = create(:administrator)
@user = create(:user, username: 'Jose Luis Balbin')
@moderator = create(:moderator)
@admin = create(:administrator)
login_as(@admin.user)
visit admin_moderators_path
end
scenario 'Index' do
visit admin_moderators_path
expect(page).to have_content @moderator.name
expect(page).to have_content @moderator.email
expect(page).to_not have_content @user.name
end
scenario 'Create Moderator', :js do
visit admin_moderators_path
fill_in 'email', with: @user.email
click_button 'Search'
@@ -28,7 +27,6 @@ feature 'Admin moderators' do
end
scenario 'Delete Moderator' do
visit admin_moderators_path
click_link 'Delete'
within("#moderators") do

View File

@@ -0,0 +1,52 @@
require 'rails_helper'
require 'cancan/matchers'
describe "Abilities::Administrator" do
subject(:ability) { Ability.new(user) }
let(:user) { administrator.user }
let(:administrator) { create(:administrator) }
let(:other_user) { create(:user) }
let(:hidden_user) { create(:user, :hidden) }
let(:debate) { create(:debate) }
let(:comment) { create(:comment) }
let(:proposal) { create(:proposal) }
let(:hidden_debate) { create(:debate, :hidden) }
let(:hidden_comment) { create(:comment, :hidden) }
let(:hidden_proposal) { create(:proposal, :hidden) }
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should be_able_to(:vote, debate) }
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should_not be_able_to(:restore, comment) }
it { should_not be_able_to(:restore, debate) }
it { should_not be_able_to(:restore, proposal) }
it { should_not be_able_to(:restore, other_user) }
it { should be_able_to(:restore, hidden_comment) }
it { should be_able_to(:restore, hidden_debate) }
it { should be_able_to(:restore, hidden_proposal) }
it { should be_able_to(:restore, hidden_user) }
it { should_not be_able_to(:confirm_hide, comment) }
it { should_not be_able_to(:confirm_hide, debate) }
it { should_not be_able_to(:confirm_hide, proposal) }
it { should_not be_able_to(:confirm_hide, other_user) }
it { should be_able_to(:confirm_hide, hidden_comment) }
it { should be_able_to(:confirm_hide, hidden_debate) }
it { should be_able_to(:confirm_hide, hidden_proposal) }
it { should be_able_to(:confirm_hide, hidden_user) }
it { should be_able_to(:comment_as_administrator, debate) }
it { should_not be_able_to(:comment_as_moderator, debate) }
it { should be_able_to(:comment_as_administrator, proposal) }
it { should_not be_able_to(:comment_as_moderator, proposal) }
end

View File

@@ -0,0 +1,92 @@
require 'rails_helper'
require 'cancan/matchers'
describe "Abilities::Common" do
subject(:ability) { Ability.new(user) }
let(:user) { create(:user) }
let(:debate) { create(:debate) }
let(:comment) { create(:comment) }
let(:proposal) { create(:proposal) }
let(:own_debate) { create(:debate, author: user) }
let(:own_comment) { create(:comment, author: user) }
let(:own_proposal) { create(:proposal, author: user) }
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should be_able_to(:vote, debate) }
it { should be_able_to(:show, user) }
it { should be_able_to(:edit, user) }
it { should be_able_to(:create, Comment) }
it { should be_able_to(:vote, Comment) }
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should_not be_able_to(:vote, Proposal) }
it { should_not be_able_to(:comment_as_administrator, debate) }
it { should_not be_able_to(:comment_as_moderator, debate) }
it { should_not be_able_to(:comment_as_administrator, proposal) }
it { should_not be_able_to(:comment_as_moderator, proposal) }
describe 'flagging content' do
it { should be_able_to(:flag, debate) }
it { should be_able_to(:unflag, debate) }
it { should be_able_to(:flag, comment) }
it { should be_able_to(:unflag, comment) }
it { should be_able_to(:flag, proposal) }
it { should be_able_to(:unflag, proposal) }
describe "own content" do
it { should_not be_able_to(:flag, own_comment) }
it { should_not be_able_to(:unflag, own_comment) }
it { should_not be_able_to(:flag, own_debate) }
it { should_not be_able_to(:unflag, own_debate) }
it { should_not be_able_to(:flag, own_proposal) }
it { should_not be_able_to(:unflag, own_proposal) }
end
end
describe "other users" do
let(:other_user) { create(:user) }
it { should_not be_able_to(:show, other_user) }
it { should_not be_able_to(:edit, other_user) }
end
describe "editing debates" do
let(:own_debate_non_editable) { create(:debate, author: user) }
before { allow(own_debate_non_editable).to receive(:editable?).and_return(false) }
it { should be_able_to(:edit, own_debate) }
it { should_not be_able_to(:edit, debate) } # Not his
it { should_not be_able_to(:edit, own_debate_non_editable) }
end
describe "editing proposals" do
let(:own_proposal_non_editable) { create(:proposal, author: user) }
before { allow(own_proposal_non_editable).to receive(:editable?).and_return(false) }
it { should be_able_to(:edit, own_proposal) }
it { should_not be_able_to(:edit, proposal) } # Not his
it { should_not be_able_to(:edit, own_proposal_non_editable) }
end
describe "when level 2 verified" do
before{ user.update(residence_verified_at: Time.now, confirmed_phone: "1") }
it { should be_able_to(:vote, Proposal) }
end
describe "when level 3 verified" do
before{ user.update(verified_at: Time.now) }
it { should be_able_to(:vote, Proposal) }
end
end

View File

@@ -0,0 +1,24 @@
require 'rails_helper'
require 'cancan/matchers'
describe "Abilities::Everyone" do
subject(:ability) { Ability.new(user) }
let(:user) { nil }
let(:debate) { create(:debate) }
let(:proposal) { create(:proposal) }
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should_not be_able_to(:edit, Debate) }
it { should_not be_able_to(:vote, Debate) }
it { should_not be_able_to(:flag, Debate) }
it { should_not be_able_to(:unflag, Debate) }
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should_not be_able_to(:edit, Proposal) }
it { should_not be_able_to(:vote, Proposal) }
it { should_not be_able_to(:flag, Proposal) }
it { should_not be_able_to(:unflag, Proposal) }
end

View File

@@ -0,0 +1,107 @@
require 'rails_helper'
require 'cancan/matchers'
describe "Abilities::Moderator" do
subject(:ability) { Ability.new(user) }
let(:user) { moderator.user }
let(:moderator) { create(:moderator) }
let(:other_user) { create(:user) }
let(:debate) { create(:debate) }
let(:comment) { create(:comment) }
let(:proposal) { create(:proposal) }
let(:own_debate) { create(:debate, author: user) }
let(:own_comment) { create(:comment, author: user) }
let(:own_proposal) { create(:proposal, author: user) }
let(:hidden_debate) { create(:debate, :hidden) }
let(:hidden_comment) { create(:comment, :hidden) }
let(:hidden_proposal) { create(:proposal, :hidden) }
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should be_able_to(:vote, debate) }
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should be_able_to(:read, Organization) }
describe "organizations" do
let(:pending_organization) { create(:organization) }
let(:rejected_organization) { create(:organization, :rejected) }
let(:verified_organization) { create(:organization, :verified) }
it { should be_able_to( :verify, pending_organization) }
it { should be_able_to( :reject, pending_organization) }
it { should_not be_able_to(:verify, verified_organization) }
it { should be_able_to( :reject, verified_organization) }
it { should_not be_able_to(:reject, rejected_organization) }
it { should be_able_to( :verify, rejected_organization) }
end
describe "hiding, reviewing and restoring" do
let(:ignored_comment) { create(:comment, :with_ignored_flag) }
let(:ignored_debate) { create(:debate, :with_ignored_flag) }
let(:ignored_proposal) { create(:proposal,:with_ignored_flag) }
it { should be_able_to(:hide, comment) }
it { should be_able_to(:hide_in_moderation_screen, comment) }
it { should_not be_able_to(:hide, hidden_comment) }
it { should_not be_able_to(:hide, own_comment) }
it { should be_able_to(:moderate, comment) }
it { should_not be_able_to(:moderate, own_comment) }
it { should be_able_to(:hide, debate) }
it { should be_able_to(:hide_in_moderation_screen, debate) }
it { should_not be_able_to(:hide, hidden_debate) }
it { should_not be_able_to(:hide, own_debate) }
it { should be_able_to(:hide, proposal) }
it { should be_able_to(:hide_in_moderation_screen, proposal) }
it { should_not be_able_to(:hide, hidden_proposal) }
it { should_not be_able_to(:hide, own_proposal) }
it { should be_able_to(:ignore_flag, comment) }
it { should_not be_able_to(:ignore_flag, hidden_comment) }
it { should_not be_able_to(:ignore_flag, ignored_comment) }
it { should_not be_able_to(:ignore_flag, own_comment) }
it { should be_able_to(:ignore_flag, debate) }
it { should_not be_able_to(:ignore_flag, hidden_debate) }
it { should_not be_able_to(:ignore_flag, ignored_debate) }
it { should_not be_able_to(:ignore_flag, own_debate) }
it { should be_able_to(:moderate, debate) }
it { should_not be_able_to(:moderate, own_debate) }
it { should be_able_to(:ignore_flag, proposal) }
it { should_not be_able_to(:ignore_flag, hidden_proposal) }
it { should_not be_able_to(:ignore_flag, ignored_proposal) }
it { should_not be_able_to(:ignore_flag, own_proposal) }
it { should be_able_to(:moderate, proposal) }
it { should_not be_able_to(:moderate, own_proposal) }
it { should_not be_able_to(:hide, user) }
it { should be_able_to(:hide, other_user) }
it { should_not be_able_to(:block, user) }
it { should be_able_to(:block, other_user) }
it { should_not be_able_to(:restore, comment) }
it { should_not be_able_to(:restore, debate) }
it { should_not be_able_to(:restore, proposal) }
it { should_not be_able_to(:restore, other_user) }
it { should be_able_to(:comment_as_moderator, debate) }
it { should be_able_to(:comment_as_moderator, proposal) }
it { should_not be_able_to(:comment_as_administrator, debate) }
it { should_not be_able_to(:comment_as_administrator, proposal) }
end
end

View File

@@ -0,0 +1,24 @@
require 'rails_helper'
require 'cancan/matchers'
describe "Abilities::Organization" do
subject(:ability) { Ability.new(user) }
let(:user) { organization.user }
let(:organization) { create(:organization) }
let(:debate) { create(:debate) }
let(:proposal) { create(:proposal) }
it { should be_able_to(:show, user) }
it { should be_able_to(:edit, user) }
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should_not be_able_to(:vote, debate) }
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should_not be_able_to(:vote, Proposal) }
it { should be_able_to(:create, Comment) }
it { should_not be_able_to(:vote, Comment) }
end

View File

@@ -1,268 +0,0 @@
require 'rails_helper'
require 'cancan/matchers'
describe Ability do
subject(:ability) { Ability.new(user) }
let(:debate) { create(:debate) }
let(:comment) { create(:comment) }
let(:proposal) { create(:proposal) }
let(:own_debate) { create(:debate, author: user) }
let(:own_comment) { create(:comment, author: user) }
let(:own_proposal) { create(:proposal, author: user) }
let(:hidden_debate) { create(:debate, :hidden) }
let(:hidden_comment) { create(:comment, :hidden) }
let(:hidden_proposal) { create(:proposal, :hidden) }
describe "Non-logged in user" do
let(:user) { nil }
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should_not be_able_to(:edit, Debate) }
it { should_not be_able_to(:vote, Debate) }
it { should_not be_able_to(:flag, Debate) }
it { should_not be_able_to(:unflag, Debate) }
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should_not be_able_to(:edit, Proposal) }
it { should_not be_able_to(:vote, Proposal) }
it { should_not be_able_to(:flag, Proposal) }
it { should_not be_able_to(:unflag, Proposal) }
end
describe "Citizen" do
let(:user) { create(:user) }
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should be_able_to(:vote, debate) }
it { should be_able_to(:show, user) }
it { should be_able_to(:edit, user) }
it { should be_able_to(:create, Comment) }
it { should be_able_to(:vote, Comment) }
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should_not be_able_to(:vote, Proposal) }
it { should_not be_able_to(:comment_as_administrator, debate) }
it { should_not be_able_to(:comment_as_moderator, debate) }
it { should_not be_able_to(:comment_as_administrator, proposal) }
it { should_not be_able_to(:comment_as_moderator, proposal) }
describe 'flagging content' do
it { should be_able_to(:flag, debate) }
it { should be_able_to(:unflag, debate) }
it { should be_able_to(:flag, comment) }
it { should be_able_to(:unflag, comment) }
it { should be_able_to(:flag, proposal) }
it { should be_able_to(:unflag, proposal) }
describe "own content" do
it { should_not be_able_to(:flag, own_comment) }
it { should_not be_able_to(:unflag, own_comment) }
it { should_not be_able_to(:flag, own_debate) }
it { should_not be_able_to(:unflag, own_debate) }
it { should_not be_able_to(:flag, own_proposal) }
it { should_not be_able_to(:unflag, own_proposal) }
end
end
describe "other users" do
let(:other_user) { create(:user) }
it { should_not be_able_to(:show, other_user) }
it { should_not be_able_to(:edit, other_user) }
end
describe "editing debates" do
let(:own_debate_non_editable) { create(:debate, author: user) }
before { allow(own_debate_non_editable).to receive(:editable?).and_return(false) }
it { should be_able_to(:edit, own_debate) }
it { should_not be_able_to(:edit, debate) } # Not his
it { should_not be_able_to(:edit, own_debate_non_editable) }
end
describe "editing proposals" do
let(:own_proposal_non_editable) { create(:proposal, author: user) }
before { allow(own_proposal_non_editable).to receive(:editable?).and_return(false) }
it { should be_able_to(:edit, own_proposal) }
it { should_not be_able_to(:edit, proposal) } # Not his
it { should_not be_able_to(:edit, own_proposal_non_editable) }
end
describe "when level 2 verified" do
before{ user.update(residence_verified_at: Time.now, confirmed_phone: "1") }
it { should be_able_to(:vote, Proposal) }
end
describe "when level 3 verified" do
before{ user.update(verified_at: Time.now) }
it { should be_able_to(:vote, Proposal) }
end
end
describe "Organization" do
let(:user) { create(:user) }
before(:each) { create(:organization, user: user) }
it { should be_able_to(:show, user) }
it { should be_able_to(:edit, user) }
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should_not be_able_to(:vote, debate) }
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should_not be_able_to(:vote, Proposal) }
it { should be_able_to(:create, Comment) }
it { should_not be_able_to(:vote, Comment) }
end
describe "Moderator" do
let(:user) { create(:user) }
before { create(:moderator, user: user) }
let(:other_user) { create(:user) }
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should be_able_to(:vote, debate) }
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should be_able_to(:read, Organization) }
describe "organizations" do
let(:pending_organization) { create(:organization) }
let(:rejected_organization) { create(:organization, :rejected) }
let(:verified_organization) { create(:organization, :verified) }
it { should be_able_to( :verify, pending_organization) }
it { should be_able_to( :reject, pending_organization) }
it { should_not be_able_to(:verify, verified_organization) }
it { should be_able_to( :reject, verified_organization) }
it { should_not be_able_to(:reject, rejected_organization) }
it { should be_able_to( :verify, rejected_organization) }
end
describe "hiding, reviewing and restoring" do
let(:ignored_comment) { create(:comment, :with_ignored_flag) }
let(:ignored_debate) { create(:debate, :with_ignored_flag) }
let(:ignored_proposal) { create(:proposal,:with_ignored_flag) }
it { should be_able_to(:hide, comment) }
it { should be_able_to(:hide_in_moderation_screen, comment) }
it { should_not be_able_to(:hide, hidden_comment) }
it { should_not be_able_to(:hide, own_comment) }
it { should be_able_to(:moderate, comment) }
it { should_not be_able_to(:moderate, own_comment) }
it { should be_able_to(:hide, debate) }
it { should be_able_to(:hide_in_moderation_screen, debate) }
it { should_not be_able_to(:hide, hidden_debate) }
it { should_not be_able_to(:hide, own_debate) }
it { should be_able_to(:hide, proposal) }
it { should be_able_to(:hide_in_moderation_screen, proposal) }
it { should_not be_able_to(:hide, hidden_proposal) }
it { should_not be_able_to(:hide, own_proposal) }
it { should be_able_to(:ignore_flag, comment) }
it { should_not be_able_to(:ignore_flag, hidden_comment) }
it { should_not be_able_to(:ignore_flag, ignored_comment) }
it { should_not be_able_to(:ignore_flag, own_comment) }
it { should be_able_to(:ignore_flag, debate) }
it { should_not be_able_to(:ignore_flag, hidden_debate) }
it { should_not be_able_to(:ignore_flag, ignored_debate) }
it { should_not be_able_to(:ignore_flag, own_debate) }
it { should be_able_to(:moderate, debate) }
it { should_not be_able_to(:moderate, own_debate) }
it { should be_able_to(:ignore_flag, proposal) }
it { should_not be_able_to(:ignore_flag, hidden_proposal) }
it { should_not be_able_to(:ignore_flag, ignored_proposal) }
it { should_not be_able_to(:ignore_flag, own_proposal) }
it { should be_able_to(:moderate, proposal) }
it { should_not be_able_to(:moderate, own_proposal) }
it { should_not be_able_to(:hide, user) }
it { should be_able_to(:hide, other_user) }
it { should_not be_able_to(:block, user) }
it { should be_able_to(:block, other_user) }
it { should_not be_able_to(:restore, comment) }
it { should_not be_able_to(:restore, debate) }
it { should_not be_able_to(:restore, proposal) }
it { should_not be_able_to(:restore, other_user) }
it { should be_able_to(:comment_as_moderator, debate) }
it { should be_able_to(:comment_as_moderator, proposal) }
it { should_not be_able_to(:comment_as_administrator, debate) }
it { should_not be_able_to(:comment_as_administrator, proposal) }
end
end
describe "Administrator" do
let(:user) { create(:user) }
before { create(:administrator, user: user) }
let(:other_user) { create(:user) }
let(:hidden_user) { create(:user, :hidden) }
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should be_able_to(:vote, debate) }
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should_not be_able_to(:restore, comment) }
it { should_not be_able_to(:restore, debate) }
it { should_not be_able_to(:restore, proposal) }
it { should_not be_able_to(:restore, other_user) }
it { should be_able_to(:restore, hidden_comment) }
it { should be_able_to(:restore, hidden_debate) }
it { should be_able_to(:restore, hidden_proposal) }
it { should be_able_to(:restore, hidden_user) }
it { should_not be_able_to(:confirm_hide, comment) }
it { should_not be_able_to(:confirm_hide, debate) }
it { should_not be_able_to(:confirm_hide, proposal) }
it { should_not be_able_to(:confirm_hide, other_user) }
it { should be_able_to(:confirm_hide, hidden_comment) }
it { should be_able_to(:confirm_hide, hidden_debate) }
it { should be_able_to(:confirm_hide, hidden_proposal) }
it { should be_able_to(:confirm_hide, hidden_user) }
it { should be_able_to(:comment_as_administrator, debate) }
it { should_not be_able_to(:comment_as_moderator, debate) }
it { should be_able_to(:comment_as_administrator, proposal) }
it { should_not be_able_to(:comment_as_moderator, proposal) }
end
end