From 1770dfd3f6e749ccb7eebfcd035b8783110631d3 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 27 Aug 2015 13:20:12 +0200 Subject: [PATCH] adds ability to confirm the hiding of comments, debates or users --- app/models/ability.rb | 15 +++++++++++++++ spec/factories.rb | 4 ++++ spec/models/ability_spec.rb | 27 +++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 3f209d626..e931d037f 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -72,8 +72,23 @@ class Ability if user.administrator? can :restore, Comment + cannot :restore, Comment, hidden_at: nil + can :restore, Debate + cannot :restore, Debate, 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, User + cannot :confirm_hide, User, hidden_at: nil + can :comment_as_administrator, [Debate, Comment] end end diff --git a/spec/factories.rb b/spec/factories.rb index 38ba6fd16..9734b3364 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -4,6 +4,10 @@ FactoryGirl.define do sequence(:email) { |n| "manuela#{n}@madrid.es" } password 'judgmentday' confirmed_at { Time.now } + + trait :hidden do + hidden_at Time.now + end end factory :identity do diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 088516d1a..06e2a9a62 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -169,15 +169,34 @@ describe Ability do describe "Administrator" do let(:user) { create(:user) } before { create(:administrator, user: user) } - let(:other_user) { create(:user) } + + let(:other_user) { create(:user) } + let(:hidden_user) { create(:user, :hidden) } + + let(:hidden_debate) { create(:debate, :hidden) } + let(:hidden_comment) { create(:comment, :hidden) } + let(:own_debate) { create(:debate, author: user)} + let(:own_comment) { create(:comment, 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(:restore, comment) } - it { should be_able_to(:restore, debate) } - it { should be_able_to(:restore, 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, 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_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, 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_user) } it { should be_able_to(:comment_as_administrator, debate) } it { should_not be_able_to(:comment_as_moderator, debate) }