diff --git a/app/models/ability.rb b/app/models/ability.rb index d8436a700..0d2ac3f8b 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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 diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 43dc06a23..f106ef14e 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -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