Merge pull request #5129 from consul/geozones

Do not show geozones when there are no geozones defined
This commit is contained in:
Senén Rodero
2023-06-30 17:21:20 +02:00
committed by GitHub
17 changed files with 169 additions and 16 deletions

View File

@@ -49,10 +49,12 @@
</div>
<% end %>
<div>
<%= f.select :geozone_id, geozone_select_options,
include_blank: t("geozones.none") %>
</div>
<% if Geozone.any? %>
<div>
<%= f.select :geozone_id, geozone_select_options,
include_blank: t("geozones.none") %>
</div>
<% end %>
<% if feature?(:map) %>
<div>

View File

@@ -0,0 +1,7 @@
class Proposals::GeozonesComponent < ApplicationComponent
delegate :image_path_for, to: :helpers
def render?
Geozone.any?
end
end

View File

@@ -0,0 +1,5 @@
<ul id="geozone" class="no-bullet geozone">
<li class="inline-block">
<%= link_to geozone_name(geozonable), link %>
</li>
</ul>

View File

@@ -0,0 +1,13 @@
class Shared::GeozoneLinkComponent < ApplicationComponent
attr_reader :geozonable, :link
delegate :geozone_name, to: :helpers
def initialize(geozonable, link)
@geozonable = geozonable
@link = link
end
def render?
Geozone.any?
end
end

View File

@@ -36,9 +36,11 @@
<%= render "documents/nested_documents", f: f %>
</div>
<div class="small-12 medium-6 column">
<%= f.select :geozone_id, geozone_select_options, include_blank: t("geozones.none") %>
</div>
<% if Geozone.any? %>
<div class="small-12 medium-6 column">
<%= f.select :geozone_id, geozone_select_options, include_blank: t("geozones.none") %>
</div>
<% end %>
<div class="small-12 column">
<%= f.label :tag_list, t("legislation.proposals.form.tags_label") %>

View File

@@ -53,6 +53,13 @@
<%= t("shared.collective") %>
</span>
<% end %>
<% if Geozone.any? %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span class="geozone">
<%= link_to geozone_name(proposal), legislation_process_proposals_path(proposal.legislation_process_id, search: geozone_name(proposal)) %>
</span>
<% end %>
</p>
<div class="proposal-description">
<p><%= proposal.summary %></p>

View File

@@ -94,7 +94,7 @@
<%= render "shared/tags", taggable: @proposal %>
<%= render "shared/geozone", geozonable: @proposal %>
<%= render Shared::GeozoneLinkComponent.new(@proposal, legislation_process_proposals_path(@process, search: geozone_name(@proposal))) %>
<div class="js-moderator-proposal-actions margin">
<%= render "legislation/proposals/actions", proposal: @proposal %>

View File

@@ -52,6 +52,13 @@
<%= t("shared.collective") %>
</span>
<% end %>
<% if Geozone.any? %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span class="geozone">
<%= link_to geozone_name(proposal), proposals_path(search: geozone_name(proposal)) %>
</span>
<% end %>
</p>
<div class="proposal-description">
<p><%= proposal.summary %></p>

View File

@@ -119,7 +119,7 @@
<% if params[:retired].blank? %>
<%= render "categories" %>
<%= render "shared/tag_cloud", taggable: "Proposal" %>
<%= render "geozones" %>
<%= render Proposals::GeozonesComponent.new %>
<% end %>
<%= render "retired" %>
<%= render "proposals_lists" %>

View File

@@ -40,7 +40,7 @@
<% end %>
<%= render "proposals/info", proposal: @proposal %>
<%= render "shared/geozone", geozonable: @proposal %>
<%= render Shared::GeozoneLinkComponent.new(@proposal, proposals_path(search: geozone_name(@proposal))) %>
<% unless @proposal.selected? %>
<%= render "relationable/related_content", relationable: @proposal %>

View File

@@ -46,7 +46,7 @@
<%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: "button radius expand" %>
<%= render "shared/tag_cloud", taggable: "Proposal" %>
<%= render "categories" %>
<%= render "geozones" %>
<%= render Proposals::GeozonesComponent.new %>
</aside>
</div>
</div>

View File

@@ -1,5 +0,0 @@
<ul id="geozone" class="no-bullet geozone">
<li class="inline-block">
<%= link_to geozone_name(geozonable), proposals_path(search: geozone_name(geozonable)) %>
</li>
</ul>

View File

@@ -0,0 +1,19 @@
require "rails_helper"
describe Proposals::GeozonesComponent do
let(:component) { Proposals::GeozonesComponent.new() }
it "is not rendered when there are no geozones defined" do
render_inline component
expect(page).not_to have_content "Districts"
end
it "is rendered when there are geozones defined" do
create(:geozone)
render_inline component
expect(page).to have_content "Districts"
end
end

View File

@@ -31,6 +31,7 @@ describe "Admin custom images", :admin do
end
scenario "Image is replaced on front views" do
create(:geozone)
budget = create(:budget)
group = create(:budget_group, budget: budget)

View File

@@ -236,4 +236,72 @@ describe "Legislation Proposals" do
expect(page).to have_link("Culture")
end
scenario "Shows geozone tag as proposals filter where there are geozones defined" do
create(:legislation_proposal, process: process)
create(:legislation_proposal, process: process, geozone: create(:geozone, name: "Zone1"))
visit legislation_process_proposals_path(process)
expect(page).to have_link("Zone1", href: legislation_process_proposals_path(process, search: "Zone1"))
link = legislation_process_proposals_path(process, search: "All city")
expect(page).to have_link("All city", href: link)
end
scenario "Does not show the geozone tag when no geozones defined" do
create(:legislation_proposal, process: process)
visit legislation_process_proposals_path(process)
expect(page).not_to have_link("All city")
end
scenario "Can filter proposals by geozone" do
geozone = create(:geozone, name: "Zone1")
proposal = create(:legislation_proposal, title: "Proposal with geozone",
legislation_process_id: process.id,
geozone: geozone)
create(:legislation_proposal, title: "Proposal without geozone", legislation_process_id: process.id)
visit legislation_process_proposal_path(proposal.process, proposal)
click_link "Zone1"
expect(page).to have_current_path(legislation_process_proposals_path(process.id, search: "Zone1"))
expect(page).to have_content("Proposal with geozone")
expect(page).not_to have_content("Proposal without geozone")
end
scenario "Show link to filter by geozone where there are geozones defined" do
create(:geozone)
create(:legislation_proposal, legislation_process_id: process.id)
visit legislation_process_proposal_path(proposal.process, proposal)
expect(page).to have_link("All city")
end
scenario "Do not show link to geozone where there are no geozones defined" do
create(:legislation_proposal, legislation_process_id: process.id)
visit legislation_process_proposal_path(proposal.process, proposal)
expect(page).not_to have_link("All city")
end
scenario "form shows the geozone selector when there are geozones defined" do
create(:geozone)
login_as user
visit new_legislation_process_proposal_path(process)
expect(page).to have_field("Scope of operation")
end
scenario "form do not show geozone selector when there are no geozones defined" do
login_as user
visit new_legislation_process_proposal_path(process)
expect(page).not_to have_field("Scope of operation")
end
end

View File

@@ -540,7 +540,15 @@ describe "Proposals" do
end
context "Geozones" do
scenario "When there are not gezones defined it does not show the geozone link" do
visit proposal_path(create(:proposal))
expect(page).not_to have_selector "#geozone"
expect(page).not_to have_link "All city"
end
scenario "Default whole city" do
create(:geozone)
author = create(:user)
login_as(author)
@@ -558,6 +566,25 @@ describe "Proposals" do
end
end
scenario "form shows the geozone selector when there are geozones defined" do
create(:geozone)
author = create(:user)
login_as(author)
visit new_proposal_path
expect(page).to have_field("Scope of operation")
end
scenario "form do not show geozone selector when there are no geozones defined" do
author = create(:user)
login_as(author)
visit new_proposal_path
expect(page).not_to have_field("Scope of operation")
end
scenario "Specific geozone" do
create(:geozone, name: "California")
create(:geozone, name: "New York")