From 9ee1e5dbc54fe3e56073104da529ae6b78472297 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 11 Aug 2015 19:34:18 +0200 Subject: [PATCH] Adds Abilities for Organizations --- app/models/ability.rb | 14 +++++++++++--- spec/models/ability_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index c1fc24ae3..3314bc321 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -8,14 +8,22 @@ class Ability if user # logged-in users can [:read, :update], User, id: user.id - can [:read, :create, :vote], Debate + can :read, Debate can :update, Debate do |debate| debate.editable_by?(user) end - can [:create, :vote], Comment + unless user.organization? + can :vote, Debate + can :vote, Comment + end - if user.moderator? or user.administrator? + if !user.organization? || user.verified_organization? + can :create, Comment + can :create, Debate + end + + if user.moderator? || user.administrator? elsif user.administrator? diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 3954ec600..352f8085c 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -45,6 +45,31 @@ describe Ability do end end + describe "Organization" do + let(:user) { create(:user, organization_name: "Organization") } + + it { should be_able_to(:show, user) } + it { should be_able_to(:edit, user) } + + it { should be_able_to(:index, Debate) } + it { should be_able_to(:show, debate) } + + it { should_not be_able_to(:vote, debate) } + it { should_not be_able_to(:vote, Comment) } + + describe "Not verified" do + it { should_not be_able_to(:create, Comment) } + it { should_not be_able_to(:create, Debate) } + end + + describe "Verified" do + before(:each) { user.organization_verified_at = Time.now } + + it { should be_able_to(:create, Comment) } + it { should be_able_to(:create, Debate) } + end + end + describe "Moderator" do let(:user) { create(:user) } before { create(:moderator, user: user) }