Implements abilities for poll & poll_question

This commit is contained in:
kikito
2016-11-07 10:37:22 +01:00
parent 35a5136d9f
commit f821d7beb7
2 changed files with 25 additions and 1 deletions

View File

@@ -48,6 +48,8 @@ module Abilities
can :create, SpendingProposal can :create, SpendingProposal
can :create, DirectMessage can :create, DirectMessage
can :show, DirectMessage, sender_id: user.id can :show, DirectMessage, sender_id: user.id
can(:answer, Poll, Poll.current){ |poll| poll.current? }
can :answer, Poll::Question, geozones: {id: user.geozone_id}
end end
can [:create, :show], ProposalNotification, proposal: { author_id: user.id } can [:create, :show], ProposalNotification, proposal: { author_id: user.id }

View File

@@ -3,8 +3,9 @@ require 'cancan/matchers'
describe "Abilities::Common" do describe "Abilities::Common" do
subject(:ability) { Ability.new(user) } subject(:ability) { Ability.new(user) }
let(:geozone) { create(:geozone) }
let(:user) { create(:user) } let(:user) { create(:user, geozone: geozone) }
let(:debate) { create(:debate) } let(:debate) { create(:debate) }
let(:comment) { create(:comment) } let(:comment) { create(:comment) }
@@ -13,6 +14,13 @@ describe "Abilities::Common" do
let(:own_comment) { create(:comment, author: user) } let(:own_comment) { create(:comment, author: user) }
let(:own_proposal) { create(:proposal, author: user) } let(:own_proposal) { create(:proposal, author: user) }
let(:current_poll) { create(:poll) }
let(:incoming_poll) { create(:poll, :incoming) }
let(:expired_poll) { create(:poll, :expired) }
let(:poll_question_from_own_geozone) { create(:poll_question, geozones: [geozone]) }
let(:poll_question_from_other_geozone) { create(:poll_question, geozones: [create(:geozone)]) }
it { should be_able_to(:index, Debate) } it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) } it { should be_able_to(:show, debate) }
it { should be_able_to(:vote, debate) } it { should be_able_to(:vote, debate) }
@@ -103,6 +111,13 @@ describe "Abilities::Common" do
it { should be_able_to(:create, DirectMessage) } it { should be_able_to(:create, DirectMessage) }
it { should be_able_to(:show, own_direct_message) } it { should be_able_to(:show, own_direct_message) }
it { should_not be_able_to(:show, create(:direct_message)) } it { should_not be_able_to(:show, create(:direct_message)) }
it { should be_able_to(:answer, current_poll) }
it { should_not be_able_to(:answer, expired_poll) }
it { should_not be_able_to(:answer, incoming_poll) }
it { should be_able_to(:answer, poll_question_from_own_geozone ) }
it { should_not be_able_to(:answer, poll_question_from_other_geozone ) }
end end
describe "when level 3 verified" do describe "when level 3 verified" do
@@ -121,5 +136,12 @@ describe "Abilities::Common" do
it { should be_able_to(:create, DirectMessage) } it { should be_able_to(:create, DirectMessage) }
it { should be_able_to(:show, own_direct_message) } it { should be_able_to(:show, own_direct_message) }
it { should_not be_able_to(:show, create(:direct_message)) } it { should_not be_able_to(:show, create(:direct_message)) }
it { should be_able_to(:answer, current_poll) }
it { should_not be_able_to(:answer, expired_poll) }
it { should_not be_able_to(:answer, incoming_poll) }
it { should be_able_to(:answer, poll_question_from_own_geozone ) }
it { should_not be_able_to(:answer, poll_question_from_other_geozone ) }
end end
end end