takes into account headings without balloted investments

This commit is contained in:
rgarcia
2017-05-03 17:49:29 +02:00
parent 2f6c1bc7bc
commit 8083f259c2
2 changed files with 14 additions and 1 deletions

View File

@@ -66,6 +66,7 @@ class Budget
end
def heading_for_group(group)
return nil unless has_lines_in_group?(group)
self.investments.where(group: group).first.heading
end

View File

@@ -79,7 +79,7 @@ describe Budget::Ballot do
describe "#heading_for_group" do
it "returns the heading with investments for a group" do
it "returns the heading with balloted investments for a group" do
budget = create(:budget)
group = create(:budget_group, budget: budget)
@@ -95,6 +95,18 @@ describe Budget::Ballot do
expect(ballot.heading_for_group(group)).to eq heading2
end
it "returns nil if there are no headings with balloted investments in a group" do
budget = create(:budget)
group = create(:budget_group, budget: budget)
heading1 = create(:budget_heading, group: group)
heading2 = create(:budget_heading, group: group)
ballot = create(:budget_ballot, budget: budget)
expect(ballot.heading_for_group(group)).to eq nil
end
end
end