@@ -32,10 +32,7 @@
<%= t("budgets.investments.show.supports") %>
- <%= render "/budgets/investments/votes",
- investment: investment,
- investment_votes: investment_votes,
- vote_url: namespaced_budget_investment_vote_path(investment, value: "yes") %>
+ <%= render Budgets::Investments::VotesComponent.new(investment) %>
<% elsif investment.should_show_vote_count? %>
diff --git a/app/views/budgets/investments/_votes.html.erb b/app/views/budgets/investments/_votes.html.erb
deleted file mode 100644
index d134506c1..000000000
--- a/app/views/budgets/investments/_votes.html.erb
+++ /dev/null
@@ -1,5 +0,0 @@
-<%= render Budgets::Investments::VotesComponent.new(
- investment,
- investment_votes: investment_votes,
- vote_url: vote_url
-) %>
diff --git a/app/views/budgets/investments/index.html.erb b/app/views/budgets/investments/index.html.erb
index dd363e037..07e604f1e 100644
--- a/app/views/budgets/investments/index.html.erb
+++ b/app/views/budgets/investments/index.html.erb
@@ -78,7 +78,6 @@
<%= render "/budgets/investments/investment",
investment: investment,
investment_ids: @investment_ids,
- investment_votes: @investment_votes,
ballot: @ballot %>
<% end %>
<% else %>
diff --git a/app/views/budgets/investments/show.html.erb b/app/views/budgets/investments/show.html.erb
index bc3976ead..8c342c5ef 100644
--- a/app/views/budgets/investments/show.html.erb
+++ b/app/views/budgets/investments/show.html.erb
@@ -6,7 +6,6 @@
<%= render "/budgets/investments/investment_show",
investment: @investment,
investment_ids: @investment_ids,
- investment_votes: @investment_votes,
ballot: @ballot %>
diff --git a/app/views/budgets/investments/vote.js.erb b/app/views/budgets/investments/vote.js.erb
deleted file mode 100644
index 74ce74ccf..000000000
--- a/app/views/budgets/investments/vote.js.erb
+++ /dev/null
@@ -1,4 +0,0 @@
-$("#<%= dom_id(@investment) %>_votes").html("<%= j render("/budgets/investments/votes",
- investment: @investment,
- investment_votes: @investment_votes,
- vote_url: namespaced_budget_investment_vote_path(@investment, value: "yes")) %>");
diff --git a/app/views/budgets/investments/votes/show.js.erb b/app/views/budgets/investments/votes/show.js.erb
new file mode 100644
index 000000000..bd86e7547
--- /dev/null
+++ b/app/views/budgets/investments/votes/show.js.erb
@@ -0,0 +1,2 @@
+$("#<%= dom_id(@investment) %>_votes")
+ .html("<%= j render Budgets::Investments::VotesComponent.new(@investment) %>");
diff --git a/app/views/management/budgets/investments/index.html.erb b/app/views/management/budgets/investments/index.html.erb
index e44f904de..ad00520b7 100644
--- a/app/views/management/budgets/investments/index.html.erb
+++ b/app/views/management/budgets/investments/index.html.erb
@@ -21,7 +21,6 @@
<%= render "/budgets/investments/investment",
investment: investment,
investment_ids: @investment_ids,
- investment_votes: @investment_votes,
ballot: @ballot %>
<% end %>
diff --git a/app/views/management/budgets/investments/print.html.erb b/app/views/management/budgets/investments/print.html.erb
index f6fcc4bab..f2ef18e22 100644
--- a/app/views/management/budgets/investments/print.html.erb
+++ b/app/views/management/budgets/investments/print.html.erb
@@ -26,7 +26,6 @@
<%= render "/budgets/investments/investment",
investment: investment,
investment_ids: @investment_ids,
- investment_votes: @investment_votes,
ballot: @ballot %>
<% end %>
diff --git a/app/views/management/budgets/investments/show.html.erb b/app/views/management/budgets/investments/show.html.erb
index 99dea2eaa..903b7ae39 100644
--- a/app/views/management/budgets/investments/show.html.erb
+++ b/app/views/management/budgets/investments/show.html.erb
@@ -2,6 +2,4 @@
<%= render "/shared/print" %>
-<%= render "/budgets/investments/investment_show",
- investment: @investment,
- investment_votes: @investment_votes %>
+<%= render "/budgets/investments/investment_show", investment: @investment %>
diff --git a/app/views/management/budgets/investments/vote.js.erb b/app/views/management/budgets/investments/vote.js.erb
deleted file mode 100644
index 74ce74ccf..000000000
--- a/app/views/management/budgets/investments/vote.js.erb
+++ /dev/null
@@ -1,4 +0,0 @@
-$("#<%= dom_id(@investment) %>_votes").html("<%= j render("/budgets/investments/votes",
- investment: @investment,
- investment_votes: @investment_votes,
- vote_url: namespaced_budget_investment_vote_path(@investment, value: "yes")) %>");
diff --git a/app/views/management/budgets/investments/votes/show.js.erb b/app/views/management/budgets/investments/votes/show.js.erb
new file mode 100644
index 000000000..bd86e7547
--- /dev/null
+++ b/app/views/management/budgets/investments/votes/show.js.erb
@@ -0,0 +1,2 @@
+$("#<%= dom_id(@investment) %>_votes")
+ .html("<%= j render Budgets::Investments::VotesComponent.new(@investment) %>");
diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml
index 5b143a513..e2c8e65fd 100644
--- a/config/locales/en/budgets.yml
+++ b/config/locales/en/budgets.yml
@@ -156,23 +156,26 @@ en:
investment:
add: Vote
already_added: You have already added this investment project
- already_supported: You have already supported this investment project. Share it!
support_title: Support this project
- support_label: "Support %{investment}"
- confirm_group:
- one: "You can only support investments in %{count} district. If you continue you cannot change the election of your district. Are you sure?"
- other: "You can only support investments in %{count} districts. If you continue you cannot change the election of your district. Are you sure?"
supports:
one: 1 support
other: "%{count} supports"
zero: No supports
- give_support: Support
header:
check_ballot: "Submit my ballot"
different_heading_assigned: "You have active votes in another heading: %{heading_link}"
change_ballot: "If you change your mind you can remove your votes in %{check_ballot} and start again."
check_ballot_link: "submit my ballot"
price: "Total budget"
+ votes:
+ already_supported: "You have already supported this investment project. Share it!"
+ confirm_group:
+ one: "You can only support investments in %{count} district. If you continue you cannot change the election of your district. Are you sure?"
+ other: "You can only support investments in %{count} districts. If you continue you cannot change the election of your district. Are you sure?"
+ remove_support: "Remove your support"
+ remove_support_label: "Remove your support to %{investment}"
+ support: "Support"
+ support_label: "Support %{investment}"
investments_list:
investment:
price: "Price"
@@ -185,7 +188,6 @@ en:
supports_info:
different: "You may support on as many different projects as you would like."
next: "Support the projects you would like to see move on to the next phase."
- remember: "Remember! You can only cast your support once for each project and each support is irreversible."
scrolling: "Keep scrolling to see all ideas"
share: "You can share the projects you have supported on through social media and attract more attention and support to them!"
supported:
diff --git a/config/locales/en/responders.yml b/config/locales/en/responders.yml
index 82ee36271..7fb544b97 100644
--- a/config/locales/en/responders.yml
+++ b/config/locales/en/responders.yml
@@ -14,6 +14,7 @@ en:
proposal_notification: "Your message has been sent correctly."
budget_investment: "Budget Investment created successfully."
signature_sheet: "Signature sheet created successfully"
+ support: "Investment supported successfully"
topic: "Topic created successfully."
valuator_group: "Valuator group created successfully"
save_changes:
diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml
index 1921ddb88..3f232f6f2 100644
--- a/config/locales/es/budgets.yml
+++ b/config/locales/es/budgets.yml
@@ -156,23 +156,26 @@ es:
investment:
add: Votar
already_added: Ya has añadido este proyecto de gasto
- already_supported: Ya has apoyado este proyecto de gasto. ¡Compártelo!
support_title: Apoyar este proyecto
- support_label: "Apoyar %{investment}"
- confirm_group:
- one: "Sólo puedes apoyar proyectos en %{count} distrito. Si sigues adelante no podrás cambiar la elección de este distrito. ¿Estás seguro/a?"
- other: "Sólo puedes apoyar proyectos en %{count} distritos. Si sigues adelante no podrás cambiar la elección de este distrito. ¿Estás seguro/a?"
supports:
zero: Sin apoyos
one: 1 apoyo
other: "%{count} apoyos"
- give_support: Apoyar
header:
check_ballot: Revisar y confirmar mis votos
different_heading_assigned: "Ya apoyaste proyectos de otra sección del presupuesto: %{heading_link}"
change_ballot: "Si cambias de opinión puedes borrar tus votos en %{check_ballot} y volver a empezar."
check_ballot_link: "revisar y confirmar mis votos"
price: "Presupuesto total"
+ votes:
+ already_supported: "Ya has apoyado este proyecto de gasto. ¡Compártelo!"
+ confirm_group:
+ one: "Sólo puedes apoyar proyectos en %{count} distrito. Si sigues adelante no podrás cambiar la elección de este distrito. ¿Estás seguro/a?"
+ other: "Sólo puedes apoyar proyectos en %{count} distritos. Si sigues adelante no podrás cambiar la elección de este distrito. ¿Estás seguro/a?"
+ remove_support: "Eliminar apoyo"
+ remove_support_label: "Eliminar tu apoyo a %{investment}"
+ support: "Apoyar"
+ support_label: "Apoyar %{investment}"
investments_list:
investment:
price: "Coste"
@@ -185,7 +188,6 @@ es:
supports_info:
different: "Puedes apoyar tantos proyectos diferentes como quieras."
next: "Apoya proyectos que te gustaría ver en la siguiente fase."
- remember: "¡Recuerda! Solo puedes emitir tu apoyo una vez por cada proyecto y cada apoyo es irreversible."
scrolling: "Sigue desplazándote para ver todas las ideas"
share: "Puedes compartir los proyectos que has apoyado en las redes sociales y ¡atraer más atención y apoyos para ellos!"
supported:
diff --git a/config/locales/es/responders.yml b/config/locales/es/responders.yml
index fc12f9961..6092cf9ff 100644
--- a/config/locales/es/responders.yml
+++ b/config/locales/es/responders.yml
@@ -14,6 +14,7 @@ es:
proposal_notification: "Tu mensaje ha sido enviado correctamente."
budget_investment: "Proyecto de gasto creado correctamente."
signature_sheet: "Hoja de firmas creada correctamente"
+ support: "Proyecto de gasto apoyado correctamente"
topic: "Tema creado correctamente."
valuator_group: "Grupo de evaluadores creado correctamente"
save_changes:
diff --git a/config/routes/budget.rb b/config/routes/budget.rb
index bed9b7324..416bdf88e 100644
--- a/config/routes/budget.rb
+++ b/config/routes/budget.rb
@@ -2,12 +2,13 @@ resources :budgets, only: [:show, :index] do
resources :groups, controller: "budgets/groups", only: [:show]
resources :investments, controller: "budgets/investments" do
member do
- post :vote
put :flag
put :unflag
end
collection { get :suggest }
+
+ resources :votes, controller: "budgets/investments/votes", only: [:create, :destroy]
end
resource :ballot, only: :show, controller: "budgets/ballots" do
diff --git a/config/routes/management.rb b/config/routes/management.rb
index 7b35850b9..9de4ef731 100644
--- a/config/routes/management.rb
+++ b/config/routes/management.rb
@@ -39,8 +39,9 @@ namespace :management do
end
resources :investments, only: [:index, :new, :create, :show, :destroy], controller: "budgets/investments" do
- post :vote, on: :member
get :print, on: :collection
+
+ resources :votes, controller: "budgets/investments/votes", only: [:create, :destroy]
end
end
end
diff --git a/spec/components/budgets/investments/votes_component_spec.rb b/spec/components/budgets/investments/votes_component_spec.rb
index 0b85f7f20..a3b3fdae0 100644
--- a/spec/components/budgets/investments/votes_component_spec.rb
+++ b/spec/components/budgets/investments/votes_component_spec.rb
@@ -4,9 +4,7 @@ describe Budgets::Investments::VotesComponent, type: :component do
describe "vote link" do
context "when investment shows votes" do
let(:investment) { create(:budget_investment, title: "Renovate sidewalks in Main Street") }
- let(:component) do
- Budgets::Investments::VotesComponent.new(investment, investment_votes: [], vote_url: "/")
- end
+ let(:component) { Budgets::Investments::VotesComponent.new(investment) }
before { allow(investment).to receive(:should_show_votes?).and_return(true) }
@@ -25,8 +23,21 @@ describe Budgets::Investments::VotesComponent, type: :component do
render_inline component
+ expect(page).to have_button count: 1, disabled: :all
expect(page).to have_button "Support", disabled: true
end
+
+ it "shows the button to remove support when users have supported the investment" do
+ user = create(:user)
+ user.up_votes(investment)
+ allow(controller).to receive(:current_user).and_return(user)
+
+ render_inline component
+
+ expect(page).to have_button count: 1, disabled: :all
+ expect(page).to have_button "Remove your support"
+ expect(page).to have_button "Remove your support to Renovate sidewalks in Main Street"
+ end
end
end
end
diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb
index 2cd3815f4..8cce034f2 100644
--- a/spec/models/abilities/common_spec.rb
+++ b/spec/models/abilities/common_spec.rb
@@ -248,9 +248,12 @@ describe Abilities::Common do
it { should_not be_able_to(:create, investment_in_selecting_budget) }
it { should_not be_able_to(:create, investment_in_balloting_budget) }
- it { should be_able_to(:vote, investment_in_selecting_budget) }
- it { should_not be_able_to(:vote, investment_in_accepting_budget) }
- it { should_not be_able_to(:vote, investment_in_balloting_budget) }
+ it { should be_able_to(:create, user.votes.build(votable: investment_in_selecting_budget)) }
+ it { should_not be_able_to(:create, user.votes.build(votable: investment_in_accepting_budget)) }
+ it { should_not be_able_to(:create, user.votes.build(votable: investment_in_balloting_budget)) }
+ it { should be_able_to(:destroy, create(:vote, voter: user, votable: investment_in_selecting_budget)) }
+ it { should_not be_able_to(:destroy, create(:vote, voter: user, votable: investment_in_accepting_budget)) }
+ it { should_not be_able_to(:destroy, create(:vote, voter: user, votable: investment_in_balloting_budget)) }
it { should_not be_able_to(:destroy, investment_in_accepting_budget) }
it { should_not be_able_to(:destroy, investment_in_reviewing_budget) }
diff --git a/spec/system/budgets/budgets_spec.rb b/spec/system/budgets/budgets_spec.rb
index 9aa52b13e..9214ff311 100644
--- a/spec/system/budgets/budgets_spec.rb
+++ b/spec/system/budgets/budgets_spec.rb
@@ -432,6 +432,42 @@ describe "Budgets" do
expect(page).to have_content "It's time to support projects!"
expect(page).to have_content "So far you've supported 3 projects."
end
+
+ scenario "Show supports only if the support has not been removed" do
+ voter = create(:user, :level_two)
+ budget = create(:budget, phase: "selecting")
+ investment = create(:budget_investment, :selected, budget: budget)
+
+ login_as(voter)
+
+ visit budget_path(budget)
+
+ expect(page).to have_content "So far you've supported 0 projects."
+
+ visit budget_investment_path(budget, investment)
+
+ within("#budget_investment_#{investment.id}_votes") do
+ click_button "Support"
+
+ expect(page).to have_content "You have already supported this investment project."
+ end
+
+ visit budget_path(budget)
+
+ expect(page).to have_content "So far you've supported 1 project."
+
+ visit budget_investment_path(budget, investment)
+
+ within("#budget_investment_#{investment.id}_votes") do
+ click_button "Remove your support"
+
+ expect(page).to have_content "No supports"
+ end
+
+ visit budget_path(budget)
+
+ expect(page).to have_content "So far you've supported 0 projects."
+ end
end
context "In Drafting phase" do
diff --git a/spec/system/budgets/investments_spec.rb b/spec/system/budgets/investments_spec.rb
index 2b1d3ae48..ea9075c93 100644
--- a/spec/system/budgets/investments_spec.rb
+++ b/spec/system/budgets/investments_spec.rb
@@ -1177,6 +1177,48 @@ describe "Budget Investments" do
expect(page).to have_content "SUPPORTS"
end
end
+
+ scenario "Remove a support from show view" do
+ investment = create(:budget_investment, budget: budget)
+
+ login_as(author)
+ visit budget_investment_path(budget, investment)
+
+ within("aside") do
+ expect(page).to have_content "No supports"
+
+ click_button "Support"
+
+ expect(page).to have_content "1 support"
+ expect(page).to have_content "You have already supported this investment project."
+
+ click_button "Remove your support"
+
+ expect(page).to have_content "No supports"
+ expect(page).to have_button "Support"
+ end
+ end
+
+ scenario "Remove a support from index view" do
+ investment = create(:budget_investment, budget: budget)
+
+ login_as(author)
+ visit budget_investments_path(budget)
+
+ within("#budget_investment_#{investment.id}") do
+ expect(page).to have_content "No supports"
+
+ click_button "Support"
+
+ expect(page).to have_content "1 support"
+ expect(page).to have_content "You have already supported this investment project."
+
+ click_button "Remove your support"
+
+ expect(page).to have_content "No supports"
+ expect(page).to have_button "Support"
+ end
+ end
end
context "Evaluating Phase" do
diff --git a/spec/system/budgets/votes_spec.rb b/spec/system/budgets/votes_spec.rb
index 5e1aff243..2a9de4659 100644
--- a/spec/system/budgets/votes_spec.rb
+++ b/spec/system/budgets/votes_spec.rb
@@ -127,6 +127,8 @@ describe "Votes" do
"Share it!"
end
+ expect(page).to have_content "Investment supported successfully"
+
visit budget_investments_path(budget, heading_id: san_francisco.id)
within("#budget_investment_#{san_francisco_investment.id}") do
diff --git a/spec/system/management/budget_investments_spec.rb b/spec/system/management/budget_investments_spec.rb
index eafb51d94..b814066e8 100644
--- a/spec/system/management/budget_investments_spec.rb
+++ b/spec/system/management/budget_investments_spec.rb
@@ -329,9 +329,60 @@ describe "Budget Investments" do
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 "Investment supported successfully"
expect(page).to have_content "CONSUL\nMANAGEMENT"
end
+ scenario "Remove support on behalf of someone else in index view" do
+ create(:budget_investment, heading: heading)
+
+ login_managed_user(user)
+ login_as_manager(manager)
+
+ visit management_budget_investments_path(budget)
+ click_button "Support"
+
+ expect(page).to have_content "1 support"
+ expect(page).to have_content "You have already supported this investment project. Share it!"
+ expect(page).not_to have_button "Support"
+
+ click_button "Remove your support"
+
+ expect(page).to have_content "No supports"
+ expect(page).to have_button "Support"
+ expect(page).not_to have_button "Remove your support"
+ end
+
+ scenario "Remove support on behalf of someone else in show view" do
+ create(:budget_investment, heading: heading, title: "Don't support me!")
+
+ login_managed_user(user)
+ login_as_manager(manager)
+
+ visit management_budget_investments_path(budget)
+ click_link "Don't support me!"
+
+ expect(page).to have_css "h1", exact_text: "Don't support me!"
+
+ click_button "Support"
+
+ expect(page).to have_content "1 support"
+ expect(page).to have_content "You have already supported this investment project. Share it!"
+ expect(page).not_to have_button "Support"
+
+ click_button "Remove your support"
+
+ expect(page).to have_content "No supports"
+ expect(page).to have_button "Support"
+ expect(page).not_to have_button "Remove your support"
+
+ refresh
+
+ expect(page).to have_content "No supports"
+ expect(page).to have_button "Support"
+ expect(page).not_to have_button "Remove your support"
+ end
+
scenario "Should not allow unverified users to vote proposals" do
login_managed_user(create(:user))
create(:budget_investment, budget: budget)