From d983443ecc24ce130eb8aef81dce10b9a17e4db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 13 Jun 2021 01:06:31 +0200 Subject: [PATCH] Fix investment support in management section When supporting an investment in the management section through the investment view, we were accessing an action in the public investments controller. This meant the manager was the one supporting the investment (as they'd be the `current_user` in this controller) and not the managed user. In the case of groups with many headings, voting the first time requires a confirmation and then a regular (non-AJAX) request takes place. In this case, users were redirected to the public area instead of remaining in the management area. Using the proper URL to vote solves the problem. Note there was a comment about one of these tests failing in Travis. Most probably the test failed because there was no expectation after clicking the link with the investment title, so the "Support" button (which is also present in the index page) was clicked before the investment view was loaded. --- .../investments/_investment_show.html.erb | 2 +- .../management/budget_investments_spec.rb | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index 621efde66..8920b2ba6 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -35,7 +35,7 @@ <%= render "/budgets/investments/votes", investment: investment, investment_votes: investment_votes, - vote_url: vote_budget_investment_path(investment.budget, investment, value: "yes") %> + vote_url: namespaced_budget_investment_vote_path(investment, value: "yes") %> <% elsif investment.should_show_vote_count? %> diff --git a/spec/system/management/budget_investments_spec.rb b/spec/system/management/budget_investments_spec.rb index 4dd949584..f9273a49c 100644 --- a/spec/system/management/budget_investments_spec.rb +++ b/spec/system/management/budget_investments_spec.rb @@ -284,9 +284,9 @@ describe "Budget Investments" do end end - # This test passes ok locally but fails on the last two lines in Travis - xscenario "Supporting budget investments on behalf of someone in show view" do + scenario "Supporting budget investments on behalf of someone in show view" do budget_investment = create(:budget_investment, budget: budget) + manager.user.update!(level_two_verified_at: Time.current) login_managed_user(user) login_as_manager(manager) @@ -300,9 +300,36 @@ describe "Budget Investments" do click_link budget_investment.title end + expect(page).to have_css "h1", exact_text: budget_investment.title + find(".js-in-favor a").click + expect(page).to have_content "1 support" - expect(page).to have_content "You have already supported this. Share it!" + expect(page).to have_content "You have already supported this investment project. Share it!" + + refresh + + expect(page).to have_content "1 support" + expect(page).to have_content "You have already supported this investment project. Share it!" + end + + scenario "Support investments on behalf of someone else when there are more headings" do + create(:budget_investment, heading: heading, title: "Default heading investment") + create(:budget_investment, heading: create(:budget_heading, group: group)) + + login_managed_user(user) + login_as_manager(manager) + + visit management_budget_investments_path(budget) + click_link "Default heading investment" + + expect(page).to have_css "h1", exact_text: "Default heading investment" + + accept_confirm { find(".js-in-favor a").click } + + expect(page).to have_content "1 support" + expect(page).to have_content "You have already supported this investment project. Share it!" + expect(page).to have_content "CONSUL\nMANAGEMENT" end scenario "Should not allow unverified users to vote proposals" do