diff --git a/app/components/polls/geozones_component.html.erb b/app/components/polls/geozones_component.html.erb
new file mode 100644
index 000000000..09785642b
--- /dev/null
+++ b/app/components/polls/geozones_component.html.erb
@@ -0,0 +1,9 @@
+
+ <%= t("polls.index.geozone_info") %>
+
+
+
diff --git a/app/components/polls/geozones_component.rb b/app/components/polls/geozones_component.rb
new file mode 100644
index 000000000..75e982c0b
--- /dev/null
+++ b/app/components/polls/geozones_component.rb
@@ -0,0 +1,11 @@
+class Polls::GeozonesComponent < ApplicationComponent
+ attr_reader :poll
+
+ def initialize(poll)
+ @poll = poll
+ end
+
+ def render?
+ poll.geozones.any?
+ end
+end
diff --git a/app/components/polls/poll_component.html.erb b/app/components/polls/poll_component.html.erb
index 24594fc7e..110bef076 100644
--- a/app/components/polls/poll_component.html.erb
+++ b/app/components/polls/poll_component.html.erb
@@ -40,16 +40,7 @@
<% end %>
<% end %>
- <% if poll.geozones.any? %>
-
- <%= t("polls.index.geozone_info") %>
-
- <% end %>
-
+ <%= render Polls::GeozonesComponent.new(poll) %>
<%= render SDG::TagListComponent.new(poll, limit: 5, linkable: false) %>
diff --git a/app/components/polls/poll_header_component.html.erb b/app/components/polls/poll_header_component.html.erb
index c4b2e6cad..6058b9bcf 100644
--- a/app/components/polls/poll_header_component.html.erb
+++ b/app/components/polls/poll_header_component.html.erb
@@ -11,13 +11,7 @@
<%= auto_link_already_sanitized_html simple_format(poll.summary) %>
- <% if poll.geozones.any? %>
-
- <% end %>
+ <%= render Polls::GeozonesComponent.new(poll) %>
<%= render SDG::TagListComponent.new(poll, linkable: false) %>
diff --git a/spec/components/polls/poll_component_spec.rb b/spec/components/polls/poll_component_spec.rb
index 9cd5ea50a..a12041ff8 100644
--- a/spec/components/polls/poll_component_spec.rb
+++ b/spec/components/polls/poll_component_spec.rb
@@ -63,6 +63,20 @@ describe Polls::PollComponent do
end
end
+ describe "geozones" do
+ it "renders a list of geozones when the poll is geozone-restricted" do
+ render_inline Polls::PollComponent.new(create(:poll, geozone_restricted_to: [create(:geozone)]))
+
+ expect(page).to have_css ".tags"
+ end
+
+ it "does not render a list of geozones when the poll isn't geozone-restricted" do
+ render_inline Polls::PollComponent.new(create(:poll))
+
+ expect(page).not_to have_css ".tags"
+ end
+ end
+
it "shows a link to poll stats if enabled" do
poll = create(:poll, :expired, name: "Poll with stats", stats_enabled: true)
diff --git a/spec/components/polls/poll_header_component_spec.rb b/spec/components/polls/poll_header_component_spec.rb
new file mode 100644
index 000000000..6062a62ec
--- /dev/null
+++ b/spec/components/polls/poll_header_component_spec.rb
@@ -0,0 +1,17 @@
+require "rails_helper"
+
+describe Polls::PollHeaderComponent do
+ describe "geozones" do
+ it "shows a text when the poll is geozone-restricted" do
+ render_inline Polls::PollHeaderComponent.new(create(:poll, geozone_restricted_to: [create(:geozone)]))
+
+ expect(page).to have_content "Only residents in the following areas can participate"
+ end
+
+ it "does not show the text when the poll isn't geozone-restricted" do
+ render_inline Polls::PollHeaderComponent.new(create(:poll))
+
+ expect(page).not_to have_content "Only residents in the following areas can participate"
+ end
+ end
+end