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.
This commit is contained in:
Javi Martín
2021-06-13 01:06:31 +02:00
parent 6841fe1491
commit d983443ecc
2 changed files with 31 additions and 4 deletions

View File

@@ -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") %>
</div>
</div>
<% elsif investment.should_show_vote_count? %>

View File

@@ -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