diff --git a/app/assets/stylesheets/polls/access_status.scss b/app/assets/stylesheets/polls/access_status.scss
new file mode 100644
index 000000000..24391e76e
--- /dev/null
+++ b/app/assets/stylesheets/polls/access_status.scss
@@ -0,0 +1,55 @@
+.poll .access-status {
+ border-bottom: 60px solid transparent;
+ border-top: 0;
+ height: 0;
+ position: absolute;
+ right: 0;
+ top: 0;
+ width: 0;
+
+ &.cant-answer::after,
+ &.not-logged-in::after,
+ &.already-answer::after,
+ &.unverified::after {
+ font-family: "icons" !important;
+ left: 34px;
+ position: absolute;
+ top: 5px;
+ }
+
+ &.cant-answer {
+ border-right: 60px solid $alert-bg;
+
+ &::after {
+ color: $color-alert;
+ content: "\74";
+ }
+ }
+
+ &.not-logged-in {
+ border-right: 60px solid $info-bg;
+
+ &::after {
+ color: $color-info;
+ content: "\6f";
+ }
+ }
+
+ &.unverified {
+ border-right: 60px solid $warning-bg;
+
+ &::after {
+ color: $color-warning;
+ content: "\6f";
+ }
+ }
+
+ &.already-answer {
+ border-right: 60px solid $success-bg;
+
+ &::after {
+ color: $color-success;
+ content: "\59";
+ }
+ }
+}
diff --git a/app/assets/stylesheets/polls/poll.scss b/app/assets/stylesheets/polls/poll.scss
index 8e3446ef7..e97264af5 100644
--- a/app/assets/stylesheets/polls/poll.scss
+++ b/app/assets/stylesheets/polls/poll.scss
@@ -12,62 +12,6 @@
}
}
- .icon-poll-answer {
- border-bottom: 60px solid transparent;
- border-top: 0;
- height: 0;
- position: absolute;
- right: 0;
- top: 0;
- width: 0;
-
- &.cant-answer::after,
- &.not-logged-in::after,
- &.already-answer::after,
- &.unverified::after {
- font-family: "icons" !important;
- left: 34px;
- position: absolute;
- top: 5px;
- }
-
- &.cant-answer {
- border-right: 60px solid $alert-bg;
-
- &::after {
- color: $color-alert;
- content: "\74";
- }
- }
-
- &.not-logged-in {
- border-right: 60px solid $info-bg;
-
- &::after {
- color: $color-info;
- content: "\6f";
- }
- }
-
- &.unverified {
- border-right: 60px solid $warning-bg;
-
- &::after {
- color: $color-warning;
- content: "\6f";
- }
- }
-
- &.already-answer {
- border-right: 60px solid $success-bg;
-
- &::after {
- color: $color-success;
- content: "\59";
- }
- }
- }
-
.dates {
color: $text-medium;
font-size: $small-font-size;
diff --git a/app/components/polls/access_status_component.html.erb b/app/components/polls/access_status_component.html.erb
new file mode 100644
index 000000000..046094db9
--- /dev/null
+++ b/app/components/polls/access_status_component.html.erb
@@ -0,0 +1,19 @@
+<% if current_user %>
+ <% if current_user.unverified? %>
+
">
+ <%= t("polls.index.unverified") %>
+
+ <% elsif cannot?(:answer, poll) %>
+ ">
+ <%= t("polls.index.cant_answer") %>
+
+ <% elsif !poll.votable_by?(current_user) %>
+ ">
+ <%= t("polls.index.already_answer") %>
+
+ <% end %>
+<% else %>
+ ">
+ <%= t("polls.index.not_logged_in") %>
+
+<% end %>
diff --git a/app/components/polls/access_status_component.rb b/app/components/polls/access_status_component.rb
new file mode 100644
index 000000000..faf10512e
--- /dev/null
+++ b/app/components/polls/access_status_component.rb
@@ -0,0 +1,8 @@
+class Polls::AccessStatusComponent < ApplicationComponent
+ attr_reader :poll
+ use_helpers :cannot?, :current_user
+
+ def initialize(poll)
+ @poll = poll
+ end
+end
diff --git a/app/components/polls/poll_component.html.erb b/app/components/polls/poll_component.html.erb
index 110bef076..e290c9434 100644
--- a/app/components/polls/poll_component.html.erb
+++ b/app/components/polls/poll_component.html.erb
@@ -1,23 +1,6 @@
- <% if current_user %>
- <% if current_user.unverified? %>
-
">
- <%= t("polls.index.unverified") %>
-
- <% elsif cannot?(:answer, poll) %>
-
">
- <%= t("polls.index.cant_answer") %>
-
- <% elsif !poll.votable_by?(current_user) %>
-
">
- <%= t("polls.index.already_answer") %>
-
- <% end %>
- <% else %>
-
">
- <%= t("polls.index.not_logged_in") %>
-
- <% end %>
+ <%= render Polls::AccessStatusComponent.new(poll) %>
+
diff --git a/app/components/polls/poll_component.rb b/app/components/polls/poll_component.rb
index a1cda60ea..32b8b0b17 100644
--- a/app/components/polls/poll_component.rb
+++ b/app/components/polls/poll_component.rb
@@ -1,6 +1,6 @@
class Polls::PollComponent < ApplicationComponent
attr_reader :poll
- use_helpers :cannot?, :current_user, :link_to_poll
+ use_helpers :link_to_poll
def initialize(poll)
@poll = poll
diff --git a/spec/components/polls/access_status_component_spec.rb b/spec/components/polls/access_status_component_spec.rb
new file mode 100644
index 000000000..405f06049
--- /dev/null
+++ b/spec/components/polls/access_status_component_spec.rb
@@ -0,0 +1,40 @@
+require "rails_helper"
+
+describe Polls::AccessStatusComponent do
+ it "asks anonymous users to sign in" do
+ render_inline Polls::AccessStatusComponent.new(create(:poll))
+
+ expect(page).to have_css ".not-logged-in", count: 1
+ expect(page).to have_content "You must sign in or sign up to participate"
+ end
+
+ it "asks unverified users to verify their account" do
+ sign_in(create(:user))
+
+ render_inline Polls::AccessStatusComponent.new(create(:poll))
+
+ expect(page).to have_css ".unverified", count: 1
+ expect(page).to have_content "You must verify your account to participate"
+ end
+
+ it "tell users from different geozones that the poll isn't available" do
+ sign_in(create(:user, :level_two))
+
+ render_inline Polls::AccessStatusComponent.new(create(:poll, geozone_restricted: true))
+
+ expect(page).to have_css ".cant-answer", count: 1
+ expect(page).to have_content "This poll is not available on your geozone"
+ end
+
+ it "informs users when they've already participated" do
+ user = create(:user, :level_two)
+ poll = create(:poll)
+ create(:poll_voter, user: user, poll: poll)
+
+ sign_in(user)
+ render_inline Polls::AccessStatusComponent.new(poll)
+
+ expect(page).to have_css ".already-answer", count: 1
+ expect(page).to have_content "You already have participated in this poll"
+ end
+end
diff --git a/spec/components/polls/poll_component_spec.rb b/spec/components/polls/poll_component_spec.rb
index a12041ff8..4317ad2a8 100644
--- a/spec/components/polls/poll_component_spec.rb
+++ b/spec/components/polls/poll_component_spec.rb
@@ -3,45 +3,6 @@ require "rails_helper"
describe Polls::PollComponent do
include Rails.application.routes.url_helpers
- describe "status message" do
- it "asks anonymous users to sign in" do
- render_inline Polls::PollComponent.new(create(:poll))
-
- expect(page).to have_css ".not-logged-in", count: 1
- expect(page).to have_content "You must sign in or sign up to participate"
- end
-
- it "asks unverified users to verify their account" do
- sign_in(create(:user))
-
- render_inline Polls::PollComponent.new(create(:poll))
-
- expect(page).to have_css ".unverified", count: 1
- expect(page).to have_content "You must verify your account to participate"
- end
-
- it "tell users from different geozones that the poll isn't available" do
- sign_in(create(:user, :level_two))
-
- render_inline Polls::PollComponent.new(create(:poll, geozone_restricted: true))
-
- expect(page).to have_css ".cant-answer", count: 1
- expect(page).to have_content "This poll is not available on your geozone"
- end
-
- it "informs users when they've already participated" do
- user = create(:user, :level_two)
- poll = create(:poll)
- create(:poll_voter, user: user, poll: poll)
-
- sign_in(user)
- render_inline Polls::PollComponent.new(poll)
-
- expect(page).to have_css ".already-answer", count: 1
- expect(page).to have_content "You already have participated in this poll"
- end
- end
-
describe "dates" do
it "renders the dates inside an HTML tag" do
poll = create(:poll, starts_at: "2015-07-15", ends_at: "2015-07-22")