Files
nairobi/spec/models/valuator_spec.rb
Javi Martín 45c6a70d91 Fix extra nil added to assigned investment IDs
When `valuator_group` was `nil`, `[valuator_group&.investment_ids]` is
evaluated to `nil`, and so we were adding an extra element to the array.

We could add a `compact` call to the resulting array, but I find it
easier to convert `nil` to an array using `to_a`.
2019-09-26 19:58:02 +02:00

63 lines
1.8 KiB
Ruby

require "rails_helper"
describe Valuator do
describe "#description_or_email" do
it "returns description if present" do
valuator = create(:valuator, description: "Urbanism manager")
expect(valuator.description_or_email).to eq("Urbanism manager")
end
it "returns email if not description present" do
valuator = create(:valuator)
expect(valuator.description_or_email).to eq(valuator.email)
end
end
describe "#assigned_investment_ids" do
it "returns investments assigned to a valuator" do
valuator = create(:valuator)
investment1 = create(:budget_investment)
investment2 = create(:budget_investment)
investment3 = create(:budget_investment)
investment1.valuators << valuator
investment2.valuators << valuator
assigned_investment_ids = valuator.assigned_investment_ids
expect(assigned_investment_ids).to match_array [investment1.id, investment2.id]
expect(assigned_investment_ids).not_to include investment3.id
end
it "returns investments assigned to a valuator group" do
group = create(:valuator_group)
valuator = create(:valuator, valuator_group: group)
investment1 = create(:budget_investment)
investment2 = create(:budget_investment)
investment3 = create(:budget_investment)
investment1.valuator_groups << group
investment2.valuator_groups << group
assigned_investment_ids = valuator.assigned_investment_ids
expect(assigned_investment_ids).to match_array [investment1.id, investment2.id]
expect(assigned_investment_ids).not_to include investment3.id
end
end
describe "abilities" do
context "by default" do
let(:valuator) { Valuator.new }
it { expect(valuator.can_comment).to be_truthy }
it { expect(valuator.can_edit_dossier).to be_truthy }
end
end
end