Adds valuator investment abilities
This commit is contained in:
@@ -3,7 +3,9 @@ module Abilities
|
|||||||
include CanCan::Ability
|
include CanCan::Ability
|
||||||
|
|
||||||
def initialize(user)
|
def initialize(user)
|
||||||
|
valuator = user.valuator
|
||||||
can [:read, :update, :valuate], SpendingProposal
|
can [:read, :update, :valuate], SpendingProposal
|
||||||
|
can [:update, :valuate], Budget::Investment, id: valuator.investment_ids, budget: { valuating: true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -4,6 +4,8 @@ class Valuator < ActiveRecord::Base
|
|||||||
|
|
||||||
has_many :valuation_assignments, dependent: :destroy
|
has_many :valuation_assignments, dependent: :destroy
|
||||||
has_many :spending_proposals, through: :valuation_assignments
|
has_many :spending_proposals, through: :valuation_assignments
|
||||||
|
has_many :valuator_assignments, dependent: :destroy, class_name: 'Budget::ValuatorAssignment'
|
||||||
|
has_many :investments, through: :valuator_assignments, class_name: 'Budget::Investment'
|
||||||
|
|
||||||
validates :user_id, presence: true, uniqueness: true
|
validates :user_id, presence: true, uniqueness: true
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,24 @@ describe "Abilities::Valuator" do
|
|||||||
subject(:ability) { Ability.new(user) }
|
subject(:ability) { Ability.new(user) }
|
||||||
let(:user) { valuator.user }
|
let(:user) { valuator.user }
|
||||||
let(:valuator) { create(:valuator) }
|
let(:valuator) { create(:valuator) }
|
||||||
|
let(:non_assigned_investment) { create(:budget_investment) }
|
||||||
|
|
||||||
|
let(:assigned_investment) { create(:budget_investment, budget: create(:budget, valuating: true)) }
|
||||||
|
before(:each) { assigned_investment.valuators << valuator }
|
||||||
|
|
||||||
|
let(:assigned_investment_not_valuating) { create(:budget_investment, budget: create(:budget, valuating: false)) }
|
||||||
|
before(:each) { assigned_investment_not_valuating.valuators << valuator }
|
||||||
|
|
||||||
it { should be_able_to(:read, SpendingProposal) }
|
it { should be_able_to(:read, SpendingProposal) }
|
||||||
it { should be_able_to(:update, SpendingProposal) }
|
it { should be_able_to(:update, SpendingProposal) }
|
||||||
it { should be_able_to(:valuate, SpendingProposal) }
|
it { should be_able_to(:valuate, SpendingProposal) }
|
||||||
|
|
||||||
|
it { should_not be_able_to(:update, non_assigned_investment) }
|
||||||
|
it { should_not be_able_to(:valuate, non_assigned_investment) }
|
||||||
|
|
||||||
|
it { should be_able_to(:update, assigned_investment) }
|
||||||
|
it { should be_able_to(:valuate, assigned_investment) }
|
||||||
|
|
||||||
|
it { should_not be_able_to(:update, assigned_investment_not_valuating) }
|
||||||
|
it { should_not be_able_to(:valuate, assigned_investment_not_valuating) }
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user