Implements abilities for poll & poll_question
This commit is contained in:
@@ -48,6 +48,8 @@ module Abilities
|
||||
can :create, SpendingProposal
|
||||
can :create, DirectMessage
|
||||
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
|
||||
|
||||
can [:create, :show], ProposalNotification, proposal: { author_id: user.id }
|
||||
|
||||
@@ -3,8 +3,9 @@ require 'cancan/matchers'
|
||||
|
||||
describe "Abilities::Common" do
|
||||
subject(:ability) { Ability.new(user) }
|
||||
let(:geozone) { create(:geozone) }
|
||||
|
||||
let(:user) { create(:user) }
|
||||
let(:user) { create(:user, geozone: geozone) }
|
||||
|
||||
let(:debate) { create(:debate) }
|
||||
let(:comment) { create(:comment) }
|
||||
@@ -13,6 +14,13 @@ describe "Abilities::Common" do
|
||||
let(:own_comment) { create(:comment, 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(:show, 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(:show, own_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
|
||||
|
||||
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(:show, own_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
|
||||
|
||||
Reference in New Issue
Block a user