Move poll callout partial to a component
This way it'll be easier to refactor it. Note there was a system test which tested both the callout and the form when unverified users visit a poll. We've split this system test in two component tests.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<% unless can?(:answer, @poll) %>
|
<% unless can?(:answer, poll) %>
|
||||||
<% if current_user.nil? %>
|
<% if current_user.nil? %>
|
||||||
<div class="callout primary">
|
<div class="callout primary">
|
||||||
<%= sanitize(t("polls.show.cant_answer_not_logged_in",
|
<%= sanitize(t("polls.show.cant_answer_not_logged_in",
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
<%= sanitize(t("polls.show.cant_answer_verify",
|
<%= sanitize(t("polls.show.cant_answer_verify",
|
||||||
verify_link: link_to(t("polls.show.verify_link"), verification_path))) %>
|
verify_link: link_to(t("polls.show.verify_link"), verification_path))) %>
|
||||||
</div>
|
</div>
|
||||||
<% elsif @poll.expired? %>
|
<% elsif poll.expired? %>
|
||||||
<div class="callout alert">
|
<div class="callout alert">
|
||||||
<%= t("polls.show.cant_answer_expired") %>
|
<%= t("polls.show.cant_answer_expired") %>
|
||||||
</div>
|
</div>
|
||||||
8
app/components/polls/callout_component.rb
Normal file
8
app/components/polls/callout_component.rb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
class Polls::CalloutComponent < ApplicationComponent
|
||||||
|
attr_reader :poll
|
||||||
|
use_helpers :can?, :current_user, :link_to_signin, :link_to_signup
|
||||||
|
|
||||||
|
def initialize(poll)
|
||||||
|
@poll = poll
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
<div class="row margin">
|
<div class="row margin">
|
||||||
<div class="small-12 medium-9 column">
|
<div class="small-12 medium-9 column">
|
||||||
<%= render "callout" %>
|
<%= render Polls::CalloutComponent.new(@poll) %>
|
||||||
|
|
||||||
<% if @poll.voted_in_booth?(current_user) %>
|
<% if @poll.voted_in_booth?(current_user) %>
|
||||||
<div class="callout warning">
|
<div class="callout warning">
|
||||||
|
|||||||
27
spec/components/polls/callout_component_spec.rb
Normal file
27
spec/components/polls/callout_component_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Polls::CalloutComponent do
|
||||||
|
it "asks anonymous users to sign in" do
|
||||||
|
render_inline Polls::CalloutComponent.new(create(:poll))
|
||||||
|
|
||||||
|
expect(page).to have_content "You must sign in or sign up to participate"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "shows a message to level 2 users when a poll has finished" do
|
||||||
|
sign_in(create(:user, :level_two))
|
||||||
|
|
||||||
|
render_inline Polls::CalloutComponent.new(create(:poll, :expired))
|
||||||
|
|
||||||
|
expect(page).to have_content "This poll has finished"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "asks unverified users to verify their account" do
|
||||||
|
sign_in(create(:user, :incomplete_verification))
|
||||||
|
|
||||||
|
render_inline Polls::CalloutComponent.new(create(:poll))
|
||||||
|
|
||||||
|
expect(page).to have_content "You must verify your account in order to answer"
|
||||||
|
expect(page).not_to have_content "You have already participated in this poll. " \
|
||||||
|
"If you vote again it will be overwritten"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -20,6 +20,19 @@ describe Polls::FormComponent do
|
|||||||
expect(page).to have_button "Vote", disabled: true
|
expect(page).to have_button "Vote", disabled: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "renders disabled answers to unverified users" do
|
||||||
|
sign_in(create(:user, :incomplete_verification))
|
||||||
|
|
||||||
|
render_inline Polls::FormComponent.new(web_vote)
|
||||||
|
|
||||||
|
page.find("fieldset[disabled]") do |fieldset|
|
||||||
|
expect(fieldset).to have_field "Yes"
|
||||||
|
expect(fieldset).to have_field "No"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_button "Vote", disabled: true
|
||||||
|
end
|
||||||
|
|
||||||
context "expired poll" do
|
context "expired poll" do
|
||||||
let(:poll) { create(:poll, :expired) }
|
let(:poll) { create(:poll, :expired) }
|
||||||
|
|
||||||
|
|||||||
@@ -168,14 +168,6 @@ describe "Polls" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Non-logged in users" do
|
|
||||||
create(:poll_question, :yes_no, poll: poll)
|
|
||||||
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
expect(page).to have_content("You must sign in or sign up to participate")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Level 1 users" do
|
scenario "Level 1 users" do
|
||||||
poll.update!(geozone_restricted_to: [geozone])
|
poll.update!(geozone_restricted_to: [geozone])
|
||||||
create(:poll_question, :yes_no, poll: poll)
|
create(:poll_question, :yes_no, poll: poll)
|
||||||
@@ -186,17 +178,6 @@ describe "Polls" do
|
|||||||
expect(page).to have_content("You must verify your account in order to answer")
|
expect(page).to have_content("You must verify your account in order to answer")
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Level 2 users in an expired poll" do
|
|
||||||
expired_poll = create(:poll, :expired)
|
|
||||||
create(:poll_question, :yes_no, poll: expired_poll)
|
|
||||||
|
|
||||||
login_as(create(:user, :level_two, geozone: geozone))
|
|
||||||
|
|
||||||
visit poll_path(expired_poll)
|
|
||||||
|
|
||||||
expect(page).to have_content("This poll has finished")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Level 2 users answering" do
|
scenario "Level 2 users answering" do
|
||||||
poll.update!(geozone_restricted_to: [geozone])
|
poll.update!(geozone_restricted_to: [geozone])
|
||||||
create(:poll_question, :yes_no, poll: poll, title: "Do you agree?")
|
create(:poll_question, :yes_no, poll: poll, title: "Do you agree?")
|
||||||
|
|||||||
@@ -28,22 +28,6 @@ describe "Voter" do
|
|||||||
"If you vote again it will be overwritten."
|
"If you vote again it will be overwritten."
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Voting via web as unverified user" do
|
|
||||||
user = create(:user, :incomplete_verification)
|
|
||||||
|
|
||||||
login_as user
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
within_fieldset "Is this question stupid?" do
|
|
||||||
expect(page).to have_field "Yes", type: :radio, disabled: true
|
|
||||||
expect(page).to have_field "No", type: :radio, disabled: true
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "You must verify your account in order to answer"
|
|
||||||
expect(page).not_to have_content "You have already participated in this poll. " \
|
|
||||||
"If you vote again it will be overwritten"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Voting in booth" do
|
scenario "Voting in booth" do
|
||||||
admin_user = admin.user
|
admin_user = admin.user
|
||||||
login_through_form_as_officer(officer)
|
login_through_form_as_officer(officer)
|
||||||
|
|||||||
Reference in New Issue
Block a user