From 5409db6c5578149c8e99e6712f1c08095775b19d Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 1 Feb 2019 16:11:35 +0100 Subject: [PATCH 1/2] Show only selected investments on map from publishing prices phase If there are no selected investements show all investments on map. --- app/helpers/budgets_helper.rb | 2 +- app/models/budget.rb | 4 +-- spec/features/budgets/budgets_spec.rb | 42 ++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index 179d83ba8..b05c0ea4c 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -70,7 +70,7 @@ module BudgetsHelper def current_budget_map_locations return unless current_budget.present? - if current_budget.valuating_or_later? + if current_budget.publishing_prices_or_later? && current_budget.investments.selected.any? investments = current_budget.investments.selected else investments = current_budget.investments diff --git a/app/models/budget.rb b/app/models/budget.rb index 3f4bed9a1..93e6a095f 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -105,8 +105,8 @@ class Budget < ActiveRecord::Base Budget::Phase::PUBLISHED_PRICES_PHASES.include?(phase) end - def valuating_or_later? - valuating? || publishing_prices? || balloting_or_later? + def publishing_prices_or_later? + publishing_prices? || balloting_or_later? end def balloting_process? diff --git a/spec/features/budgets/budgets_spec.rb b/spec/features/budgets/budgets_spec.rb index b3fa3bee3..a973650f3 100644 --- a/spec/features/budgets/budgets_spec.rb +++ b/spec/features/budgets/budgets_spec.rb @@ -230,7 +230,7 @@ feature 'Budgets' do let(:heading) { create(:budget_heading, group: group) } background do - Setting['feature.map'] = true + Setting["feature.map"] = true end scenario "Display investment's map location markers", :js do @@ -249,6 +249,46 @@ feature 'Budgets' do end end + scenario "Display all investment's map location if there are no selected", :js do + budget.update(phase: :publishing_prices) + + investment1 = create(:budget_investment, heading: heading) + investment2 = create(:budget_investment, heading: heading) + investment3 = create(:budget_investment, heading: heading) + investment4 = create(:budget_investment, heading: heading) + + investment1.create_map_location(longitude: 40.1234, latitude: 3.1234, zoom: 10) + investment2.create_map_location(longitude: 40.1235, latitude: 3.1235, zoom: 10) + investment3.create_map_location(longitude: 40.1236, latitude: 3.1236, zoom: 10) + investment4.create_map_location(longitude: 40.1240, latitude: 3.1240, zoom: 10) + + visit budgets_path + + within ".map_location" do + expect(page).to have_css(".map-icon", count: 4, visible: false) + end + end + + scenario "Display only selected investment's map location from publishing prices phase", :js do + budget.update(phase: :publishing_prices) + + investment1 = create(:budget_investment, :selected, heading: heading) + investment2 = create(:budget_investment, :selected, heading: heading) + investment3 = create(:budget_investment, heading: heading) + investment4 = create(:budget_investment, heading: heading) + + investment1.create_map_location(longitude: 40.1234, latitude: 3.1234, zoom: 10) + investment2.create_map_location(longitude: 40.1235, latitude: 3.1235, zoom: 10) + investment3.create_map_location(longitude: 40.1236, latitude: 3.1236, zoom: 10) + investment4.create_map_location(longitude: 40.1240, latitude: 3.1240, zoom: 10) + + visit budgets_path + + within ".map_location" do + expect(page).to have_css(".map-icon", count: 2, visible: false) + end + end + scenario "Skip invalid map markers", :js do map_locations = [] From 726340156187102dc020a98858ec13a4ef244265 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 1 Feb 2019 16:12:15 +0100 Subject: [PATCH 2/2] Remove duplicated budgets specs --- spec/features/budgets/budgets_spec.rb | 71 --------------------------- 1 file changed, 71 deletions(-) diff --git a/spec/features/budgets/budgets_spec.rb b/spec/features/budgets/budgets_spec.rb index a973650f3..ca90a1c40 100644 --- a/spec/features/budgets/budgets_spec.rb +++ b/spec/features/budgets/budgets_spec.rb @@ -319,77 +319,6 @@ feature 'Budgets' do end end - xcontext "Index map" do - - let(:group) { create(:budget_group, budget: budget) } - let(:heading) { create(:budget_heading, group: group) } - - before do - Setting['feature.map'] = true - end - - scenario "Display investment's map location markers" , :js do - investment1 = create(:budget_investment, heading: heading) - investment2 = create(:budget_investment, heading: heading) - investment3 = create(:budget_investment, heading: heading) - - investment1.create_map_location(longitude: 40.1234, latitude: 3.1234, zoom: 10) - investment2.create_map_location(longitude: 40.1235, latitude: 3.1235, zoom: 10) - investment3.create_map_location(longitude: 40.1236, latitude: 3.1236, zoom: 10) - - visit budgets_path - - within ".map_location" do - expect(page).to have_css(".map-icon", count: 3) - end - end - - scenario "Display selected investment's map location markers" , :js do - - budget.update(phase: :valuating) - - investment1 = create(:budget_investment, :selected, heading: heading) - investment2 = create(:budget_investment, :selected, heading: heading) - investment3 = create(:budget_investment, heading: heading) - - investment1.create_map_location(longitude: 40.1234, latitude: 3.1234, zoom: 10) - investment2.create_map_location(longitude: 40.1235, latitude: 3.1235, zoom: 10) - investment3.create_map_location(longitude: 40.1236, latitude: 3.1236, zoom: 10) - - visit budgets_path - - within ".map_location" do - expect(page).to have_css(".map-icon", count: 2) - end - end - - scenario "Skip invalid map markers" , :js do - map_locations = [] - map_locations << { longitude: 40.123456789, latitude: 3.12345678 } - map_locations << { longitude: 40.123456789, latitude: "*******" } - map_locations << { longitude: "**********", latitude: 3.12345678 } - - budget_map_locations = map_locations.map do |map_location| - { - lat: map_location[:latitude], - long: map_location[:longitude], - investment_title: "#{rand(999)}", - investment_id: "#{rand(999)}", - budget_id: budget.id - } - end - - allow_any_instance_of(BudgetsHelper). - to receive(:current_budget_map_locations).and_return(budget_map_locations) - - visit budgets_path - - within ".map_location" do - expect(page).to have_css(".map-icon", count: 1) - end - end - end - context 'Show' do scenario "List all groups" do