Skip to content

Commit

Permalink
Merge pull request #5129 from consul/geozones
Browse files Browse the repository at this point in the history
Do not show geozones when there are no geozones defined
  • Loading branch information
Senen committed Jun 30, 2023
2 parents 286a128 + ca12388 commit 37417e5
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 16 deletions.
10 changes: 6 additions & 4 deletions app/components/proposals/form_component.html.erb
Expand Up @@ -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>
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions app/components/proposals/geozones_component.rb
@@ -0,0 +1,7 @@
class Proposals::GeozonesComponent < ApplicationComponent
delegate :image_path_for, to: :helpers

def render?
Geozone.any?
end
end
5 changes: 5 additions & 0 deletions app/components/shared/geozone_link_component.html.erb
@@ -0,0 +1,5 @@
<ul id="geozone" class="no-bullet geozone">
<li class="inline-block">
<%= link_to geozone_name(geozonable), link %>
</li>
</ul>
13 changes: 13 additions & 0 deletions app/components/shared/geozone_link_component.rb
@@ -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
8 changes: 5 additions & 3 deletions app/views/legislation/proposals/_form.html.erb
Expand Up @@ -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") %>
Expand Down
7 changes: 7 additions & 0 deletions app/views/legislation/proposals/_proposal.html.erb
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion app/views/legislation/proposals/show.html.erb
Expand Up @@ -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 %>
Expand Down
7 changes: 7 additions & 0 deletions app/views/proposals/_proposal.html.erb
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion app/views/proposals/index.html.erb
Expand Up @@ -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" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/proposals/show.html.erb
Expand Up @@ -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 %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/proposals/summary.html.erb
Expand Up @@ -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>
Expand Down
5 changes: 0 additions & 5 deletions app/views/shared/_geozone.html.erb

This file was deleted.

19 changes: 19 additions & 0 deletions spec/components/proposals/geozones_component_spec.rb
@@ -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
1 change: 1 addition & 0 deletions spec/system/admin/site_customization/images_spec.rb
Expand Up @@ -31,6 +31,7 @@
end

scenario "Image is replaced on front views" do
create(:geozone)
budget = create(:budget)
group = create(:budget_group, budget: budget)

Expand Down
68 changes: 68 additions & 0 deletions spec/system/legislation/proposals_spec.rb
Expand Up @@ -236,4 +236,72 @@ def legislation_proposals_order

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
27 changes: 27 additions & 0 deletions spec/system/proposals_spec.rb
Expand Up @@ -540,7 +540,15 @@
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)

Expand All @@ -558,6 +566,25 @@
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")
Expand Down

0 comments on commit 37417e5

Please sign in to comment.