From 5a529e5eb7d93118c8514c3b8f1dc720d03be990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 27 Mar 2019 14:20:20 +0100 Subject: [PATCH 01/43] Use investments per page instead of Kaminari's This is the actual number of investments per page in the index action. Also note one test was generating 100 extra records, which made the test take more than 40 seconds (on my machine). --- spec/features/budgets/investments_spec.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 26cb0350a..9815cdcaa 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -583,10 +583,10 @@ feature "Budget Investments" do context "Orders" do before { budget.update(phase: "selecting") } + let(:per_page) { Budgets::InvestmentsController::PER_PAGE } scenario "Default order is random" do - per_page = Kaminari.config.default_per_page - (per_page + 100).times { create(:budget_investment) } + (per_page + 2).times { create(:budget_investment) } visit budget_investments_path(budget, heading_id: heading.id) order = all(".budget-investment h3").collect {|i| i.text } @@ -598,7 +598,6 @@ feature "Budget Investments" do end scenario "Random order after another order" do - per_page = Kaminari.config.default_per_page (per_page + 2).times { create(:budget_investment) } visit budget_investments_path(budget, heading_id: heading.id) @@ -614,7 +613,6 @@ feature "Budget Investments" do end scenario "Random order maintained with pagination" do - per_page = Kaminari.config.default_per_page (per_page + 2).times { create(:budget_investment, heading: heading) } visit budget_investments_path(budget, heading_id: heading.id) @@ -632,7 +630,7 @@ feature "Budget Investments" do end scenario "Random order maintained when going back from show" do - 10.times { |i| create(:budget_investment, heading: heading) } + per_page.times { |i| create(:budget_investment, heading: heading) } visit budget_investments_path(budget, heading_id: heading.id) @@ -646,8 +644,7 @@ feature "Budget Investments" do end scenario "Investments are not repeated with random order" do - 12.times { create(:budget_investment, heading: heading) } - # 12 instead of per_page + 2 because in each page there are 10 (in this case), not 25 + (per_page + 2).times { create(:budget_investment, heading: heading) } visit budget_investments_path(budget, order: "random") @@ -661,7 +658,6 @@ feature "Budget Investments" do common_values = first_page_investments & second_page_investments expect(common_values.length).to eq(0) - end scenario "Proposals are ordered by confidence_score" do @@ -686,7 +682,7 @@ feature "Budget Investments" do end scenario "Each user has a different and consistent random budget investment order" do - (Kaminari.config.default_per_page * 1.3).to_i.times { create(:budget_investment, heading: heading) } + (per_page * 1.3).to_i.times { create(:budget_investment, heading: heading) } in_browser(:one) do visit budget_investments_path(budget, heading: heading) @@ -722,7 +718,7 @@ feature "Budget Investments" do end scenario "Each user has a equal and consistent budget investment order when the random_seed is equal" do - (Kaminari.config.default_per_page * 1.3).to_i.times { create(:budget_investment, heading: heading) } + (per_page * 1.3).to_i.times { create(:budget_investment, heading: heading) } in_browser(:one) do visit budget_investments_path(budget, heading: heading, random_seed: "1") @@ -741,10 +737,10 @@ feature "Budget Investments" do voter = create(:user, :level_two) login_as(voter) - 10.times { create(:budget_investment, heading: heading) } + per_page.times { create(:budget_investment, heading: heading) } voted_investments = [] - 10.times do + per_page.times do investment = create(:budget_investment, heading: heading) create(:vote, votable: investment, voter: voter) voted_investments << investment @@ -762,7 +758,7 @@ feature "Budget Investments" do end scenario "Order is random if budget is finished" do - 10.times { create(:budget_investment) } + per_page.times { create(:budget_investment) } budget.update(phase: "finished") From f6da20da64822c10570b9d004f648088875e4331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 27 Mar 2019 14:27:41 +0100 Subject: [PATCH 02/43] Fix typos in investment order tests There was a typo: `new_order = eq(all(` instead of `new_order = all(`, which was causing the tests to pass. However, the final expectation should test that we keep the same order in the same session, and we were accidentally testing the opposite. We're also adding an extra check to verify there are investments on the page, since in some cases we were accessing pages with no investments, and so these tests were always passing. --- spec/features/budgets/investments_spec.rb | 41 +++++++++++++---------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 9815cdcaa..22c7bd698 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -586,30 +586,34 @@ feature "Budget Investments" do let(:per_page) { Budgets::InvestmentsController::PER_PAGE } scenario "Default order is random" do - (per_page + 2).times { create(:budget_investment) } + (per_page + 2).times { create(:budget_investment, heading: heading) } visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").collect {|i| i.text } + + within(".submenu .is-active") { expect(page).to have_content "random" } + order = all(".budget-investment h3").collect { |i| i.text } + expect(order).not_to be_empty visit budget_investments_path(budget, heading_id: heading.id) - new_order = eq(all(".budget-investment h3").collect {|i| i.text }) + new_order = all(".budget-investment h3").collect { |i| i.text } - expect(order).not_to eq(new_order) + expect(order).to eq(new_order) end scenario "Random order after another order" do - (per_page + 2).times { create(:budget_investment) } + (per_page + 2).times { create(:budget_investment, heading: heading) } visit budget_investments_path(budget, heading_id: heading.id) + order = all(".budget-investment h3").collect { |i| i.text } + expect(order).not_to be_empty + click_link "highest rated" click_link "random" - order = all(".budget-investment h3").collect {|i| i.text } - visit budget_investments_path(budget, heading_id: heading.id) - new_order = eq(all(".budget-investment h3").collect {|i| i.text }) + new_order = all(".budget-investment h3").collect { |i| i.text } - expect(order).not_to eq(new_order) + expect(order).to eq(new_order) end scenario "Random order maintained with pagination" do @@ -617,7 +621,8 @@ feature "Budget Investments" do visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").collect {|i| i.text } + order = all(".budget-investment h3").collect { |i| i.text } + expect(order).not_to be_empty click_link "Next" expect(page).to have_content "You're on page 2" @@ -625,7 +630,7 @@ feature "Budget Investments" do click_link "Previous" expect(page).to have_content "You're on page 1" - new_order = all(".budget-investment h3").collect {|i| i.text } + new_order = all(".budget-investment h3").collect { |i| i.text } expect(order).to eq(new_order) end @@ -634,12 +639,13 @@ feature "Budget Investments" do visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").collect {|i| i.text } + order = all(".budget-investment h3").collect { |i| i.text } + expect(order).not_to be_empty click_link Budget::Investment.first.title click_link "Go back" - new_order = all(".budget-investment h3").collect {|i| i.text } + new_order = all(".budget-investment h3").collect { |i| i.text } expect(order).to eq(new_order) end @@ -758,17 +764,18 @@ feature "Budget Investments" do end scenario "Order is random if budget is finished" do - per_page.times { create(:budget_investment) } + per_page.times { create(:budget_investment, :winner, heading: heading) } budget.update(phase: "finished") visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").collect {|i| i.text } + order = all(".budget-investment h3").collect { |i| i.text } + expect(order).not_to be_empty visit budget_investments_path(budget, heading_id: heading.id) - new_order = eq(all(".budget-investment h3").collect {|i| i.text }) + new_order = all(".budget-investment h3").collect { |i| i.text } - expect(order).not_to eq(new_order) + expect(order).to eq(new_order) end scenario "Order always is random for unfeasible and unselected investments" do From cc4eed3500a18eb1bc5a198e4b5904ce6a04ab16 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 8 Feb 2017 12:21:28 +0100 Subject: [PATCH 03/43] fixes specs --- .../officing/residence_controller.rb | 6 +-- app/views/officing/residence/new.html.erb | 39 ++++++++----------- config/locales/en/officing.yml | 1 - config/locales/es/officing.yml | 1 - spec/support/common_actions.rb | 5 +++ 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/app/controllers/officing/residence_controller.rb b/app/controllers/officing/residence_controller.rb index ef76162ea..da39f8428 100644 --- a/app/controllers/officing/residence_controller.rb +++ b/app/controllers/officing/residence_controller.rb @@ -1,7 +1,6 @@ class Officing::ResidenceController < Officing::BaseController - before_action :load_officer_assignment - before_action :validate_officer_assignment, only: :create + before_action :validate_officer_assignment def new @residence = Officing::Residence.new @@ -23,13 +22,14 @@ class Officing::ResidenceController < Officing::BaseController end def load_officer_assignment - @officer_assignments = current_user.poll_officer. + @officer_assignments ||= current_user.poll_officer. officer_assignments. voting_days. where(date: Date.current) end def validate_officer_assignment + load_officer_assignment if @officer_assignments.blank? redirect_to officing_root_path, notice: t("officing.residence.flash.not_allowed") end diff --git a/app/views/officing/residence/new.html.erb b/app/views/officing/residence/new.html.erb index a508fae52..c736b1f23 100644 --- a/app/views/officing/residence/new.html.erb +++ b/app/views/officing/residence/new.html.erb @@ -1,32 +1,25 @@

<%= t("officing.residence.new.title") %>

-<% if @officer_assignments.present? %> - diff --git a/app/views/budgets/investments/_sidebar.html.erb b/app/views/budgets/investments/_sidebar.html.erb index 866d4a9e7..4f18054f4 100644 --- a/app/views/budgets/investments/_sidebar.html.erb +++ b/app/views/budgets/investments/_sidebar.html.erb @@ -71,4 +71,8 @@ <% end %> <% end %> + + <%= link_to t("budgets.investments.header.check_ballot"), + budget_ballot_path(@budget), + class: "button hollow expanded" %> <% end %> diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index 107b6d747..3fd88cd48 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -10,7 +10,8 @@ en: voted_html: one: "You have voted one investment." other: "You have voted %{count} investments." - voted_info_html: "You can change your vote at any time until the close of this phase.
No need to spend all the money available." + voted_info_html: "Your ballot is confirmed!" + voted_info_2: "But you can change your vote at any time until this phase is closed." zero: You have not voted any investment project. reasons_for_not_balloting: not_logged_in: You must %{signin} or %{signup} to continue. @@ -90,7 +91,7 @@ en: voted_info_link: change your vote different_heading_assigned_html: "You have active votes in another heading: %{heading_link}" change_ballot: "If your change your mind you can remove your votes in %{check_ballot} and start again." - check_ballot_link: "check my ballot" + check_ballot_link: "check and confirm my ballot" zero: You have not voted any investment project in this group. verified_only: "To create a new budget investment %{verify}." verify_account: "verify your account" @@ -142,10 +143,10 @@ en: zero: No supports give_support: Support header: - check_ballot: Check my ballot + check_ballot: Check and confirm my ballot different_heading_assigned_html: "You have active votes in another heading: %{heading_link}" change_ballot: "If your change your mind you can remove your votes in %{check_ballot} and start again." - check_ballot_link: "check my ballot" + check_ballot_link: "check and confirm my ballot" price: "This heading has a budget of" progress_bar: assigned: "You have assigned: " diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 123b77f21..c827b2349 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -10,7 +10,8 @@ es: voted_html: one: "Has votado un proyecto." other: "Has votado %{count} proyectos." - voted_info_html: "Puedes cambiar tus votos en cualquier momento hasta el cierre de esta fase.
No hace falta que gastes todo el dinero disponible." + voted_info_html: "¡Tus votos están confirmados!" + voted_info_2: "Pero puedes cambiarlos en cualquier momento hasta el cierre de esta fase." zero: Todavía no has votado ningún proyecto de gasto. reasons_for_not_balloting: not_logged_in: Necesitas %{signin} o %{signup} para continuar. @@ -90,7 +91,7 @@ es: voted_info_link: cambiar tus votos different_heading_assigned_html: "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 mis votos" + check_ballot_link: "revisar y confirmar mis votos" zero: Todavía no has votado ningún proyecto de gasto en este ámbito del presupuesto. verified_only: "Para crear un nuevo proyecto de gasto %{verify}." verify_account: "verifica tu cuenta" @@ -142,10 +143,10 @@ es: other: "%{count} apoyos" give_support: Apoyar header: - check_ballot: Revisar mis votos + check_ballot: Revisar y confirmar mis votos different_heading_assigned_html: "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 mis votos" + check_ballot_link: "revisar y confirmar mis votos" price: "Esta partida tiene un presupuesto de" progress_bar: assigned: "Has asignado: " diff --git a/spec/features/budgets/ballots_spec.rb b/spec/features/budgets/ballots_spec.rb index 4398ab07f..639c4e75a 100644 --- a/spec/features/budgets/ballots_spec.rb +++ b/spec/features/budgets/ballots_spec.rb @@ -117,6 +117,7 @@ feature "Ballots" do within("#sidebar") do expect(page).to have_content investment1.title expect(page).to have_content "€10,000" + expect(page).to have_link("Check and confirm my ballot") end add_to_ballot(investment2) @@ -127,6 +128,7 @@ feature "Ballots" do within("#sidebar") do expect(page).to have_content investment2.title expect(page).to have_content "€20,000" + expect(page).to have_link("Check and confirm my ballot") end end @@ -146,6 +148,7 @@ feature "Ballots" do within("#sidebar") do expect(page).to have_content investment.title expect(page).to have_content "€10,000" + expect(page).to have_link("Check and confirm my ballot") end within("#budget_investment_#{investment.id}") do @@ -158,6 +161,7 @@ feature "Ballots" do within("#sidebar") do expect(page).not_to have_content investment.title expect(page).not_to have_content "€10,000" + expect(page).to have_link("Check and confirm my ballot") end end @@ -454,7 +458,9 @@ feature "Ballots" do visit budget_investments_path(budget, heading_id: new_york.id) add_to_ballot(investment) - click_link "Check my ballot" + within(".budget-heading") do + click_link "Check and confirm my ballot" + end expect(page).to have_content("You have voted one investment") diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 26cb0350a..4b04a5864 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -930,10 +930,12 @@ feature "Budget Investments" do visit budget_investments_path(budget, heading_id: heading.id) - expect(page).not_to have_link("Check my ballot") + expect(page).not_to have_link("Check and confirm my ballot") expect(page).not_to have_css("#progress_bar") + within("#sidebar") do expect(page).not_to have_content("My ballot") + expect(page).not_to have_link("Check and confirm my ballot") end end @@ -1564,7 +1566,8 @@ feature "Budget Investments" do visit budget_ballot_path(budget) - expect(page).to have_content "You can change your vote at any time until the close of this phase" + expect(page).to have_content "But you can change your vote at any time "\ + "until this phase is closed." within("#budget_group_#{global_group.id}") do expect(page).to have_content sp1.title @@ -1627,10 +1630,12 @@ feature "Budget Investments" do visit budget_investments_path(budget, heading_id: heading.id) - expect(page).to have_link("Check my ballot") + expect(page).to have_link("Check and confirm my ballot") expect(page).to have_css("#progress_bar") + within("#sidebar") do expect(page).to have_content("My ballot") + expect(page).to have_link("Check and confirm my ballot") end end From 5822d250da021068fca610062f423f1db3ad514e Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Sun, 31 Mar 2019 18:19:17 +0200 Subject: [PATCH 38/43] Use 3 Travis nodes for running the test suite --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0aa683c04..f9222fdb3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,11 @@ env: global: - KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true - KNAPSACK_PRO_LOG_LEVEL=info - - KNAPSACK_PRO_CI_NODE_TOTAL=2 + - KNAPSACK_PRO_CI_NODE_TOTAL=3 matrix: - KNAPSACK_PRO_CI_NODE_INDEX=0 - KNAPSACK_PRO_CI_NODE_INDEX=1 + - KNAPSACK_PRO_CI_NODE_INDEX=2 notifications: slack: secure: 18E9SU0SR/9knRvCMYwVqFCqVTBT6qJtZQ/gadpheqUPPlcLoQfnlIzJkLIYqkE0sn1nkBE5Bt2I90FU53p0NkrTEmSGlQXcN1vEXM8EXMaoVf3NBsIJeleMwt9VTojzo81EgIi6x7q3fDiFORJ4rqOGd9XkeLn5yrAtIkdaenVs0bhS5s24FP76hKqO37IFLG2v3EEqxg5k31oW6yhyP35Mxns+AGbfaZbxEy4XbCoU65KFuYhBsVZ/y1evOl/wcre2fCAoT2uKeqUWGEcDzH7oSCz7vfk7iO9BZnO++v7oj8mr/nrZL1KMFt77eqtdT51XQoJcchgJC/R9km5hRGkQqFCHhqPcBxo5c3p+jauL0kLaqTggeLDv2FQ2huJ8FSJ4ADac+n3g7wT7BX7HJlCvK0nbooY1JtBlk7+6/pw6ksSFIOo0FHg5gXN9IlG1tQQuENzzsXULNc6s4nPeT+n78uOp1b0N/Gn06moEBaKgXqqx1yV1XeJ02X8n3uDZxPuX3n2bJ4DMIrBjeWApxHAgyOraOzQHNQgJoj4tHlWutF33ApV2tcIMefIzvjM4tIYwIkpfGgohGaTf8eU5X9pqiMgwlDpJHVBsSvpk/Z/Nj7evYznjBiDYqOcXoztsqHrS0C91MaT+eExDfd9HDmThsE07RT7zcP9aElFZA/k= From e0d60fc7c7fecaf13aefe40a7972d306d01136ef Mon Sep 17 00:00:00 2001 From: decabeza Date: Mon, 1 Apr 2019 18:21:29 +0200 Subject: [PATCH 39/43] Update readme file --- README.md | 18 ++++++++++++++---- README_ES.md | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9cb539e31..afefb81df 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ + + ![CONSUL logo](https://raw.githubusercontent.com/consul/consul/master/public/consul_logo.png) # CONSUL @@ -19,9 +25,13 @@ Citizen Participation and Open Government Application This is the opensource code repository of the eParticipation website CONSUL, originally developed for the Madrid City government eParticipation website -## Current state +## Documentation -Development started on [2015 July 15th](https://github.com/consul/consul/commit/8db36308379accd44b5de4f680a54c41a0cc6fc6). Code was deployed to production on 2015 september 7th to [decide.madrid.es](https://decide.madrid.es). Since then new features are added often. You can take a look at the current features at the [project's website](http://consulproject.org/) and future features at the [Roadmap](https://github.com/consul/consul/projects/6) and [open issues list](https://github.com/consul/consul/issues). +Check the ongoing documentation at [https://docs.consulproject.org](https://docs.consulproject.org) to learn more about how to start your own CONSUL fork, install it, customize it and learn to use it from an administrator/maintainer perspective. + +## CONSUL Project main website + +You can access the main website of the project at [http://consulproject.org](http://consulproject.org) where you can find documentation about the use of the platform, videos, and links to the community space. ## Configuration for development and test environments @@ -69,9 +79,9 @@ But for some actions like voting, you will need a verified user, the seeds file See [installer](https://github.com/consul/installer) -## Documentation +## Current state -Check the ongoing documentation at [https://consul_docs.gitbooks.io/docs/content/](https://consul_docs.gitbooks.io/docs/content/) to learn more about how to start your own CONSUL fork, install it, customize it and learn to use it from an administrator/maintainer perspective. You can contribute to it at [https://github.com/consul/docs](https://github.com/consul/docs) +Development started on [2015 July 15th](https://github.com/consul/consul/commit/8db36308379accd44b5de4f680a54c41a0cc6fc6). Code was deployed to production on 2015 september 7th to [decide.madrid.es](https://decide.madrid.es). Since then new features are added often. You can take a look at the current features at the [project's website](http://consulproject.org/) and future features at the [Roadmap](https://github.com/consul/consul/projects/6) and [open issues list](https://github.com/consul/consul/issues). ## License diff --git a/README_ES.md b/README_ES.md index ee5f6d16b..7eceeb72d 100644 --- a/README_ES.md +++ b/README_ES.md @@ -1,3 +1,9 @@ + + ![Logotipo de CONSUL](https://raw.githubusercontent.com/consul/consul/master/public/consul_logo.png) # CONSUL @@ -18,9 +24,13 @@ Aplicación de Participación Ciudadana y Gobierno Abierto Este es el repositorio de código abierto de la Aplicación de Participación Ciudadana CONSUL, creada originariamente por el Ayuntamiento de Madrid. -## Estado del proyecto +## Documentación -El desarrollo de esta aplicación comenzó el [15 de Julio de 2015](https://github.com/consul/consul/commit/8db36308379accd44b5de4f680a54c41a0cc6fc6) y el código fue puesto en producción el día 7 de Septiembre de 2015 en [decide.madrid.es](https://decide.madrid.es). Desde entonces se le añaden mejoras y funcionalidades constantemente. Las funcionalidades actuales se pueden consultar en la [la página del projecto](http://consulproject.org/es) y las futuras funcionalidades en el [Roadmap](https://github.com/consul/consul/projects/6) y [el listado de issues](https://github.com/consul/consul/issues). +Por favor visita la documentación que está siendo completada en [https://docs.consulproject.org](https://docs.consulproject.org) para conocer más sobre este proyecto, cómo comenzar tu propio fork, instalarlo, personalizarlo y usarlo como administrador/mantenedor. + +## Web CONSUL Project + +Puedes acceder a la página principal del proyecto en [http://consulproject.org](http://consulproject.org) donde puedes encontrar documentación sobre el uso de la plataforma, videos y enlaces al espacio de la comunidad. ## Configuración para desarrollo y tests @@ -64,9 +74,9 @@ Pero para ciertas acciones, como apoyar, necesitarás un usuario verificado, el **user:** verified@consul.dev **pass:** 12345678 -## Documentación +## Estado del proyecto -Por favor visita la documentación que está siendo completada en [https://consul_docs.gitbooks.io/docs/content/](https://consul_docs.gitbooks.io/docs/content/) para conocer más sobre este proyecto, como comenzar tu propio fork, instalarlo, customizarlo y usarlo como administrador/mantenedor. Puedes colaborar en ella en [https://github.com/consul/docs](https://github.com/consul/docs) +El desarrollo de esta aplicación comenzó el [15 de Julio de 2015](https://github.com/consul/consul/commit/8db36308379accd44b5de4f680a54c41a0cc6fc6) y el código fue puesto en producción el día 7 de Septiembre de 2015 en [decide.madrid.es](https://decide.madrid.es). Desde entonces se le añaden mejoras y funcionalidades constantemente. Las funcionalidades actuales se pueden consultar en la [la página del projecto](http://consulproject.org/es) y las futuras funcionalidades en el [Roadmap](https://github.com/consul/consul/projects/6) y [el listado de issues](https://github.com/consul/consul/issues). ## Licencia From e3555ae2bb3bb4869cb97cd55bfd11dd54aa7e79 Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 2 Apr 2019 10:45:36 +0200 Subject: [PATCH 40/43] Update docs link on readme --- README.md | 2 +- README_ES.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index afefb81df..37adc5791 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ You can access the main website of the project at [http://consulproject.org](htt ## Configuration for development and test environments -**NOTE**: For more detailed instructions check the [docs](https://consul_docs.gitbooks.io/docs/) +**NOTE**: For more detailed instructions check the [docs](https://docs.consulproject.org) Prerequisites: install git, Ruby 2.3.2, `bundler` gem, Node.js and PostgreSQL (>=9.4). diff --git a/README_ES.md b/README_ES.md index 7eceeb72d..052b4ee85 100644 --- a/README_ES.md +++ b/README_ES.md @@ -34,7 +34,7 @@ Puedes acceder a la página principal del proyecto en [http://consulproject.org] ## Configuración para desarrollo y tests -**NOTA**: para unas instrucciones más detalladas consulta la [documentación](https://github.com/consul/docs/tree/master/es/getting_started/prerequisites) +**NOTA**: para unas instrucciones más detalladas consulta la [documentación](https://docs.consulproject.org) Prerequisitos: tener instalado git, Ruby 2.3.2, la gema `bundler`, Node.js y PostgreSQL (9.4 o superior). From 0a5057a0a88f5077a25bca9a736bf1bb80809428 Mon Sep 17 00:00:00 2001 From: lalo Date: Tue, 2 Apr 2019 19:46:16 +0200 Subject: [PATCH 41/43] Add max support advanced filter for admin budget investments --- .../admin_budget_investments_helper.rb | 8 ++++- app/models/budget/investment.rb | 2 ++ .../budget_investments/_search_form.html.erb | 11 ++++-- .../_select_investment.html.erb | 2 ++ config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + .../features/admin/budget_investments_spec.rb | 36 +++++++++++++++++++ 7 files changed, 58 insertions(+), 3 deletions(-) diff --git a/app/helpers/admin_budget_investments_helper.rb b/app/helpers/admin_budget_investments_helper.rb index 5c2dc479e..aa33961aa 100644 --- a/app/helpers/admin_budget_investments_helper.rb +++ b/app/helpers/admin_budget_investments_helper.rb @@ -1,7 +1,13 @@ module AdminBudgetInvestmentsHelper def advanced_menu_visibility - (params[:advanced_filters].empty? && params["min_total_supports"].blank?) ? "hide" : "" + if params[:advanced_filters].empty? && + params["min_total_supports"].blank? && + params["max_total_supports"].blank? + "hide" + else + "" + end end def init_advanced_menu diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index f2095c746..4dae6c3ac 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -118,6 +118,8 @@ class Budget results = results.where("cached_votes_up + physical_votes >= ?", params[:min_total_supports]) if params[:min_total_supports].present? + results = results.where("cached_votes_up + physical_votes <= ?", + params[:max_total_supports]) if params[:max_total_supports].present? results = results.where(group_id: params[:group_id]) if params[:group_id].present? results = results.by_tag(params[:tag_name]) if params[:tag_name].present? results = results.by_heading(params[:heading_id]) if params[:heading_id].present? diff --git a/app/views/admin/budget_investments/_search_form.html.erb b/app/views/admin/budget_investments/_search_form.html.erb index 94ae8fc0b..77e177b71 100644 --- a/app/views/admin/budget_investments/_search_form.html.erb +++ b/app/views/admin/budget_investments/_search_form.html.erb @@ -17,8 +17,15 @@ <%= t("admin.budget_investments.index.filters.#{option}") %> <% end %> -
- <%= text_field_tag :min_total_supports, params["min_total_supports"], placeholder: t("admin.budget_investments.index.filters.min_total_supports") %> +
+
+ <%= label_tag :min_total_supports, t("admin.budget_investments.index.filters.min_total_supports") %> + <%= text_field_tag :min_total_supports, params["min_total_supports"] %> +
+
+ <%= label_tag :max_total_supports, t("admin.budget_investments.index.filters.max_total_supports") %> + <%= text_field_tag :max_total_supports, params["max_total_supports"] %> +
diff --git a/app/views/admin/budget_investments/_select_investment.html.erb b/app/views/admin/budget_investments/_select_investment.html.erb index 12bb5c5c8..e04c15cac 100644 --- a/app/views/admin/budget_investments/_select_investment.html.erb +++ b/app/views/admin/budget_investments/_select_investment.html.erb @@ -54,6 +54,7 @@ filter: params[:filter], sort_by: params[:sort_by], min_total_supports: params[:min_total_supports], + max_total_supports: params[:max_total_supports], advanced_filters: params[:advanced_filters], page: params[:page]), method: :patch, @@ -67,6 +68,7 @@ filter: params[:filter], sort_by: params[:sort_by], min_total_supports: params[:min_total_supports], + max_total_supports: params[:max_total_supports], advanced_filters: params[:advanced_filters], page: params[:page]), method: :patch, diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 156702512..350297008 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -191,6 +191,7 @@ en: undecided: Undecided unfeasible: Unfeasible min_total_supports: Minimum supports + max_total_supports: Maximum supports winners: Winners one_filter_html: "Current applied filters: %{filter}" two_filters_html: "Current applied filters: %{filter}, %{advanced_filters}" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 456238bcc..321f75c9b 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -191,6 +191,7 @@ es: undecided: Sin decidir unfeasible: Inviables min_total_supports: Apoyos mínimos + max_total_supports: Apoyos máximos winners: Ganadores one_filter_html: "Filtros en uso: %{filter}" two_filters_html: "Filtros en uso: %{filter}, %{advanced_filters}" diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index ea3711364..48451e14f 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -439,6 +439,42 @@ feature "Admin budget investments" do expect(page).not_to have_link("Road 100 supports") end + scenario "Filtering by maximum number of votes", :js do + group_1 = create(:budget_group, budget: budget) + group_2 = create(:budget_group, budget: budget) + parks = create(:budget_heading, group: group_1) + roads = create(:budget_heading, group: group_2) + streets = create(:budget_heading, group: group_2) + + create(:budget_investment, heading: parks, cached_votes_up: 40, title: "Park 40 supports") + create(:budget_investment, heading: parks, cached_votes_up: 99, title: "Park 99 supports") + create(:budget_investment, heading: roads, cached_votes_up: 100, title: "Road 100 supports") + create(:budget_investment, heading: roads, cached_votes_up: 199, title: "Road 199 supports") + create(:budget_investment, heading: streets, cached_votes_up: 200, title: "St. 200 supports") + create(:budget_investment, heading: streets, cached_votes_up: 300, title: "St. 300 supports") + + visit admin_budget_budget_investments_path(budget) + + expect(page).to have_link("Park 40 supports") + expect(page).to have_link("Park 99 supports") + expect(page).to have_link("Road 100 supports") + expect(page).to have_link("Road 199 supports") + expect(page).to have_link("St. 200 supports") + expect(page).to have_link("St. 300 supports") + + click_link "Advanced filters" + fill_in "max_total_supports", with: 180 + click_button "Filter" + + expect(page).to have_content("There are 3 investments") + expect(page).not_to have_link("Road 199 supports") + expect(page).not_to have_link("St. 200 supports") + expect(page).not_to have_link("St. 300 supports") + expect(page).to have_link("Park 40 supports") + expect(page).to have_link("Park 99 supports") + expect(page).to have_link("Road 100 supports") + end + scenario "Combination of checkbox with text search", :js do user = create(:user, username: "Admin 1") administrator = create(:administrator, user: user) From 9edaf44b9c8cb761bd3a2ef0652e827c25d30698 Mon Sep 17 00:00:00 2001 From: lalo Date: Wed, 3 Apr 2019 13:39:59 +0200 Subject: [PATCH 42/43] Add new admin budget investments advanced filter for max supports --- app/models/budget/investment/exporter.rb | 6 +++++- app/views/admin/budget_investments/_investments.html.erb | 1 + .../admin/budget_investments/_select_investment.html.erb | 6 ++++-- config/locales/en/admin.yml | 3 ++- config/locales/es/admin.yml | 3 ++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/models/budget/investment/exporter.rb b/app/models/budget/investment/exporter.rb index c7e4ce461..be3c5f2ac 100644 --- a/app/models/budget/investment/exporter.rb +++ b/app/models/budget/investment/exporter.rb @@ -58,6 +58,10 @@ class Budget::Investment::Exporter def price(investment) price_string = "admin.budget_investments.index.feasibility.#{investment.feasibility}" - I18n.t(price_string, price: investment.formatted_price) + if investment.feasible? + "#{I18n.t(price_string)} (#{investment.formatted_price})" + else + I18n.t(price_string) + end end end diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index 1bae41ee1..d17d85ea1 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -36,6 +36,7 @@ <%= t("admin.budget_investments.index.list.geozone") %> <%= t("admin.budget_investments.index.list.feasibility") %> + <%= t("admin.budget_investments.index.list.price") %> <%= t("admin.budget_investments.index.list.valuation_finished") %> <%= t("admin.budget_investments.index.list.visible_to_valuators") %> <%= t("admin.budget_investments.index.list.selected") %> diff --git a/app/views/admin/budget_investments/_select_investment.html.erb b/app/views/admin/budget_investments/_select_investment.html.erb index 12bb5c5c8..9ef8825cb 100644 --- a/app/views/admin/budget_investments/_select_investment.html.erb +++ b/app/views/admin/budget_investments/_select_investment.html.erb @@ -31,8 +31,10 @@ <%= investment.heading.name %> - <%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", - price: investment.formatted_price) %> + <%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}") %> + + + <%= investment.formatted_price %> <%= investment.valuation_finished? ? t("shared.yes"): t("shared.no") %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 5b541991d..895de4853 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -206,7 +206,7 @@ en: no_valuators_assigned: No valuators assigned no_valuation_groups: No valuation groups assigned feasibility: - feasible: "Feasible (%{price})" + feasible: "Feasible" unfeasible: "Unfeasible" undecided: "Undecided" selected: "Selected" @@ -225,6 +225,7 @@ en: visible_to_valuators: Show to valuators author_username: Author username incompatible: Incompatible + price: Price cannot_calculate_winners: The budget has to stay on phase "Balloting projects", "Reviewing Ballots" or "Finished budget" in order to calculate winners projects see_results: "See results" show: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index a02030100..429dd6717 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -206,7 +206,7 @@ es: no_valuators_assigned: Sin evaluador no_valuation_groups: Sin grupos evaluadores feasibility: - feasible: "Viable (%{price})" + feasible: "Viable" unfeasible: "Inviable" undecided: "Sin decidir" selected: "Seleccionado" @@ -225,6 +225,7 @@ es: visible_to_valuators: Mostrar a evaluadores author_username: Usuario autor incompatible: Incompatible + price: Precio cannot_calculate_winners: El presupuesto debe estar en las fases "Votación final", "Votación finalizada" o "Resultados" para poder calcular las propuestas ganadoras see_results: "Ver resultados" show: From 237a03552fcca73de65b95aab8c18c19db2f1ab9 Mon Sep 17 00:00:00 2001 From: lalo Date: Wed, 3 Apr 2019 22:27:48 +0200 Subject: [PATCH 43/43] Move admin budget investments tabs filters to advanced filters component --- app/assets/stylesheets/admin.scss | 5 + .../admin/budget_investments_controller.rb | 6 +- app/controllers/admin/budgets_controller.rb | 4 +- app/models/budget/investment.rb | 11 +- .../budget_investments/_investments.html.erb | 2 +- .../budget_investments/_search_form.html.erb | 7 +- spec/factories/budgets.rb | 16 +- .../features/admin/budget_investments_spec.rb | 240 +++++++++++++++--- spec/features/admin/budgets_spec.rb | 4 +- spec/models/budget/investment_spec.rb | 87 +++++++ 10 files changed, 331 insertions(+), 51 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 17ea18b9d..9c95f400f 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -1205,6 +1205,11 @@ table { .filter { display: inline-block; margin: 0 $line-height / 2; + + label { + font-weight: normal; + margin: 0; + } } .button { diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index 1a213c2f2..a451d67a5 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -4,10 +4,8 @@ class Admin::BudgetInvestmentsController < Admin::BaseController feature_flag :budgets - has_orders %w{oldest}, only: [:show, :edit] - has_filters(%w{all without_admin without_valuator under_valuation - valuation_finished winners}, - only: [:index, :toggle_selection]) + has_orders %w[oldest], only: [:show, :edit] + has_filters %w[all], only: [:index, :toggle_selection] before_action :load_budget before_action :load_investment, only: [:show, :edit, :update, :toggle_selection] diff --git a/app/controllers/admin/budgets_controller.rb b/app/controllers/admin/budgets_controller.rb index 252e48134..955da3f1d 100644 --- a/app/controllers/admin/budgets_controller.rb +++ b/app/controllers/admin/budgets_controller.rb @@ -23,7 +23,9 @@ class Admin::BudgetsController < Admin::BaseController def calculate_winners return unless @budget.balloting_process? @budget.headings.each { |heading| Budget::Result.new(@budget, heading).delay.calculate_winners } - redirect_to admin_budget_budget_investments_path(budget_id: @budget.id, filter: "winners"), + redirect_to admin_budget_budget_investments_path( + budget_id: @budget.id, + advanced_filters: ["winners"]), notice: I18n.t("admin.budgets.winners.calculated") end diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 4dae6c3ac..b033d7404 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -117,7 +117,7 @@ class Budget results = Investment.by_budget(budget) results = results.where("cached_votes_up + physical_votes >= ?", - params[:min_total_supports]) if params[:min_total_supports].present? + params[:min_total_supports]) if params[:min_total_supports].present? results = results.where("cached_votes_up + physical_votes <= ?", params[:max_total_supports]) if params[:max_total_supports].present? results = results.where(group_id: params[:group_id]) if params[:group_id].present? @@ -134,12 +134,19 @@ class Budget end def self.advanced_filters(params, results) + results = results.without_admin if params[:advanced_filters].include?("without_admin") + results = results.without_valuator if params[:advanced_filters].include?("without_valuator") + results = results.under_valuation if params[:advanced_filters].include?("under_valuation") + results = results.valuation_finished if params[:advanced_filters].include?("valuation_finished") + results = results.winners if params[:advanced_filters].include?("winners") + ids = [] ids += results.valuation_finished_feasible.pluck(:id) if params[:advanced_filters].include?("feasible") ids += results.where(selected: true).pluck(:id) if params[:advanced_filters].include?("selected") ids += results.undecided.pluck(:id) if params[:advanced_filters].include?("undecided") ids += results.unfeasible.pluck(:id) if params[:advanced_filters].include?("unfeasible") - results.where("budget_investments.id IN (?)", ids) + results = results.where("budget_investments.id IN (?)", ids) if ids.any? + results end def self.order_filter(params) diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index 2c697f53b..55603bbcd 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -2,7 +2,7 @@ admin_budget_budget_investments_path(csv_params), class: "float-right small clear" %> -<% if params[:filter] == "winners" %> +<% if params[:advanced_filters].include?("winners") %> <% if display_calculate_winners_button?(@budget) %> <%= link_to calculate_winner_button_text(@budget), calculate_winners_admin_budget_path(@budget), diff --git a/app/views/admin/budget_investments/_search_form.html.erb b/app/views/admin/budget_investments/_search_form.html.erb index 77e177b71..301845a8b 100644 --- a/app/views/admin/budget_investments/_search_form.html.erb +++ b/app/views/admin/budget_investments/_search_form.html.erb @@ -11,10 +11,11 @@
- <% ["feasible", "selected", "undecided", "unfeasible"].each do |option| %> + <% %w[feasible selected undecided unfeasible without_admin without_valuator under_valuation + valuation_finished winners].each do |filter| %>
- <%= check_box_tag "advanced_filters[]", option, params[:advanced_filters].index(option), id: "advanced_filters_#{option}" %> - <%= t("admin.budget_investments.index.filters.#{option}") %> + <%= check_box_tag "advanced_filters[]", filter, params[:advanced_filters].index(filter), id: "advanced_filters_#{filter}" %> + <%= label_tag "advanced_filters[#{filter}]", t("admin.budget_investments.index.filters.#{filter}") %>
<% end %>
diff --git a/spec/factories/budgets.rb b/spec/factories/budgets.rb index 0b9130825..b53bd8b56 100644 --- a/spec/factories/budgets.rb +++ b/spec/factories/budgets.rb @@ -150,13 +150,17 @@ FactoryBot.define do valuation_finished true end - trait :hidden do - hidden_at { Time.current } - end + trait :hidden do + hidden_at { Time.current } + end - trait :with_ignored_flag do - ignored_flag_at { Time.current } - end + trait :with_ignored_flag do + ignored_flag_at { Time.current } + end + + trait :with_administrator do + administrator + end trait :flagged do after :create do |investment| diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 48451e14f..bfc8e7881 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -251,12 +251,161 @@ feature "Admin budget investments" do expect(page).not_to have_link("Build a hospital") end + scenario "Filtering by without assigned admin", :js do + create(:budget_investment, + title: "Investment without admin", + budget: budget) + create(:budget_investment, + :with_administrator, + title: "Investment with admin", + budget: budget) + + visit admin_budget_budget_investments_path(budget_id: budget) + expect(page).to have_link("Investment without admin") + expect(page).to have_link("Investment with admin") + + click_link "Advanced filters" + check("Without assigned admin") + click_button "Filter" + + expect(page).to have_content("There is 1 investment") + expect(page).to have_link("Investment without admin") + expect(page).not_to have_link("Investment with admin") + + uncheck("Without assigned admin") + click_button "Filter" + + expect(page).to have_content("There are 2 investments") + expect(page).to have_link("Investment without admin") + expect(page).to have_link("Investment with admin") + end + + scenario "Filtering by without assigned valuator", :js do + user = create(:user) + valuator = create(:valuator, user: user) + create(:budget_investment, + title: "Investment without valuator", + budget: budget) + create(:budget_investment, + title: "Investment with valuator", + budget: budget, + valuators: [valuator]) + + visit admin_budget_budget_investments_path(budget_id: budget) + expect(page).to have_link("Investment without valuator") + expect(page).to have_link("Investment with valuator") + + click_link "Advanced filters" + check "Without assigned valuator" + click_button "Filter" + + expect(page).to have_content("There is 1 investment") + expect(page).to have_link("Investment without valuator") + expect(page).not_to have_link("Investment with valuator") + + uncheck "Without assigned valuator" + click_button "Filter" + + expect(page).to have_content("There are 2 investments") + expect(page).to have_link("Investment without valuator") + expect(page).to have_link("Investment with valuator") + end + + scenario "Filtering by under valuation", :js do + user = create(:user) + valuator = create(:valuator, user: user) + create(:budget_investment, + :with_administrator, + valuation_finished: false, + title: "Investment without valuation", + budget: budget, + valuators: [valuator]) + create(:budget_investment, + :with_administrator, + title: "Investment with valuation", + budget: budget) + + visit admin_budget_budget_investments_path(budget_id: budget) + expect(page).to have_link("Investment without valuation") + expect(page).to have_link("Investment with valuation") + + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" + + expect(page).to have_content("There is 1 investment") + expect(page).to have_link("Investment without valuation") + expect(page).not_to have_link("Investment with valuation") + + uncheck "Under valuation" + click_button "Filter" + + expect(page).to have_content("There are 2 investments") + expect(page).to have_link("Investment without valuation") + expect(page).to have_link("Investment with valuation") + end + + scenario "Filtering by valuation finished", :js do + create(:budget_investment, + title: "Investment valuation open", + budget: budget) + create(:budget_investment, + :finished, + title: "Investment valuation finished", + budget: budget) + + visit admin_budget_budget_investments_path(budget_id: budget) + expect(page).to have_link("Investment valuation open") + expect(page).to have_link("Investment valuation finished") + + click_link "Advanced filters" + check "Valuation finished" + click_button "Filter" + + expect(page).to have_content("There is 1 investment") + expect(page).not_to have_link("Investment valuation open") + expect(page).to have_link("Investment valuation finished") + + uncheck "Valuation finished" + click_button "Filter" + + expect(page).to have_content("There are 2 investments") + expect(page).to have_link("Investment valuation open") + expect(page).to have_link("Investment valuation finished") + end + + scenario "Filtering by winners", :js do + create(:budget_investment, + :winner, + valuation_finished: true, + title: "Investment winner", + budget: budget) + create(:budget_investment, + title: "Investment without winner", + budget: budget) + + visit admin_budget_budget_investments_path(budget_id: budget) + expect(page).to have_link("Investment winner") + expect(page).to have_link("Investment without winner") + + click_link "Advanced filters" + check "Winners" + click_button "Filter" + + expect(page).to have_content("There is 1 investment") + expect(page).to have_link("Investment winner") + expect(page).not_to have_link("Investment without winner") + + uncheck "Winners" + click_button "Filter" + + expect(page).to have_content("There are 2 investments") + expect(page).to have_link("Investment winner") + expect(page).to have_link("Investment without winner") + end + scenario "Current filter is properly highlighted" do - filters_links = { "all" => "All", - "without_admin" => "Without assigned admin", - "without_valuator" => "Without assigned valuator", - "under_valuation" => "Under valuation", - "valuation_finished" => "Valuation finished" } + filters_links = { "all" => "All" } visit admin_budget_budget_investments_path(budget_id: budget.id) @@ -288,13 +437,15 @@ feature "Admin budget investments" do expect(page).to have_content("Evaluating...") expect(page).to have_content("With group") - visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "without_admin") + visit admin_budget_budget_investments_path(budget_id: budget.id, + advanced_filters: ["without_admin"]) expect(page).to have_content("Evaluating...") expect(page).to have_content("With group") expect(page).not_to have_content("Assigned idea") - visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "without_valuator") + visit admin_budget_budget_investments_path(budget_id: budget.id, + advanced_filters: ["without_valuator"]) expect(page).to have_content("Assigned idea") expect(page).not_to have_content("Evaluating...") @@ -309,17 +460,20 @@ feature "Admin budget investments" do valuating.valuators.push(create(:valuator)) valuated.valuators.push(create(:valuator)) - visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "under_valuation") + query_params = {budget_id: budget.id, advanced_filters: ["under_valuation"]} + + visit admin_budget_budget_investments_path(query_params) expect(page).to have_content("Ongoing valuation") expect(page).not_to have_content("Old idea") - visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "valuation_finished") + visit admin_budget_budget_investments_path(budget_id: budget.id, + advanced_filters: ["valuation_finished"]) expect(page).not_to have_content("Ongoing valuation") expect(page).to have_content("Old idea") - visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "all") + visit admin_budget_budget_investments_path(budget_id: budget.id, advanced_filters: ["filter"]) expect(page).to have_content("Ongoing valuation") expect(page).to have_content("Old idea") end @@ -380,7 +534,10 @@ feature "Admin budget investments" do budget.update(phase: "reviewing_ballots") visit admin_budget_budget_investments_path(budget) - click_link "Winners" + + click_link "Advanced filters" + check "Winners" + click_button "Filter" expect(page).to have_link "Calculate Winner Investments" @@ -391,7 +548,9 @@ feature "Admin budget investments" do budget.update(phase: "accepting") visit admin_budget_budget_investments_path(budget) - click_link "Winners" + + check "Winners" + click_button "Filter" expect(page).not_to have_link "Calculate Winner Investments" expect(page).to have_content 'The budget has to stay on phase "Balloting projects", '\ @@ -530,7 +689,7 @@ feature "Admin budget investments" do click_link "Advanced filters" - page.check("advanced_filters_feasible") + check("Feasible") click_button "Filter" expect(page).to have_css(".budget_investment", count: 2) @@ -585,7 +744,7 @@ feature "Admin budget investments" do click_link "Advanced filters" - within("#advanced_filters") { check("advanced_filters_feasible") } + within("#advanced_filters") { check("Feasible") } click_button("Filter") expect(page).to have_css(".budget_investment", count: 2) @@ -1156,16 +1315,17 @@ feature "Admin budget investments" do scenario "Filtering by valuation and selection", :js do visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Valuation finished" } + click_link "Advanced filters" + check "Valuation finished" + click_button "Filter" + expect(page).not_to have_content(unfeasible_bi.title) expect(page).not_to have_content(feasible_bi.title) expect(page).to have_content(feasible_vf_bi.title) expect(page).to have_content(selected_bi.title) expect(page).to have_content(winner_bi.title) - click_link "Advanced filters" - - within("#advanced_filters") { check("advanced_filters_feasible") } + within("#advanced_filters") { check("Feasible") } click_button("Filter") expect(page).not_to have_content(unfeasible_bi.title) @@ -1175,8 +1335,8 @@ feature "Admin budget investments" do expect(page).to have_content(winner_bi.title) within("#advanced_filters") do - check("advanced_filters_selected") - uncheck("advanced_filters_feasible") + check("Selected") + uncheck("Feasible") end click_button("Filter") @@ -1187,7 +1347,9 @@ feature "Admin budget investments" do expect(page).to have_content(selected_bi.title) expect(page).to have_content(winner_bi.title) - within("#filter-subnav") { click_link "Winners" } + check "Winners" + click_button "Filter" + expect(page).not_to have_content(unfeasible_bi.title) expect(page).not_to have_content(feasible_bi.title) expect(page).not_to have_content(feasible_vf_bi.title) @@ -1200,7 +1362,7 @@ feature "Admin budget investments" do click_link "Advanced filters" - within("#advanced_filters") { check("advanced_filters_undecided") } + within("#advanced_filters") { check("Undecided") } click_button("Filter") expect(page).to have_content(undecided_bi.title) @@ -1210,7 +1372,7 @@ feature "Admin budget investments" do expect(page).not_to have_content(unfeasible_bi.title) expect(page).not_to have_content(feasible_vf_bi.title) - within("#advanced_filters") { check("advanced_filters_unfeasible") } + within("#advanced_filters") { check("Unfeasible") } click_button("Filter") expect(page).to have_content(undecided_bi.title) @@ -1255,7 +1417,7 @@ feature "Admin budget investments" do click_link "Advanced filters" - within("#advanced_filters") { check("advanced_filters_selected") } + within("#advanced_filters") { check("Selected") } click_button("Filter") within("#budget_investment_#{feasible_vf_bi.id}") do @@ -1268,7 +1430,7 @@ feature "Admin budget investments" do visit admin_budget_budget_investments_path(budget) click_link "Advanced filters" - within("#advanced_filters") { check("advanced_filters_selected") } + within("#advanced_filters") { check("Selected") } click_button("Filter") expect(page).to have_content("There are 2 investments") @@ -1325,15 +1487,18 @@ feature "Admin budget investments" do investment2.update(administrator: admin) visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Under valuation" } - expect(page).not_to have_link("Under valuation") + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" within("#budget_investment_#{investment1.id}") do check "budget_investment_visible_to_valuators" end visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Under valuation" } + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" within("#budget_investment_#{investment1.id}") do expect(find("#budget_investment_visible_to_valuators")).to be_checked @@ -1371,15 +1536,20 @@ feature "Admin budget investments" do investment2.update(administrator: admin, visible_to_valuators: true) visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Under valuation" } - expect(page).not_to have_link("Under valuation") + + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" within("#budget_investment_#{investment1.id}") do uncheck "budget_investment_visible_to_valuators" end visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Under valuation" } + + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" within("#budget_investment_#{investment1.id}") do expect(find("#budget_investment_visible_to_valuators")).not_to be_checked @@ -1400,7 +1570,9 @@ feature "Admin budget investments" do expect(page).to have_css("#budget_investment_visible_to_valuators") - within("#filter-subnav") { click_link "Under valuation" } + click_link "Advanced filters" + check "Under valuation" + click_button "Filter" within("#budget_investment_#{investment1.id}") do valuating_checkbox = find("#budget_investment_visible_to_valuators") @@ -1478,7 +1650,9 @@ feature "Admin budget investments" do create(:budget_investment, :finished, budget: budget, title: "Finished Investment") visit admin_budget_budget_investments_path(budget) - within("#filter-subnav") { click_link "Valuation finished" } + click_link "Advanced filters" + check "Valuation finished" + click_button "Filter" click_link "Download current selection" diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb index e24c344b2..38347b56e 100644 --- a/spec/features/admin/budgets_spec.rb +++ b/spec/features/admin/budgets_spec.rb @@ -281,7 +281,9 @@ feature "Admin budgets" do expect(page).not_to have_content "Calculate Winner Investments" visit admin_budget_budget_investments_path(budget) - click_link "Winners" + click_link "Advanced filters" + check "Winners" + click_button "Filter" expect(page).to have_content "Recalculate Winner Investments" expect(page).not_to have_content "Calculate Winner Investments" diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index 7c2b0a980..044dead99 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -1131,4 +1131,91 @@ describe Budget::Investment do end end + + describe "scoped_filter" do + let(:budget) { create(:budget, phase: "balloting") } + let(:investment) { create(:budget_investment, budget: budget) } + + describe "with without_admin filter" do + let(:params) { {advanced_filters: ["without_admin"], budget_id: budget.id} } + it "returns only investment without admin" do + create(:budget_investment, + :finished, + budget: budget) + create(:budget_investment, + :with_administrator, + budget: budget) + investment3 = create(:budget_investment, budget: budget) + expect(described_class.scoped_filter(params, "all")).to eq([investment3]) + expect(described_class.scoped_filter(params, "all").count).to eq(1) + end + end + + describe "with without_valuator filter" do + let(:params) { {advanced_filters: ["without_valuator"], budget_id: budget.id} } + it "returns only investment without valuator" do + create(:budget_investment, + :finished, + budget: budget) + investment2 = create(:budget_investment, + :with_administrator, + budget: budget) + investment3 = create(:budget_investment, + budget: budget) + expect(described_class.scoped_filter(params, "all")) + .to contain_exactly(investment2, investment3) + expect(described_class.scoped_filter(params, "all").count) + .to eq(2) + end + end + + describe "with under_valuation filter" do + let(:params) { {advanced_filters: ["under_valuation"], budget_id: budget.id} } + it "returns only investment under valuation" do + valuator1 = create(:valuator) + investment1 = create(:budget_investment, + :with_administrator, + valuation_finished: false, + budget: budget) + investment1.valuators << valuator1 + create(:budget_investment, :with_administrator, budget: budget) + create(:budget_investment, budget: budget) + + expect(described_class.scoped_filter(params, "all")).to eq([investment1]) + expect(described_class.scoped_filter(params, "all").count).to eq(1) + end + end + + describe "with valuation_finished filter" do + let(:params) { {advanced_filters: ["valuation_finished"], budget_id: budget.id} } + it "returns only investment with valuation finished" do + investment1 = create(:budget_investment, + :selected, + budget: budget) + create(:budget_investment, + :with_administrator, + budget: budget) + create(:budget_investment, + budget: budget) + expect(described_class.scoped_filter(params, "all")).to eq([investment1]) + expect(described_class.scoped_filter(params, "all").count).to eq(1) + end + end + + describe "with winners filter" do + let(:params) { {advanced_filters: ["winners"], budget_id: budget.id} } + it "returns only investment winners" do + investment1 = create(:budget_investment, + :winner, + valuation_finished: true, + budget: budget) + create(:budget_investment, + :with_administrator, + budget: budget) + create(:budget_investment, budget: budget) + expect(described_class.scoped_filter(params, "all")).to eq([investment1]) + expect(described_class.scoped_filter(params, "all").count).to eq(1) + end + end + end end