From b8cc10d218a94e914ca8096135bafa70438f9e9d Mon Sep 17 00:00:00 2001 From: iagirre Date: Tue, 13 Feb 2018 15:33:18 +0100 Subject: [PATCH 1/4] Fix conflics after rebase --- .../admin/budget_investments_controller.rb | 2 +- .../budget_investments_controller.rb | 2 +- app/models/budget/investment.rb | 1 + .../budget_investments/_investments.html.erb | 20 ++++- .../budget_investments/index.html.erb | 2 +- config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + db/dev_seeds.rb | 6 ++ ...sible_to_valuators_to_budget_investment.rb | 5 ++ db/schema.rb | 1 + spec/factories.rb | 4 + .../features/admin/budget_investments_spec.rb | 88 +++++++++++++++++++ .../valuation/budget_investments_spec.rb | 54 +++++++++--- spec/support/common_actions.rb | 6 ++ 14 files changed, 176 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20180116151008_add_visible_to_valuators_to_budget_investment.rb diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index bc4c8d49b..b2f06518c 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -96,7 +96,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController def budget_investment_params params.require(:budget_investment) .permit(:title, :description, :external_url, :heading_id, :administrator_id, :tag_list, - :valuation_tag_list, :incompatible, :selected, valuator_ids: [], + :valuation_tag_list, :incompatible, :visible_to_valuators, :selected, valuator_ids: [], valuator_group_ids: []) end diff --git a/app/controllers/valuation/budget_investments_controller.rb b/app/controllers/valuation/budget_investments_controller.rb index c4d19f66c..bf70d657b 100644 --- a/app/controllers/valuation/budget_investments_controller.rb +++ b/app/controllers/valuation/budget_investments_controller.rb @@ -17,7 +17,7 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController def index @heading_filters = heading_filters @investments = if current_user.valuator? && @budget.present? - @budget.investments.scoped_filter(params_for_current_valuator, @current_filter) + @budget.investments.visible_to_valuators.scoped_filter(params_for_current_valuator, @current_filter) .order(cached_votes_up: :desc) .page(params[:page]) else diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 594610b6c..2bb63f335 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -65,6 +65,7 @@ class Budget scope :under_valuation, -> { valuation_open.valuating.where("administrator_id IS NOT ?", nil) } scope :managed, -> { valuation_open.where(valuator_assignments_count: 0).where("administrator_id IS NOT ?", nil) } scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0 OR valuator_group_assignments_count > 0" ) } + scope :visible_to_valuators, -> { where(visible_to_valuators: true) } scope :valuation_finished, -> { where(valuation_finished: true) } scope :valuation_finished_feasible, -> { where(valuation_finished: true, feasibility: "feasible") } scope :feasible, -> { where(feasibility: "feasible") } diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index 9d52f78d6..d76294687 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -27,8 +27,13 @@ <%= t("admin.budget_investments.index.table_geozone") %> <%= t("admin.budget_investments.index.table_feasibility") %> <%= t("admin.budget_investments.index.table_valuation_finished") %> - <%= t("admin.budget_investments.index.table_selection") %> - <% if params[:filter] == "selected" %> + + <% if params[:filter] == "valuating" %> + <%= t("admin.budget_investments.index.table_evaluation") %> + <% else %> + <%= t("admin.budget_investments.index.table_selection") %> + <% end %> + <%= t("admin.budget_investments.index.table_incompatible") %> <% end %> @@ -76,7 +81,15 @@ <%= investment.valuation_finished? ? t("shared.yes"): t("shared.no") %> - + + <% if params[:filter] == "valuating" %> + <%= form_for [:admin, investment.budget, investment], remote: true do |f| %> + <%= f.check_box :visible_to_valuators, + label: false, + class: "js-submit-on-change", + id: "budget_investment_visible_to_valuators" %> + <% end %> + <% else %> <% if investment.selected? %> <%= link_to_unless investment.budget.finished?, t("admin.budget_investments.index.selected"), @@ -104,6 +117,7 @@ remote: true, class: "button small hollow expanded" %> <% end %> + <% end %> <% if params[:filter] == "selected" %> diff --git a/app/views/valuation/budget_investments/index.html.erb b/app/views/valuation/budget_investments/index.html.erb index 5ec1adb30..361ead7fb 100644 --- a/app/views/valuation/budget_investments/index.html.erb +++ b/app/views/valuation/budget_investments/index.html.erb @@ -31,7 +31,7 @@ <% @investments.each do |investment| %> - + <%= investment.id %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index f85d6a8c8..3c753fdc3 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -186,6 +186,7 @@ en: table_feasibility: "Feasibility" table_valuation_finished: "Val. Fin." table_selection: "Selected" + table_evaluation: "Show to valuators" table_incompatible: "Incompatible" show: assigned_admin: Assigned administrator diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 64e7dafd0..3bf47484c 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -186,6 +186,7 @@ es: table_feasibility: "Viabilidad" table_valuation_finished: "Ev. Fin." table_selection: "Seleccionado" + table_evaluation: "Mostrar a evaluadores" table_incompatible: "Incompatible" show: assigned_admin: Administrador asignado diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 217047426..9d72cdffb 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -31,5 +31,11 @@ require_relative 'dev_seeds/communities' require_relative 'dev_seeds/legislation_processes' require_relative 'dev_seeds/newsletters' require_relative 'dev_seeds/notifications' +section "Marking investments as visible to valuators" do + (1..50).to_a.sample.times do + Budget::Investment.reorder("RANDOM()").first.update(visible_to_valuators: true) + end +end + log "All dev seeds created successfuly 👍" diff --git a/db/migrate/20180116151008_add_visible_to_valuators_to_budget_investment.rb b/db/migrate/20180116151008_add_visible_to_valuators_to_budget_investment.rb new file mode 100644 index 000000000..8a04a14a5 --- /dev/null +++ b/db/migrate/20180116151008_add_visible_to_valuators_to_budget_investment.rb @@ -0,0 +1,5 @@ +class AddVisibleToValuatorsToBudgetInvestment < ActiveRecord::Migration + def change + add_column :budget_investments, :visible_to_valuators, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 5a83bebe6..c1ee88246 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -163,6 +163,7 @@ ActiveRecord::Schema.define(version: 20180320104823) do t.boolean "incompatible", default: false t.integer "community_id" t.integer "valuator_group_assignments_count", default: 0 + t.boolean "visible_to_valuators", default: false end add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree diff --git a/spec/factories.rb b/spec/factories.rb index 8f872daaf..cb937e698 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -342,6 +342,10 @@ FactoryBot.define do winner true end + trait :visible_to_valuators do + visible_to_valuators true + end + trait :incompatible do selected incompatible true diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 9a44249b4..08217cc80 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -946,6 +946,94 @@ feature 'Admin budget investments' do end end + context "Mark as visible to valuators" do + let(:group) { create(:budget_group, budget: @budget) } + let(:heading) { create(:budget_heading, group: group) } + + scenario "Mark as visible to valuator", :js do + valuator = create(:valuator) + + investment1 = create(:budget_investment, heading: heading) + investment2 = create(:budget_investment, heading: heading) + + investment1.valuators << valuator + investment2.valuators << valuator + + visit admin_budget_budget_investments_path(@budget) + within('#filter-subnav') { click_link 'Under valuation' } + + within("#budget_investment_#{investment1.id}") do + check "budget_investment_visible_to_valuators" + end + + wait_for_ajax + + login_as(valuator.user) + visit valuation_root_path + + within "#budget_#{@budget.id}" do + click_link "Evaluate" + end + expect(page).to have_content investment1.title + expect(page).not_to have_content investment2.title + end + + scenario "Unmark as visible to valuator", :js do + valuator = create(:valuator) + + investment1 = create(:budget_investment, heading: heading, visible_to_valuators: true) + investment2 = create(:budget_investment, heading: heading, visible_to_valuators: true) + + investment1.valuators << valuator + investment2.valuators << valuator + + visit admin_budget_budget_investments_path(@budget) + within('#filter-subnav') { click_link 'Under valuation' } + + within("#budget_investment_#{investment1.id}") do + uncheck "budget_investment_visible_to_valuators" + end + + wait_for_ajax + + login_as(valuator.user) + visit valuation_root_path + + within "#budget_#{@budget.id}" do + click_link "Evaluate" + end + + expect(page).not_to have_content investment1.title + expect(page).to have_content investment2.title + end + + scenario "Showing the valuating checkbox" do + investment1 = create(:budget_investment, heading: heading, visible_to_valuators: true) + investment2 = create(:budget_investment, heading: heading, visible_to_valuators: false) + + investment1.valuators << create(:valuator) + investment2.valuators << create(:valuator) + + visit admin_budget_budget_investments_path(@budget) + within('#filter-subnav') { click_link 'All' } + + expect(page).not_to have_css("#budget_investment_visible_to_valuators") + expect(page).not_to have_css("#budget_investment_visible_to_valuators") + + within('#filter-subnav') { click_link 'Under valuation' } + + within("#budget_investment_#{investment1.id}") do + valuating_checkbox = find("#budget_investment_visible_to_valuators") + expect(valuating_checkbox).to be_checked + end + + within("#budget_investment_#{investment2.id}") do + valuating_checkbox = find("#budget_investment_visible_to_valuators") + expect(valuating_checkbox).not_to be_checked + end + end + end + context "Selecting csv" do scenario "Downloading CSV file" do diff --git a/spec/features/valuation/budget_investments_spec.rb b/spec/features/valuation/budget_investments_spec.rb index b23aee7ec..35c4d0400 100644 --- a/spec/features/valuation/budget_investments_spec.rb +++ b/spec/features/valuation/budget_investments_spec.rb @@ -26,8 +26,8 @@ feature 'Valuation budget investments' do end scenario 'Index shows budget investments assigned to current valuator' do - investment1 = create(:budget_investment, budget: budget) - investment2 = create(:budget_investment, budget: budget) + investment1 = create(:budget_investment, :visible_to_valuators, budget: budget) + investment2 = create(:budget_investment, :visible_to_valuators, budget: budget) investment1.valuators << valuator @@ -38,8 +38,8 @@ feature 'Valuation budget investments' do end scenario 'Index shows no budget investment to admins no valuators' do - investment1 = create(:budget_investment, budget: budget) - investment2 = create(:budget_investment, budget: budget) + investment1 = create(:budget_investment, :visible_to_valuators, budget: budget) + investment2 = create(:budget_investment, :visible_to_valuators, budget: budget) investment1.valuators << valuator @@ -52,9 +52,9 @@ feature 'Valuation budget investments' do end scenario 'Index orders budget investments by votes' do - investment10 = create(:budget_investment, budget: budget, cached_votes_up: 10) - investment100 = create(:budget_investment, budget: budget, cached_votes_up: 100) - investment1 = create(:budget_investment, budget: budget, cached_votes_up: 1) + investment10 = create(:budget_investment, :visible_to_valuators, budget: budget, cached_votes_up: 10) + investment100 = create(:budget_investment, :visible_to_valuators, budget: budget, cached_votes_up: 100) + investment1 = create(:budget_investment, :visible_to_valuators, budget: budget, cached_votes_up: 1) investment1.valuators << valuator investment10.valuators << valuator @@ -66,6 +66,27 @@ feature 'Valuation budget investments' do expect(investment10.title).to appear_before(investment1.title) end + scenario 'Index displays investments paginated' do + per_page = Kaminari.config.default_per_page + (per_page + 2).times do + investment = create(:budget_investment, :visible_to_valuators, budget: @budget) + investment.valuators << @valuator + end + + visit valuation_budget_budget_investments_path(@budget) + + expect(page).to have_css('.budget_investment', count: per_page) + + within("ul.pagination") do + expect(page).to have_content("1") + expect(page).to have_content("2") + expect(page).not_to have_content("3") + click_link "Next", exact: false + end + + expect(page).to have_css('.budget_investment', count: 2) + end + scenario "Index filtering by heading", :js do group = create(:budget_group, budget: budget) valuating_heading = create(:budget_heading, name: "Only Valuating", group: group) @@ -91,6 +112,14 @@ feature 'Valuation budget investments' do group: group, budget: budget, valuators: [valuator]) + # heading1 = create(:budget_heading, name: "District 9", group: group) + # heading2 = create(:budget_heading, name: "Down to the river", group: group) + # investment1 = create(:budget_investment, :visible_to_valuators, title: "Realocate visitors", + # heading: heading1, group: group, budget: budget) + # investment2 = create(:budget_investment, :visible_to_valuators, title: "Destroy the city", + # heading: heading2, group: group, budget: budget) + investment1.valuators << valuator + investment2.valuators << valuator visit valuation_budget_budget_investments_path(budget) @@ -162,9 +191,10 @@ feature 'Valuation budget investments' do end scenario "Index filtering by valuation status" do - valuating = create(:budget_investment, budget: budget, title: "Ongoing valuation") - valuated = create(:budget_investment, budget: budget, title: "Old idea", - valuation_finished: true) + valuating = create(:budget_investment, :visible_to_valuators, + budget: budget, title: "Ongoing valuation") + valuated = create(:budget_investment, :visible_to_valuators, + budget: budget, title: "Old idea", valuation_finished: true) valuating.valuators << valuator valuated.valuators << valuator @@ -194,7 +224,7 @@ feature 'Valuation budget investments' do let(:investment) do create(:budget_investment, budget: budget, price: 1234, feasibility: 'unfeasible', unfeasibility_explanation: 'It is impossible', - administrator: administrator) + administrator: administrator,) end background do @@ -202,8 +232,10 @@ feature 'Valuation budget investments' do end scenario 'visible for assigned valuators' do + investment.update(visible_to_valuators: true) visit valuation_budget_budget_investments_path(budget) + click_link investment.title expect(page).to have_content(investment.title) diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index fb077c264..4ce415b26 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -362,6 +362,12 @@ module CommonActions fill_in "newsletter_from", with: (options[:from] || "no-reply@consul.dev") fill_in "newsletter_body", with: (options[:body] || "This is a different body") end + def wait_for_ajax + Timeout.timeout(Capybara.default_max_wait_time) do + loop until page.evaluate_script('jQuery.active').zero? + end + end + def click_notifications_icon find("#notifications a").click From e2a91c6cc8ca889dd3d73530c431b97c2909f954 Mon Sep 17 00:00:00 2001 From: iagirre Date: Wed, 24 Jan 2018 14:40:42 +0100 Subject: [PATCH 2/4] Modified the investments partial to fit the new budget_investments UI: valuating filter name has changed to under_valuation. Modified the specs to fit the new UI for budget_investments --- .../budget_investments/_investments.html.erb | 5 +++-- .../features/admin/budget_investments_spec.rb | 21 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index d76294687..e3dd56dc6 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -28,12 +28,13 @@ <%= t("admin.budget_investments.index.table_feasibility") %> <%= t("admin.budget_investments.index.table_valuation_finished") %> - <% if params[:filter] == "valuating" %> + <% if params[:filter] == "under_valuation" %> <%= t("admin.budget_investments.index.table_evaluation") %> <% else %> <%= t("admin.budget_investments.index.table_selection") %> <% end %> + <% if params[:filter] == "selected" %> <%= t("admin.budget_investments.index.table_incompatible") %> <% end %> @@ -82,7 +83,7 @@ <%= investment.valuation_finished? ? t("shared.yes"): t("shared.no") %> - <% if params[:filter] == "valuating" %> + <% if params[:filter] == "under_valuation" %> <%= form_for [:admin, investment.budget, investment], remote: true do |f| %> <%= f.check_box :visible_to_valuators, label: false, diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 08217cc80..fbbff0abf 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -8,8 +8,8 @@ feature 'Admin budget investments' do end background do - admin = create(:administrator) - login_as(admin.user) + @admin = create(:administrator) + login_as(@admin.user) end context "Feature flag" do @@ -953,8 +953,8 @@ feature 'Admin budget investments' do scenario "Mark as visible to valuator", :js do valuator = create(:valuator) - investment1 = create(:budget_investment, heading: heading) - investment2 = create(:budget_investment, heading: heading) + investment1 = create(:budget_investment, heading: heading, administrator_id: @admin.id) + investment2 = create(:budget_investment, heading: heading, administrator_id: @admin.id) investment1.valuators << valuator investment2.valuators << valuator @@ -981,8 +981,8 @@ feature 'Admin budget investments' do scenario "Unmark as visible to valuator", :js do valuator = create(:valuator) - investment1 = create(:budget_investment, heading: heading, visible_to_valuators: true) - investment2 = create(:budget_investment, heading: heading, visible_to_valuators: true) + investment1 = create(:budget_investment, heading: heading, visible_to_valuators: true, administrator_id: @admin.id) + investment2 = create(:budget_investment, heading: heading, visible_to_valuators: true, administrator_id: @admin.id) investment1.valuators << valuator investment2.valuators << valuator @@ -1008,14 +1008,17 @@ feature 'Admin budget investments' do end scenario "Showing the valuating checkbox" do - investment1 = create(:budget_investment, heading: heading, visible_to_valuators: true) - investment2 = create(:budget_investment, heading: heading, visible_to_valuators: false) + investment1 = create(:budget_investment, heading: heading, visible_to_valuators: true, administrator_id: @admin.id) + investment2 = create(:budget_investment, heading: heading, visible_to_valuators: false, administrator_id: @admin.id) investment1.valuators << create(:valuator) investment2.valuators << create(:valuator) visit admin_budget_budget_investments_path(@budget) - within('#filter-subnav') { click_link 'All' } + within('#filter-subnav') do + expect(page).not_to have_link "All" + expect(page).to have_content "All" + end expect(page).not_to have_css("#budget_investment_visible_to_valuators") expect(page).not_to have_css("#budget_investment_visible_to_valuators") From d02b3e0486878f6268147d0b17b83d999a8439f1 Mon Sep 17 00:00:00 2001 From: iagirre Date: Wed, 14 Feb 2018 08:57:48 +0100 Subject: [PATCH 3/4] Modifications to the spec to avoid using wait_for_ajax --- .../features/admin/budget_investments_spec.rb | 83 +++++++++++-------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index fbbff0abf..22d42e86f 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -947,91 +947,104 @@ feature 'Admin budget investments' do end context "Mark as visible to valuators" do - let(:group) { create(:budget_group, budget: @budget) } + let(:valuator) { create(:valuator) } + let(:admin) { create(:administrator) } + + let(:group) { create(:budget_group, budget: budget) } let(:heading) { create(:budget_heading, group: group) } + let(:investment1) { create(:budget_investment, heading: heading) } + let(:investment2) { create(:budget_investment, heading: heading) } + scenario "Mark as visible to valuator", :js do - valuator = create(:valuator) - - investment1 = create(:budget_investment, heading: heading, administrator_id: @admin.id) - investment2 = create(:budget_investment, heading: heading, administrator_id: @admin.id) - investment1.valuators << valuator investment2.valuators << valuator + investment1.update(administrator: admin) + investment2.update(administrator: admin) - visit admin_budget_budget_investments_path(@budget) + visit admin_budget_budget_investments_path(budget) within('#filter-subnav') { click_link 'Under valuation' } within("#budget_investment_#{investment1.id}") do check "budget_investment_visible_to_valuators" end - wait_for_ajax + visit admin_budget_budget_investments_path(budget) + within('#filter-subnav') { click_link 'Under valuation' } - login_as(valuator.user) - visit valuation_root_path + within("#budget_investment_#{investment1.id}") do + expect(find("#budget_investment_visible_to_valuators")).to be_checked + end + end - within "#budget_#{@budget.id}" do + scenario "Shows the correct investments to valuators" do + investment1.update(visible_to_valuators: true) + investment2.update(visible_to_valuators: false) + + investment1.valuators << valuator + investment2.valuators << valuator + investment1.update(administrator: admin) + investment2.update(administrator: admin) + + login_as(valuator.user.reload) + visit root_path + click_link "Admin" + click_link "Valuation" + + within "#budget_#{budget.id}" do click_link "Evaluate" end + expect(page).to have_content investment1.title expect(page).not_to have_content investment2.title end scenario "Unmark as visible to valuator", :js do - valuator = create(:valuator) - - investment1 = create(:budget_investment, heading: heading, visible_to_valuators: true, administrator_id: @admin.id) - investment2 = create(:budget_investment, heading: heading, visible_to_valuators: true, administrator_id: @admin.id) + Setting['feature.budgets.valuators_allowed'] = true investment1.valuators << valuator investment2.valuators << valuator + investment1.update(administrator: admin) + investment2.update(administrator: admin) - visit admin_budget_budget_investments_path(@budget) + visit admin_budget_budget_investments_path(budget) within('#filter-subnav') { click_link 'Under valuation' } within("#budget_investment_#{investment1.id}") do uncheck "budget_investment_visible_to_valuators" end - wait_for_ajax + visit admin_budget_budget_investments_path(budget) + within('#filter-subnav') { click_link 'Under valuation' } - login_as(valuator.user) - visit valuation_root_path - - within "#budget_#{@budget.id}" do - click_link "Evaluate" + within("#budget_investment_#{investment1.id}") do + expect(find("#budget_investment_visible_to_valuators")).not_to be_checked end - - expect(page).not_to have_content investment1.title - expect(page).to have_content investment2.title end scenario "Showing the valuating checkbox" do - investment1 = create(:budget_investment, heading: heading, visible_to_valuators: true, administrator_id: @admin.id) - investment2 = create(:budget_investment, heading: heading, visible_to_valuators: false, administrator_id: @admin.id) + investment1 = create(:budget_investment, budget: budget, visible_to_valuators: true) + investment2 = create(:budget_investment, budget: budget, visible_to_valuators: false) investment1.valuators << create(:valuator) investment2.valuators << create(:valuator) + investment2.valuators << create(:valuator) + investment1.update(administrator: create(:administrator)) + investment2.update(administrator: create(:administrator)) - visit admin_budget_budget_investments_path(@budget) - within('#filter-subnav') do - expect(page).not_to have_link "All" - expect(page).to have_content "All" - end + visit admin_budget_budget_investments_path(budget) - expect(page).not_to have_css("#budget_investment_visible_to_valuators") expect(page).not_to have_css("#budget_investment_visible_to_valuators") within('#filter-subnav') { click_link 'Under valuation' } within("#budget_investment_#{investment1.id}") do - valuating_checkbox = find("#budget_investment_visible_to_valuators") + valuating_checkbox = find('#budget_investment_visible_to_valuators') expect(valuating_checkbox).to be_checked end within("#budget_investment_#{investment2.id}") do - valuating_checkbox = find("#budget_investment_visible_to_valuators") + valuating_checkbox = find('#budget_investment_visible_to_valuators') expect(valuating_checkbox).not_to be_checked end end From 21a6d3495a4ba6154a97ef7d4276826ef54763b2 Mon Sep 17 00:00:00 2001 From: iagirre Date: Mon, 2 Apr 2018 13:03:09 +0200 Subject: [PATCH 4/4] Update PR with master Rebase master branch so that this PR can be updated with the latest changes. Conflicts has been solved and some specs updated to fit the new changes. dev_seeds has been also adapted to the new format. --- db/dev_seeds.rb | 6 ---- db/dev_seeds/budgets.rb | 6 ++++ .../valuation/budget_investments_spec.rb | 30 +++++++++---------- spec/support/common_actions.rb | 6 ---- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 9d72cdffb..217047426 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -31,11 +31,5 @@ require_relative 'dev_seeds/communities' require_relative 'dev_seeds/legislation_processes' require_relative 'dev_seeds/newsletters' require_relative 'dev_seeds/notifications' -section "Marking investments as visible to valuators" do - (1..50).to_a.sample.times do - Budget::Investment.reorder("RANDOM()").first.update(visible_to_valuators: true) - end -end - log "All dev seeds created successfuly 👍" diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb index 243785e0a..4740ed407 100644 --- a/db/dev_seeds/budgets.rb +++ b/db/dev_seeds/budgets.rb @@ -56,6 +56,12 @@ section "Creating Investments" do end end +section "Marking investments as visible to valuators" do + (1..50).to_a.sample.times do + Budget::Investment.reorder("RANDOM()").first.update(visible_to_valuators: true) + end +end + section "Geolocating Investments" do Budget.all.each do |budget| budget.investments.each do |investment| diff --git a/spec/features/valuation/budget_investments_spec.rb b/spec/features/valuation/budget_investments_spec.rb index 35c4d0400..5d9b4fa4a 100644 --- a/spec/features/valuation/budget_investments_spec.rb +++ b/spec/features/valuation/budget_investments_spec.rb @@ -69,11 +69,11 @@ feature 'Valuation budget investments' do scenario 'Index displays investments paginated' do per_page = Kaminari.config.default_per_page (per_page + 2).times do - investment = create(:budget_investment, :visible_to_valuators, budget: @budget) - investment.valuators << @valuator + investment = create(:budget_investment, :visible_to_valuators, budget: budget) + investment.valuators << valuator end - visit valuation_budget_budget_investments_path(@budget) + visit valuation_budget_budget_investments_path(budget) expect(page).to have_css('.budget_investment', count: per_page) @@ -92,34 +92,26 @@ feature 'Valuation budget investments' do valuating_heading = create(:budget_heading, name: "Only Valuating", group: group) valuating_finished_heading = create(:budget_heading, name: "Valuating&Finished", group: group) finished_heading = create(:budget_heading, name: "Only Finished", group: group) - create(:budget_investment, title: "Valuating Investment ONE", + create(:budget_investment, :visible_to_valuators, title: "Valuating Investment ONE", heading: valuating_heading, group: group, budget: budget, valuators: [valuator]) - create(:budget_investment, title: "Valuating Investment TWO", + create(:budget_investment, :visible_to_valuators, title: "Valuating Investment TWO", heading: valuating_finished_heading, group: group, budget: budget, valuators: [valuator]) - create(:budget_investment, :finished, title: "Finished ONE", + create(:budget_investment, :finished, :visible_to_valuators, title: "Finished ONE", heading: valuating_finished_heading, group: group, budget: budget, valuators: [valuator]) - create(:budget_investment, :finished, title: "Finished TWO", + create(:budget_investment, :finished, :visible_to_valuators, title: "Finished TWO", heading: finished_heading, group: group, budget: budget, valuators: [valuator]) - # heading1 = create(:budget_heading, name: "District 9", group: group) - # heading2 = create(:budget_heading, name: "Down to the river", group: group) - # investment1 = create(:budget_investment, :visible_to_valuators, title: "Realocate visitors", - # heading: heading1, group: group, budget: budget) - # investment2 = create(:budget_investment, :visible_to_valuators, title: "Destroy the city", - # heading: heading2, group: group, budget: budget) - investment1.valuators << valuator - investment2.valuators << valuator visit valuation_budget_budget_investments_path(budget) @@ -299,6 +291,8 @@ feature 'Valuation budget investments' do end scenario 'Dossier empty by default' do + investment.update(visible_to_valuators: true) + visit valuation_budget_budget_investments_path(budget) click_link investment.title @@ -310,6 +304,7 @@ feature 'Valuation budget investments' do end scenario 'Edit dossier' do + investment.update(visible_to_valuators: true) visit valuation_budget_budget_investments_path(budget) within("#budget_investment_#{investment.id}") do click_link "Edit dossier" @@ -411,6 +406,8 @@ feature 'Valuation budget investments' do end scenario 'Finish valuation' do + investment.update(visible_to_valuators: true) + visit valuation_budget_budget_investment_path(budget, investment) click_link 'Edit dossier' @@ -468,7 +465,10 @@ feature 'Valuation budget investments' do end scenario 'Validates price formats' do + investment.update(visible_to_valuators: true) + visit valuation_budget_budget_investments_path(budget) + within("#budget_investment_#{investment.id}") do click_link "Edit dossier" end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 4ce415b26..fb077c264 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -362,12 +362,6 @@ module CommonActions fill_in "newsletter_from", with: (options[:from] || "no-reply@consul.dev") fill_in "newsletter_body", with: (options[:body] || "This is a different body") end - def wait_for_ajax - Timeout.timeout(Capybara.default_max_wait_time) do - loop until page.evaluate_script('jQuery.active').zero? - end - end - def click_notifications_icon find("#notifications a").click