Merge pull request #4810 from consul/budgets_map
Show budgets map only if feature is enabled
This commit is contained in:
@@ -33,13 +33,7 @@
|
||||
<% end %>
|
||||
|
||||
<%= render Budgets::SupportsInfoComponent.new(budget) %>
|
||||
|
||||
<% unless budget.informing? %>
|
||||
<div class="map inline">
|
||||
<h2><%= t("budgets.index.map") %></h2>
|
||||
<%= render_map(nil, "budgets", false, nil, coordinates) %>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= render Budgets::MapComponent.new(budget) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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
|
||||
|
||||
4
app/components/budgets/map_component.html.erb
Normal file
4
app/components/budgets/map_component.html.erb
Normal file
@@ -0,0 +1,4 @@
|
||||
<div class="map inline">
|
||||
<h2><%= t("budgets.index.map") %></h2>
|
||||
<%= render_map(nil, "budgets", false, nil, coordinates) %>
|
||||
</div>
|
||||
26
app/components/budgets/map_component.rb
Normal file
26
app/components/budgets/map_component.rb
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
34
spec/components/budgets/map_component_spec.rb
Normal file
34
spec/components/budgets/map_component_spec.rb
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user