Merge pull request #5129 from consul/geozones
Do not show geozones when there are no geozones defined
This commit is contained in:
@@ -49,10 +49,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% if Geozone.any? %>
|
||||||
<div>
|
<div>
|
||||||
<%= f.select :geozone_id, geozone_select_options,
|
<%= f.select :geozone_id, geozone_select_options,
|
||||||
include_blank: t("geozones.none") %>
|
include_blank: t("geozones.none") %>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if feature?(:map) %>
|
<% if feature?(:map) %>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
7
app/components/proposals/geozones_component.rb
Normal file
7
app/components/proposals/geozones_component.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
class Proposals::GeozonesComponent < ApplicationComponent
|
||||||
|
delegate :image_path_for, to: :helpers
|
||||||
|
|
||||||
|
def render?
|
||||||
|
Geozone.any?
|
||||||
|
end
|
||||||
|
end
|
||||||
5
app/components/shared/geozone_link_component.html.erb
Normal file
5
app/components/shared/geozone_link_component.html.erb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<ul id="geozone" class="no-bullet geozone">
|
||||||
|
<li class="inline-block">
|
||||||
|
<%= link_to geozone_name(geozonable), link %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
13
app/components/shared/geozone_link_component.rb
Normal file
13
app/components/shared/geozone_link_component.rb
Normal 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
|
||||||
@@ -36,9 +36,11 @@
|
|||||||
<%= render "documents/nested_documents", f: f %>
|
<%= render "documents/nested_documents", f: f %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% if Geozone.any? %>
|
||||||
<div class="small-12 medium-6 column">
|
<div class="small-12 medium-6 column">
|
||||||
<%= f.select :geozone_id, geozone_select_options, include_blank: t("geozones.none") %>
|
<%= f.select :geozone_id, geozone_select_options, include_blank: t("geozones.none") %>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<%= f.label :tag_list, t("legislation.proposals.form.tags_label") %>
|
<%= f.label :tag_list, t("legislation.proposals.form.tags_label") %>
|
||||||
|
|||||||
@@ -53,6 +53,13 @@
|
|||||||
<%= t("shared.collective") %>
|
<%= t("shared.collective") %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% if Geozone.any? %>
|
||||||
|
<span class="bullet"> • </span>
|
||||||
|
<span class="geozone">
|
||||||
|
<%= link_to geozone_name(proposal), legislation_process_proposals_path(proposal.legislation_process_id, search: geozone_name(proposal)) %>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
<div class="proposal-description">
|
<div class="proposal-description">
|
||||||
<p><%= proposal.summary %></p>
|
<p><%= proposal.summary %></p>
|
||||||
|
|||||||
@@ -94,7 +94,7 @@
|
|||||||
|
|
||||||
<%= render "shared/tags", taggable: @proposal %>
|
<%= 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">
|
<div class="js-moderator-proposal-actions margin">
|
||||||
<%= render "legislation/proposals/actions", proposal: @proposal %>
|
<%= render "legislation/proposals/actions", proposal: @proposal %>
|
||||||
|
|||||||
@@ -52,6 +52,13 @@
|
|||||||
<%= t("shared.collective") %>
|
<%= t("shared.collective") %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% if Geozone.any? %>
|
||||||
|
<span class="bullet"> • </span>
|
||||||
|
<span class="geozone">
|
||||||
|
<%= link_to geozone_name(proposal), proposals_path(search: geozone_name(proposal)) %>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
<div class="proposal-description">
|
<div class="proposal-description">
|
||||||
<p><%= proposal.summary %></p>
|
<p><%= proposal.summary %></p>
|
||||||
|
|||||||
@@ -119,7 +119,7 @@
|
|||||||
<% if params[:retired].blank? %>
|
<% if params[:retired].blank? %>
|
||||||
<%= render "categories" %>
|
<%= render "categories" %>
|
||||||
<%= render "shared/tag_cloud", taggable: "Proposal" %>
|
<%= render "shared/tag_cloud", taggable: "Proposal" %>
|
||||||
<%= render "geozones" %>
|
<%= render Proposals::GeozonesComponent.new %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= render "retired" %>
|
<%= render "retired" %>
|
||||||
<%= render "proposals_lists" %>
|
<%= render "proposals_lists" %>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= render "proposals/info", proposal: @proposal %>
|
<%= render "proposals/info", proposal: @proposal %>
|
||||||
<%= render "shared/geozone", geozonable: @proposal %>
|
<%= render Shared::GeozoneLinkComponent.new(@proposal, proposals_path(search: geozone_name(@proposal))) %>
|
||||||
|
|
||||||
<% unless @proposal.selected? %>
|
<% unless @proposal.selected? %>
|
||||||
<%= render "relationable/related_content", relationable: @proposal %>
|
<%= render "relationable/related_content", relationable: @proposal %>
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
<%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: "button radius expand" %>
|
<%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: "button radius expand" %>
|
||||||
<%= render "shared/tag_cloud", taggable: "Proposal" %>
|
<%= render "shared/tag_cloud", taggable: "Proposal" %>
|
||||||
<%= render "categories" %>
|
<%= render "categories" %>
|
||||||
<%= render "geozones" %>
|
<%= render Proposals::GeozonesComponent.new %>
|
||||||
</aside>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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>
|
|
||||||
19
spec/components/proposals/geozones_component_spec.rb
Normal file
19
spec/components/proposals/geozones_component_spec.rb
Normal 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
|
||||||
@@ -31,6 +31,7 @@ describe "Admin custom images", :admin do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Image is replaced on front views" do
|
scenario "Image is replaced on front views" do
|
||||||
|
create(:geozone)
|
||||||
budget = create(:budget)
|
budget = create(:budget)
|
||||||
group = create(:budget_group, budget: budget)
|
group = create(:budget_group, budget: budget)
|
||||||
|
|
||||||
|
|||||||
@@ -236,4 +236,72 @@ describe "Legislation Proposals" do
|
|||||||
|
|
||||||
expect(page).to have_link("Culture")
|
expect(page).to have_link("Culture")
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -540,7 +540,15 @@ describe "Proposals" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "Geozones" do
|
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
|
scenario "Default whole city" do
|
||||||
|
create(:geozone)
|
||||||
author = create(:user)
|
author = create(:user)
|
||||||
login_as(author)
|
login_as(author)
|
||||||
|
|
||||||
@@ -558,6 +566,25 @@ describe "Proposals" do
|
|||||||
end
|
end
|
||||||
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
|
scenario "Specific geozone" do
|
||||||
create(:geozone, name: "California")
|
create(:geozone, name: "California")
|
||||||
create(:geozone, name: "New York")
|
create(:geozone, name: "New York")
|
||||||
|
|||||||
Reference in New Issue
Block a user