Takes already-flagged-content out of Ability's concerns
This commit is contained in:
@@ -22,21 +22,11 @@ class Ability
|
||||
can :create, Comment
|
||||
can :create, Debate
|
||||
|
||||
can :flag, Comment do |comment|
|
||||
comment.author_id != user.id && !Flag.flagged?(user, comment)
|
||||
end
|
||||
can [:flag, :unflag], Comment
|
||||
cannot [:flag, :unflag], Comment, user_id: user.id
|
||||
|
||||
can :unflag, Comment do |comment|
|
||||
comment.author_id != user.id && Flag.flagged?(user, comment)
|
||||
end
|
||||
|
||||
can :flag, Debate do |debate|
|
||||
debate.author_id != user.id && !Flag.flagged?(user, debate)
|
||||
end
|
||||
|
||||
can :unflag, Debate do |debate|
|
||||
debate.author_id != user.id && Flag.flagged?(user, debate)
|
||||
end
|
||||
can [:flag, :unflag], Debate
|
||||
cannot [:flag, :unflag], Debate, author_id: user.id
|
||||
|
||||
unless user.organization?
|
||||
can :vote, Debate
|
||||
|
||||
@@ -33,9 +33,10 @@ describe Ability do
|
||||
|
||||
describe 'flagging content' do
|
||||
it { should be_able_to(:flag, debate) }
|
||||
it { should_not be_able_to(:unflag, debate) }
|
||||
it { should be_able_to(:unflag, debate) }
|
||||
|
||||
it { should be_able_to(:flag, comment) }
|
||||
it { should_not be_able_to(:unflag, comment) }
|
||||
it { should be_able_to(:unflag, comment) }
|
||||
|
||||
describe "own comments" do
|
||||
let(:own_comment) { create(:comment, author: user) }
|
||||
@@ -50,20 +51,6 @@ describe Ability do
|
||||
it { should_not be_able_to(:flag, own_debate) }
|
||||
it { should_not be_able_to(:unflag, own_debate) }
|
||||
end
|
||||
|
||||
describe "already-flagged comments" do
|
||||
before(:each) { Flag.flag(user, comment) }
|
||||
|
||||
it { should_not be_able_to(:flag, comment) }
|
||||
it { should be_able_to(:unflag, comment) }
|
||||
end
|
||||
|
||||
describe "already-flagged debates" do
|
||||
before(:each) { Flag.flag(user, debate) }
|
||||
|
||||
it { should_not be_able_to(:flag, debate) }
|
||||
it { should be_able_to(:unflag, debate) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "other users" do
|
||||
|
||||
Reference in New Issue
Block a user