Adds Abilities for Organizations

This commit is contained in:
kikito
2015-08-11 19:34:18 +02:00
parent 83e3dd1c6f
commit 9ee1e5dbc5
2 changed files with 36 additions and 3 deletions

View File

@@ -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?

View File

@@ -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) }