From 3eb22ab7b9710691ccdfd15228039dcfb316dc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 16 May 2017 13:12:32 +0200 Subject: [PATCH 1/3] removes exception on invalid vote responds rendering correct error message instead --- app/controllers/budgets/ballot/lines_controller.rb | 4 +--- app/models/budget/ballot.rb | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb index e341e07d1..64806f2c9 100644 --- a/app/controllers/budgets/ballot/lines_controller.rb +++ b/app/controllers/budgets/ballot/lines_controller.rb @@ -18,9 +18,7 @@ module Budgets load_investment load_heading - unless @ballot.add_investment(@investment) - head :bad_request - end + @ballot.add_investment(@investment) end def destroy diff --git a/app/models/budget/ballot.rb b/app/models/budget/ballot.rb index 6a4047aff..83e799d6f 100644 --- a/app/models/budget/ballot.rb +++ b/app/models/budget/ballot.rb @@ -9,7 +9,7 @@ class Budget has_many :headings, -> { uniq }, through: :groups def add_investment(investment) - lines.create!(investment: investment) + lines.create(investment: investment).persisted? end def total_amount_spent From 86c37d49527202b1a57511a113d432bdd599e63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 16 May 2017 13:12:55 +0200 Subject: [PATCH 2/3] removes old commented code --- app/controllers/budgets/ballot/lines_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb index 64806f2c9..25f356f1f 100644 --- a/app/controllers/budgets/ballot/lines_controller.rb +++ b/app/controllers/budgets/ballot/lines_controller.rb @@ -27,7 +27,6 @@ module Budgets @line.destroy load_investments - #@ballot.reset_geozone end private From da43e9e2e491699fa145afbb200f1bce5dbee697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 17 May 2017 13:03:46 +0200 Subject: [PATCH 3/3] adds spec for edge case --- spec/features/budgets/ballots_spec.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/features/budgets/ballots_spec.rb b/spec/features/budgets/ballots_spec.rb index b7471ee41..b8f40acf0 100644 --- a/spec/features/budgets/ballots_spec.rb +++ b/spec/features/budgets/ballots_spec.rb @@ -592,7 +592,7 @@ feature 'Ballots' do end end - scenario 'Insufficient functs (removed after destroying from sidebar)', :js do + scenario 'Insufficient funds (removed after destroying from sidebar)', :js do bi1 = create(:budget_investment, :selected, heading: california, price: 600) bi2 = create(:budget_investment, :selected, heading: california, price: 500) @@ -621,6 +621,29 @@ feature 'Ballots' do end end + scenario "Edge case voting a non-elegible investment", :js do + investment1 = create(:budget_investment, :selected, heading: new_york, price: 10000) + + login_as(user) + visit budget_path(budget) + click_link "States" + click_link "New York" + + new_york.update(price: 10) + + within("#budget_investment_#{investment1.id}") do + expect(page).to have_selector('.in-favor a', visible: true) + find('.add a').trigger('click') + + expect(page.status_code).to eq(200) + expect(page).to_not have_content "Remove" + expect(page).to have_selector('.participation-not-allowed', visible: false) + find("div.ballot").hover + expect(page).to have_selector('.participation-not-allowed', visible: true) + expect(page).to have_selector('.in-favor a', visible: false) + end + end + scenario "Balloting is disabled when budget isn't in the balotting phase", :js do budget.update(phase: 'accepting')