From b4b69d89e7445dcada46faee327949446692afb7 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 13 Aug 2015 20:03:38 +0200 Subject: [PATCH] Updates abilities for the new organisations Note that unverified organisations can now create debates and comments - that is a change over the initial request --- app/models/ability.rb | 17 ++++++----------- spec/models/ability_spec.rb | 38 +++++++++++++++---------------------- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index d1e47095f..0d1a518bf 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -13,24 +13,19 @@ class Ability debate.editable_by?(user) end + can :create, Comment + can :create, Debate + unless user.organization? can :vote, Debate can :vote, Comment end - if !user.organization? || user.verified_organization? - can :create, Comment - can :create, Debate - end - if user.moderator? || user.administrator? - can :verify_organization, User do |u| - !u.verified_organization? - end - can :reject_organization, User do |u| - !u.rejected_organization? - end + can :read, Organization + can(:verify, Organization){ |o| !o.verified? } + can(:reject, Organization){ |o| !o.rejected? } elsif user.administrator? diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 952f1cf1f..0cc6edcc8 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -46,28 +46,18 @@ describe Ability do end describe "Organization" do - let(:user) { create(:organization) } + let(:user) { create(:user) } + before(:each) { create(:organization, user: user) } 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 be_able_to(:create, Comment) } 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 @@ -78,19 +68,21 @@ describe Ability do it { should be_able_to(:show, debate) } it { should be_able_to(:vote, debate) } + it { should be_able_to(:read, Organization) } + describe "organizations" do - let(:pending_organization) { create(:user, organization_name: 'org') } - let(:rejected_organization) { create(:user, organization_name: 'org', organization_rejected_at: Time.now)} - let(:verified_organization) { create(:user, organization_name: 'org', organization_verified_at: Time.now)} + let(:pending_organization) { create(:organization) } + let(:rejected_organization) { create(:rejected_organization) } + let(:verified_organization) { create(:verified_organization) } - it { should be_able_to( :verify_organization, pending_organization) } - it { should be_able_to( :reject_organization, pending_organization) } + it { should be_able_to( :verify, pending_organization) } + it { should be_able_to( :reject, pending_organization) } - it { should_not be_able_to(:verify_organization, verified_organization) } - it { should be_able_to( :reject_organization, verified_organization) } + it { should_not be_able_to(:verify, verified_organization) } + it { should be_able_to( :reject, verified_organization) } - it { should_not be_able_to(:reject_organization, rejected_organization) } - it { should be_able_to( :verify_organization, rejected_organization) } + it { should_not be_able_to(:reject, rejected_organization) } + it { should be_able_to( :verify, rejected_organization) } end end