Adds valuator investment abilities

This commit is contained in:
kikito
2016-05-30 13:55:12 +02:00
parent daa8783b02
commit 13f43d8b67
3 changed files with 21 additions and 1 deletions

View File

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

View File

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

View File

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