diff --git a/app/components/budgets/budget_component.html.erb b/app/components/budgets/budget_component.html.erb index 232d5da75..d0855c9db 100644 --- a/app/components/budgets/budget_component.html.erb +++ b/app/components/budgets/budget_component.html.erb @@ -33,13 +33,7 @@ <% end %> <%= render Budgets::SupportsInfoComponent.new(budget) %> - - <% unless budget.informing? %> -
-

<%= t("budgets.index.map") %>

- <%= render_map(nil, "budgets", false, nil, coordinates) %> -
- <% end %> + <%= render Budgets::MapComponent.new(budget) %> diff --git a/app/components/budgets/budget_component.rb b/app/components/budgets/budget_component.rb index 83536cfd6..b11ebce85 100644 --- a/app/components/budgets/budget_component.rb +++ b/app/components/budgets/budget_component.rb @@ -1,22 +1,7 @@ class Budgets::BudgetComponent < ApplicationComponent - delegate :wysiwyg, :auto_link_already_sanitized_html, :render_map, to: :helpers attr_reader :budget def initialize(budget) @budget = budget end - - private - - def coordinates - return unless budget.present? - - if budget.publishing_prices_or_later? && budget.investments.selected.any? - investments = budget.investments.selected - else - investments = budget.investments - end - - MapLocation.where(investment_id: investments).map(&:json_data) - end end diff --git a/app/components/budgets/map_component.html.erb b/app/components/budgets/map_component.html.erb new file mode 100644 index 000000000..733ce56af --- /dev/null +++ b/app/components/budgets/map_component.html.erb @@ -0,0 +1,4 @@ +
+

<%= t("budgets.index.map") %>

+ <%= render_map(nil, "budgets", false, nil, coordinates) %> +
diff --git a/app/components/budgets/map_component.rb b/app/components/budgets/map_component.rb new file mode 100644 index 000000000..1da16c137 --- /dev/null +++ b/app/components/budgets/map_component.rb @@ -0,0 +1,26 @@ +class Budgets::MapComponent < ApplicationComponent + delegate :render_map, to: :helpers + attr_reader :budget + + def initialize(budget) + @budget = budget + end + + def render? + feature?(:map) && !budget.informing? + end + + private + + def coordinates + return unless budget.present? + + if budget.publishing_prices_or_later? && budget.investments.selected.any? + investments = budget.investments.selected + else + investments = budget.investments + end + + MapLocation.where(investment_id: investments).map(&:json_data) + end +end diff --git a/app/models/concerns/mappable.rb b/app/models/concerns/mappable.rb index 4b2dbbb53..356a38231 100644 --- a/app/models/concerns/mappable.rb +++ b/app/models/concerns/mappable.rb @@ -4,9 +4,5 @@ module Mappable included do has_one :map_location, dependent: :destroy accepts_nested_attributes_for :map_location, allow_destroy: true, reject_if: :all_blank - - def feature_maps? - Setting["feature.map"].present? - end end end diff --git a/spec/components/budgets/map_component_spec.rb b/spec/components/budgets/map_component_spec.rb new file mode 100644 index 000000000..7d9d3ffb8 --- /dev/null +++ b/spec/components/budgets/map_component_spec.rb @@ -0,0 +1,34 @@ +require "rails_helper" + +describe Budgets::MapComponent do + let(:budget) { build(:budget) } + + describe "#render?" do + it "is rendered after the informing phase when the map feature is enabled" do + Setting["feature.map"] = true + budget.phase = "accepting" + + render_inline Budgets::MapComponent.new(budget) + + expect(page.first("div.map")).to have_content "located geographically" + end + + it "is not rendered during the informing phase" do + Setting["feature.map"] = true + budget.phase = "informing" + + render_inline Budgets::MapComponent.new(budget) + + expect(page).not_to be_rendered + end + + it "is not rendered when the map feature is disabled" do + Setting["feature.map"] = false + budget.phase = "accepting" + + render_inline Budgets::MapComponent.new(budget) + + expect(page).not_to be_rendered + end + end +end diff --git a/spec/system/budgets/budgets_spec.rb b/spec/system/budgets/budgets_spec.rb index b0a8ce7f9..d8db309f8 100644 --- a/spec/system/budgets/budgets_spec.rb +++ b/spec/system/budgets/budgets_spec.rb @@ -96,12 +96,6 @@ describe "Budgets" do within("#budget_info") do expect(page).not_to have_link heading.name expect(page).to have_content "#{heading.name}\n€1,000,000" - - expect(page).not_to have_link("List of all investment projects") - expect(page).not_to have_link("List of all unfeasible investment projects") - expect(page).not_to have_link("List of all investment projects not selected for balloting") - - expect(page).not_to have_css("div.map") end end @@ -114,8 +108,6 @@ describe "Budgets" do within("#budget_info") do expect(page).not_to have_link heading.name expect(page).to have_content "#{heading.name}\n€1,000,000" - - expect(page).to have_css("div.map") end end @@ -342,7 +334,7 @@ describe "Budgets" do } end - allow_any_instance_of(Budgets::BudgetComponent).to receive(:coordinates).and_return(coordinates) + allow_any_instance_of(Budgets::MapComponent).to receive(:coordinates).and_return(coordinates) visit budgets_path