From 24740578ffc4fd88f7b16f1d1b016f376c25aa3f Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 9 Sep 2016 19:07:53 +0200 Subject: [PATCH] displays money remaining in each group --- app/models/budget/ballot.rb | 2 +- app/views/budgets/ballot/show.html.erb | 4 ++-- spec/features/budgets/ballots_spec.rb | 13 +++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/models/budget/ballot.rb b/app/models/budget/ballot.rb index 3f71921c0..fa7317dc8 100644 --- a/app/models/budget/ballot.rb +++ b/app/models/budget/ballot.rb @@ -55,7 +55,7 @@ class Budget end def heading_for_group(group) - self.headings.where(group: group).first.id + self.headings.where(group: group).first end end diff --git a/app/views/budgets/ballot/show.html.erb b/app/views/budgets/ballot/show.html.erb index 4b9808aef..de48bb73f 100644 --- a/app/views/budgets/ballot/show.html.erb +++ b/app/views/budgets/ballot/show.html.erb @@ -29,7 +29,7 @@

<%= t("budgets.ballots.show.amount_spent") %> - <%= format_price(@budget, @ballot.amount_spent(@ballot.heading_for_group(group))) %> + <%= format_price(@budget, @ballot.amount_spent(@ballot.heading_for_group(group).id)) %>

<% else %> @@ -48,7 +48,7 @@

<%= t("budgets.ballots.show.remaining", - amount_city: format_price(@budget, @ballot.amount_available(group.headings.first))).html_safe %> + amount_city: format_price(@budget, @ballot.amount_available(@ballot.heading_for_group(group)))).html_safe %>

<% end %> diff --git a/spec/features/budgets/ballots_spec.rb b/spec/features/budgets/ballots_spec.rb index 582853c99..f75cdca77 100644 --- a/spec/features/budgets/ballots_spec.rb +++ b/spec/features/budgets/ballots_spec.rb @@ -315,16 +315,15 @@ feature 'Ballots' do context 'Showing the ballot' do pending "Do not display heading name if there is only one heading in the group (example: group city)" - pending "Money remaining in each group (maybe integrate in an existing scenario)" - scenario 'Displaying the correct count & amount', :focus do + scenario 'Displaying the correct count & amount' do user = create(:user, :level_two) group1 = create(:budget_group, budget: budget) group2 = create(:budget_group, budget: budget) - heading1 = create(:budget_heading, name: "District 1", group: group1) - heading2 = create(:budget_heading, name: "District 2", group: group2) + heading1 = create(:budget_heading, name: "District 1", group: group1, price: 100) + heading2 = create(:budget_heading, name: "District 2", group: group2, price: 50) ballot = create(:budget_ballot, user: user, budget: budget) @@ -349,12 +348,14 @@ feature 'Ballots' do within("#budget_group_#{group1.id}") do expect(page).to have_content "#{group1.name} - #{heading1.name}" - expect(page).to have_content "€20" + expect(page).to have_content "Amount spent €20" + expect(page).to have_content "You still have €80 to invest" end within("#budget_group_#{group2.id}") do expect(page).to have_content "#{group2.name} - #{heading2.name}" - expect(page).to have_content "€15" + expect(page).to have_content "Amount spent €15" + expect(page).to have_content "You still have €35 to invest" end end