From c92827e89e71bf724e1378176fc98d76df213e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Fri, 21 Jul 2017 11:55:15 +0200 Subject: [PATCH] Add abilities to documentable authors and admins to create and destroy documents. --- app/models/abilities/administrator.rb | 1 + app/models/abilities/common.rb | 2 ++ spec/models/abilities/administrator_spec.rb | 12 ++++++++++++ spec/models/abilities/common_spec.rb | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index bc2fea5d4..b8f80c0cd 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -73,6 +73,7 @@ module Abilities can [:manage], ::Legislation::Question cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation] + can [:create, :destroy], Document end end end diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 33a9d50f6..4eb202332 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -36,6 +36,8 @@ module Abilities can [:create, :destroy], Follow + can [:create, :destroy], Document, documentable: { author_id: user.id } + unless user.organization? can :vote, Debate can :vote, Comment diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index da872e353..bbec927a0 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -12,8 +12,12 @@ describe "Abilities::Administrator" do let(:debate) { create(:debate) } let(:comment) { create(:comment) } let(:proposal) { create(:proposal) } + let(:budget_investment) { create(:budget_investment) } let(:legislation_question) { create(:legislation_question) } + let(:proposal_document) { build(:document, documentable: proposal) } + let(:budget_investment_document) { build(:document, documentable: budget_investment) } + let(:hidden_debate) { create(:debate, :hidden) } let(:hidden_comment) { create(:comment, :hidden) } let(:hidden_proposal) { create(:proposal, :hidden) } @@ -71,4 +75,12 @@ describe "Abilities::Administrator" do it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, phase: 'valuating'))) } it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, phase: 'finished'))) } + + it { should be_able_to(:new, proposal_document) } + it { should be_able_to(:create, proposal_document) } + it { should be_able_to(:destroy, proposal_document) } + + it { should be_able_to(:new, budget_investment_document) } + it { should be_able_to(:create, budget_investment_document) } + it { should be_able_to(:destroy, budget_investment_document) } end diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb index da398e610..a3f8227b3 100644 --- a/spec/models/abilities/common_spec.rb +++ b/spec/models/abilities/common_spec.rb @@ -54,6 +54,11 @@ describe "Abilities::Common" do let(:incoming_poll_question_from_other_geozone) { create(:poll_question, poll: incoming_poll_from_other_geozone) } let(:incoming_poll_question_from_all_geozones) { create(:poll_question, poll: incoming_poll) } + let(:own_proposal_document) { build(:document, documentable: own_proposal) } + let(:proposal_document) { build(:document, documentable: proposal) } + let(:own_budget_investment_document) { build(:document, documentable: own_investment_in_accepting_budget) } + let(:budget_investment_document) { build(:document, documentable: investment_in_accepting_budget) } + it { should be_able_to(:index, Debate) } it { should be_able_to(:show, debate) } it { should be_able_to(:vote, debate) } @@ -82,6 +87,22 @@ describe "Abilities::Common" do it { should_not be_able_to(:create, DirectMessage) } it { should_not be_able_to(:show, DirectMessage) } + it { should be_able_to(:new, own_proposal_document) } + it { should be_able_to(:create, own_proposal_document) } + it { should be_able_to(:destroy, own_proposal_document) } + + it { should_not be_able_to(:new, proposal_document) } + it { should_not be_able_to(:create, proposal_document) } + it { should_not be_able_to(:destroy, proposal_document) } + + it { should be_able_to(:new, own_budget_investment_document) } + it { should be_able_to(:create, own_budget_investment_document) } + it { should be_able_to(:destroy, own_budget_investment_document) } + + it { should_not be_able_to(:new, budget_investment_document) } + it { should_not be_able_to(:create, budget_investment_document) } + it { should_not be_able_to(:destroy, budget_investment_document) } + describe 'flagging content' do it { should be_able_to(:flag, debate) } it { should be_able_to(:unflag, debate) }