From 8083f259c27d7eb821552fa877577d8fc7a96220 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 3 May 2017 17:49:29 +0200 Subject: [PATCH] takes into account headings without balloted investments --- app/models/budget/ballot.rb | 1 + spec/models/budget/ballot_spec.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/budget/ballot.rb b/app/models/budget/ballot.rb index 17e514d2c..6a4047aff 100644 --- a/app/models/budget/ballot.rb +++ b/app/models/budget/ballot.rb @@ -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 diff --git a/spec/models/budget/ballot_spec.rb b/spec/models/budget/ballot_spec.rb index 9d4ff9608..3a9f9f232 100644 --- a/spec/models/budget/ballot_spec.rb +++ b/spec/models/budget/ballot_spec.rb @@ -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