diff --git a/app/components/dashboard/polls_component.html.erb b/app/components/dashboard/polls_component.html.erb
new file mode 100644
index 000000000..68cb5b18a
--- /dev/null
+++ b/app/components/dashboard/polls_component.html.erb
@@ -0,0 +1,5 @@
+
+ <% polls.each do |poll| %>
+ <%= render Dashboard::PollComponent.new(poll) %>
+ <% end %>
+
diff --git a/app/components/dashboard/polls_component.rb b/app/components/dashboard/polls_component.rb
new file mode 100644
index 000000000..4dad2c277
--- /dev/null
+++ b/app/components/dashboard/polls_component.rb
@@ -0,0 +1,11 @@
+class Dashboard::PollsComponent < ApplicationComponent
+ attr_reader :polls
+
+ def initialize(polls)
+ @polls = polls
+ end
+
+ def render?
+ polls.any?
+ end
+end
diff --git a/app/views/dashboard/polls/index.html.erb b/app/views/dashboard/polls/index.html.erb
index ad362dd84..035874638 100644
--- a/app/views/dashboard/polls/index.html.erb
+++ b/app/views/dashboard/polls/index.html.erb
@@ -3,13 +3,7 @@
<%= Setting["proposals.poll_description"] %>
- <% if @polls.any? %>
-
- <% @polls.each do |poll| %>
- <%= render Dashboard::PollComponent.new(poll) %>
- <% end %>
-
- <% end %>
+ <%= render Dashboard::PollsComponent.new(@polls) %>
diff --git a/spec/components/dashboard/poll_component_spec.rb b/spec/components/dashboard/poll_component_spec.rb
index 101615e39..f31c7fd15 100644
--- a/spec/components/dashboard/poll_component_spec.rb
+++ b/spec/components/dashboard/poll_component_spec.rb
@@ -9,27 +9,13 @@ describe Dashboard::PollComponent do
describe "Poll card content" do
describe "actions visibility" do
- it "shows edit link for upcoming polls" do
- upcoming = create(:poll, related: proposal, starts_at: 1.week.from_now)
-
- render_inline Dashboard::PollComponent.new(upcoming)
-
- page.find("div#poll_#{upcoming.id}") do |poll_card|
- expect(poll_card).to have_link "Edit survey",
- href: edit_proposal_dashboard_poll_path(proposal, upcoming)
- expect(poll_card).not_to have_link "View results"
- end
- end
-
it "shows results link for current polls" do
current = create(:poll, related: proposal)
render_inline Dashboard::PollComponent.new(current)
- page.find("div#poll_#{current.id}") do |poll_card|
- expect(poll_card).not_to have_link "Edit survey"
- expect(poll_card).to have_link "View results", href: results_proposal_poll_path(proposal, current)
- end
+ expect(page).not_to have_link "Edit survey"
+ expect(page).to have_link "View results", href: results_proposal_poll_path(proposal, current)
end
it "shows results link for expired polls" do
@@ -37,10 +23,17 @@ describe Dashboard::PollComponent do
render_inline Dashboard::PollComponent.new(expired)
- page.find("div#poll_#{expired.id}") do |poll_card|
- expect(poll_card).not_to have_link "Edit survey"
- expect(poll_card).to have_link "View results", href: results_proposal_poll_path(proposal, expired)
- end
+ expect(page).not_to have_link "Edit survey"
+ expect(page).to have_link "View results", href: results_proposal_poll_path(proposal, expired)
+ end
+
+ it "shows edit link for upcoming polls" do
+ upcoming = create(:poll, related: proposal, starts_at: 1.week.from_now)
+
+ render_inline Dashboard::PollComponent.new(upcoming)
+
+ expect(page).to have_link "Edit survey", href: edit_proposal_dashboard_poll_path(proposal, upcoming)
+ expect(page).not_to have_link "View results"
end
end
@@ -49,12 +42,10 @@ describe Dashboard::PollComponent do
render_inline Dashboard::PollComponent.new(expired)
- page.find("div#poll_#{expired.id}") do |poll_card|
- expect(page).to have_content I18n.l(expired.starts_at.to_date)
- expect(page).to have_content I18n.l(expired.ends_at.to_date)
- expect(page).to have_link expired.title
- expect(page).to have_link expired.title, href: proposal_poll_path(proposal, expired)
- end
+ expect(page).to have_content I18n.l(expired.starts_at.to_date)
+ expect(page).to have_content I18n.l(expired.ends_at.to_date)
+ expect(page).to have_link expired.title
+ expect(page).to have_link expired.title, href: proposal_poll_path(proposal, expired)
end
end
end
diff --git a/spec/components/dashboard/polls_component_spec.rb b/spec/components/dashboard/polls_component_spec.rb
new file mode 100644
index 000000000..2ac73f65a
--- /dev/null
+++ b/spec/components/dashboard/polls_component_spec.rb
@@ -0,0 +1,9 @@
+require "rails_helper"
+
+describe Dashboard::PollsComponent do
+ it "is not rendered when there aren't any polls" do
+ render_inline Dashboard::PollsComponent.new(Poll.none)
+
+ expect(page).not_to be_rendered
+ end
+end