Rename variables describing poll options as answers

Since we've renamed the class to `Option`, having variables, methods and
texts refering to it as `answer` was confusing.
This commit is contained in:
Javi Martín
2024-06-07 17:27:56 +02:00
parent 38b38d1fcc
commit 8997ed316c
28 changed files with 123 additions and 123 deletions

View File

@@ -1,26 +1,26 @@
(function() { (function() {
"use strict"; "use strict";
App.Options = { App.Options = {
initializeOptions: function(answers) { initializeOptions: function(options) {
$(answers).on("cocoon:after-insert", function(e, new_answer) { $(options).on("cocoon:after-insert", function(e, new_option) {
var given_order; var given_order;
given_order = App.Options.maxGivenOrder(answers) + 1; given_order = App.Options.maxGivenOrder(options) + 1;
$(new_answer).find("[name$='[given_order]']").val(given_order); $(new_option).find("[name$='[given_order]']").val(given_order);
}); });
}, },
maxGivenOrder: function(answers) { maxGivenOrder: function(options) {
var max_order; var max_order;
max_order = 0; max_order = 0;
$(answers).find("[name$='[given_order]']").each(function(index, answer) { $(options).find("[name$='[given_order]']").each(function(index, option) {
var value; var value;
value = parseFloat($(answer).val()); value = parseFloat($(option).val());
max_order = value > max_order ? value : max_order; max_order = value > max_order ? value : max_order;
}); });
return max_order; return max_order;
}, },
nestedOptions: function() { nestedOptions: function() {
$(".js-answers").each(function(index, answers) { $(".js-answers").each(function(index, options) {
App.Options.initializeOptions(answers); App.Options.initializeOptions(options);
}); });
}, },
initialize: function() { initialize: function() {

View File

@@ -3,20 +3,20 @@
App.Polls = { App.Polls = {
initialize: function() { initialize: function() {
$(".zoom-link").on("click", function(event) { $(".zoom-link").on("click", function(event) {
var answer; var option;
answer = $(event.target).closest("div.answer"); option = $(event.target).closest("div.answer");
if ($(answer).hasClass("medium-6")) { if ($(option).hasClass("medium-6")) {
$(answer).removeClass("medium-6"); $(option).removeClass("medium-6");
$(answer).addClass("answer-divider"); $(option).addClass("answer-divider");
if (!$(answer).hasClass("first")) { if (!$(option).hasClass("first")) {
$(answer).insertBefore($(answer).prev("div.answer")); $(option).insertBefore($(option).prev("div.answer"));
} }
} else { } else {
$(answer).addClass("medium-6"); $(option).addClass("medium-6");
$(answer).removeClass("answer-divider"); $(option).removeClass("answer-divider");
if (!$(answer).hasClass("first")) { if (!$(option).hasClass("first")) {
$(answer).insertAfter($(answer).next("div.answer")); $(option).insertAfter($(option).next("div.answer"));
} }
} }
}); });

View File

@@ -89,7 +89,7 @@ class Admin::ActionComponent < ApplicationComponent
end end
def default_path def default_path
if %i[answers configure destroy preview show].include?(action.to_sym) if %i[configure destroy options preview show].include?(action.to_sym)
namespaced_polymorphic_path(namespace, record) namespaced_polymorphic_path(namespace, record)
else else
namespaced_polymorphic_path(namespace, record, { action: action }.merge(request.query_parameters)) namespaced_polymorphic_path(namespace, record, { action: action }.merge(request.query_parameters))

View File

@@ -1,3 +1,3 @@
<%= render Admin::AllowedTableActionsComponent.new(question) do |actions| %> <%= render Admin::AllowedTableActionsComponent.new(question) do |actions| %>
<%= actions.action(:answers, text: t("admin.polls.show.edit_answers")) %> <%= actions.action(:options, text: t("admin.polls.show.edit_answers")) %>
<% end %> <% end %>

View File

@@ -16,7 +16,7 @@
title: t("poll_questions.show.vote_answer", answer: question_option.title), title: t("poll_questions.show.vote_answer", answer: question_option.title),
class: "button secondary hollow", class: "button secondary hollow",
"aria-pressed": false, "aria-pressed": false,
disabled: disable_answer?(question_option) %> disabled: disable_option?(question_option) %>
<% end %> <% end %>
<% end %> <% end %>
<% elsif !user_signed_in? %> <% elsif !user_signed_in? %>

View File

@@ -18,7 +18,7 @@ class Polls::Questions::OptionsComponent < ApplicationComponent
user_answers.find_by(answer: question_option.title) user_answers.find_by(answer: question_option.title)
end end
def disable_answer?(question_option) def disable_option?(question_option)
question.multiple? && user_answers.count == question.max_votes question.multiple? && user_answers.count == question.max_votes
end end

View File

@@ -16,7 +16,7 @@
<% if question.options_with_read_more? %> <% if question.options_with_read_more? %>
<div> <div>
<p><%= t("poll_questions.read_more_about") %></p> <p><%= t("poll_questions.read_more_about") %></p>
<p><%= answers_read_more_links %></p> <p><%= options_read_more_links %></p>
</div> </div>
<% end %> <% end %>
</div> </div>

View File

@@ -5,9 +5,9 @@ class Polls::Questions::QuestionComponent < ApplicationComponent
@question = question @question = question
end end
def answers_read_more_links def options_read_more_links
safe_join(question.options_with_read_more.map do |answer| safe_join(question.options_with_read_more.map do |option|
link_to answer.title, "#answer_#{answer.id}" link_to option.title, "#answer_#{option.id}"
end, ", ") end, ", ")
end end
end end

View File

@@ -1,52 +1,52 @@
<h2><%= question.title %></h2> <h2><%= question.title %></h2>
<% question.options_with_read_more.each do |answer| %> <% question.options_with_read_more.each do |option| %>
<div class="small-12 medium-6 column end answer <%= cycle("first", "") %>" id="answer_<%= answer.id %>"> <div class="small-12 medium-6 column end answer <%= cycle("first", "") %>" id="answer_<%= option.id %>">
<h3><%= answer.title %></h3> <h3><%= option.title %></h3>
<div class="margin-top"> <div class="margin-top">
<% if answer.description.present? %> <% if option.description.present? %>
<div id="answer_description_<%= answer.id %>" class="answer-description short" data-toggler="short"> <div id="answer_description_<%= option.id %>" class="answer-description short" data-toggler="short">
<%= wysiwyg(answer.description) %> <%= wysiwyg(option.description) %>
</div> </div>
<div class="read-more"> <div class="read-more">
<button type="button" id="read_more_<%= answer.id %>" <button type="button" id="read_more_<%= option.id %>"
data-toggle="answer_description_<%= answer.id %> read_more_<%= answer.id %> read_less_<%= answer.id %>" data-toggle="answer_description_<%= option.id %> read_more_<%= option.id %> read_less_<%= option.id %>"
data-toggler="hide"> data-toggler="hide">
<%= t("polls.show.read_more", answer: answer.title) %> <%= t("polls.show.read_more", answer: option.title) %>
</button> </button>
<button type="button" id="read_less_<%= answer.id %>" <button type="button" id="read_less_<%= option.id %>"
data-toggle="answer_description_<%= answer.id %> read_more_<%= answer.id %> read_less_<%= answer.id %>" data-toggle="answer_description_<%= option.id %> read_more_<%= option.id %> read_less_<%= option.id %>"
data-toggler="hide" data-toggler="hide"
class="hide"> class="hide">
<%= t("polls.show.read_less", answer: answer.title) %> <%= t("polls.show.read_less", answer: option.title) %>
</button> </button>
</div> </div>
<% end %> <% end %>
<% if answer.images.any? %> <% if option.images.any? %>
<%= render "polls/gallery", answer: answer %> <%= render "polls/gallery", option: option %>
<% end %> <% end %>
<% if answer.documents.present? %> <% if option.documents.present? %>
<div class="document-link"> <div class="document-link">
<p> <p>
<strong><%= t("polls.show.documents") %></strong> <strong><%= t("polls.show.documents") %></strong>
</p> </p>
<% answer.documents.each do |document| %> <% option.documents.each do |document| %>
<%= render Documents::DocumentComponent.new(document) %> <%= render Documents::DocumentComponent.new(document) %>
<% end %> <% end %>
</div> </div>
<% end %> <% end %>
<% if answer.videos.present? %> <% if option.videos.present? %>
<div class="video-link"> <div class="video-link">
<p> <p>
<span class="icon-video"></span>&nbsp; <span class="icon-video"></span>&nbsp;
<strong><%= t("polls.show.videos") %></strong> <strong><%= t("polls.show.videos") %></strong>
</p> </p>
<% answer.videos.each do |video| %> <% option.videos.each do |video| %>
<%= link_to video.title, <%= link_to video.title,
video.url, video.url,
rel: "nofollow" %><br> rel: "nofollow" %><br>

View File

@@ -2,22 +2,22 @@
<table id="question_<%= question.id %>_results_table"> <table id="question_<%= question.id %>_results_table">
<thead> <thead>
<tr> <tr>
<%- question.question_options.each do |answer| %> <%- question.question_options.each do |option| %>
<th scope="col" class="<%= answer_styles(answer) %>"> <th scope="col" class="<%= option_styles(option) %>">
<% if most_voted_answer?(answer) %> <% if most_voted_option?(option) %>
<span class="show-for-sr"><%= t("polls.show.results.most_voted_answer") %></span> <span class="show-for-sr"><%= t("polls.show.results.most_voted_answer") %></span>
<% end %> <% end %>
<%= answer.title %> <%= option.title %>
</th> </th>
<% end %> <% end %>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<%- question.question_options.each do |answer| %> <%- question.question_options.each do |option| %>
<td id="answer_<%= answer.id %>_result" class="<%= answer_styles(answer) %>"> <td id="answer_<%= option.id %>_result" class="<%= option_styles(option) %>">
<%= answer.total_votes %> <%= option.total_votes %>
(<%= answer.total_votes_percentage.round(2) %>%) (<%= option.total_votes_percentage.round(2) %>%)
</td> </td>
<% end %> <% end %>
</tr> </tr>

View File

@@ -5,11 +5,11 @@ class Polls::Results::QuestionComponent < ApplicationComponent
@question = question @question = question
end end
def answer_styles(answer) def option_styles(option)
"win" if most_voted_answer?(answer) "win" if most_voted_option?(option)
end end
def most_voted_answer?(answer) def most_voted_option?(option)
answer.id == question.most_voted_option_id option.id == question.most_voted_option_id
end end
end end

View File

@@ -8,11 +8,11 @@ module OfficingHelper
options_for_select(options, params[:oa]) options_for_select(options, params[:oa])
end end
def answer_result_value(question_id, answer_index) def answer_result_value(question_id, option_index)
return nil if params.blank? return nil if params.blank?
return nil if params[:questions].blank? return nil if params[:questions].blank?
return nil if params[:questions][question_id.to_s].blank? return nil if params[:questions][question_id.to_s].blank?
params[:questions][question_id.to_s][answer_index.to_s] params[:questions][question_id.to_s][option_index.to_s]
end end
end end

View File

@@ -26,7 +26,7 @@
</td> </td>
<td> <td>
<%= render Admin::TableActionsComponent.new(question) do |actions| %> <%= render Admin::TableActionsComponent.new(question) do |actions| %>
<%= actions.action(:answers, text: t("admin.polls.show.edit_answers")) %> <%= actions.action(:options, text: t("admin.polls.show.edit_answers")) %>
<% end %> <% end %>
</td> </td>
</tr> </tr>

View File

@@ -71,30 +71,30 @@
</thead> </thead>
<tbody class="sortable" data-js-url="<%= admin_question_options_order_options_path(@question.id) %>"> <tbody class="sortable" data-js-url="<%= admin_question_options_order_options_path(@question.id) %>">
<% @question.question_options.each do |answer| %> <% @question.question_options.each do |option| %>
<tr id="<%= dom_id(answer) %>" class="poll_question_answer" data-answer-id="<%= answer.id %>"> <tr id="<%= dom_id(option) %>" class="poll_question_answer" data-answer-id="<%= option.id %>">
<td class="align-top"><%= answer.title %></td> <td class="align-top"><%= option.title %></td>
<td class="align-top break"><%= wysiwyg(answer.description) %></td> <td class="align-top break"><%= wysiwyg(option.description) %></td>
<td class="align-top text-center"> <td class="align-top text-center">
(<%= answer.images.count %>) (<%= option.images.count %>)
<br> <br>
<%= link_to t("admin.questions.show.answers.images_list"), <%= link_to t("admin.questions.show.answers.images_list"),
admin_option_images_path(answer) %> admin_option_images_path(option) %>
</td> </td>
<td class="align-top text-center"> <td class="align-top text-center">
(<%= answer.documents.count rescue 0 %>) (<%= option.documents.count rescue 0 %>)
<br> <br>
<%= link_to t("admin.questions.show.answers.documents_list"), <%= link_to t("admin.questions.show.answers.documents_list"),
admin_option_documents_path(answer) %> admin_option_documents_path(option) %>
</td> </td>
<td class="align-top text-center"> <td class="align-top text-center">
(<%= answer.videos.count %>) (<%= option.videos.count %>)
<br> <br>
<%= link_to t("admin.questions.show.answers.video_list"), <%= link_to t("admin.questions.show.answers.video_list"),
admin_option_videos_path(answer) %> admin_option_videos_path(option) %>
</td> </td>
<td> <td>
<%= render Admin::Poll::Questions::Options::TableActionsComponent.new(answer) %> <%= render Admin::Poll::Questions::Options::TableActionsComponent.new(option) %>
</td> </td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -13,8 +13,8 @@
</div> </div>
<div class="js-answers"> <div class="js-answers">
<%= f.fields_for :question_options do |answer| %> <%= f.fields_for :question_options do |option_form| %>
<%= render "question_option_fields", f: answer %> <%= render "question_option_fields", f: option_form %>
<% end %> <% end %>
<div class="answer-links links row expanded"> <div class="answer-links links row expanded">

View File

@@ -16,9 +16,9 @@
<div class="small-12 column"> <div class="small-12 column">
<h3><%= question.title %></h3> <h3><%= question.title %></h3>
</div> </div>
<% question.question_options.each_with_index do |answer, i| %> <% question.question_options.each_with_index do |option, i| %>
<div class="small-12 medium-6 large-3 column end"> <div class="small-12 medium-6 large-3 column end">
<label><%= answer.title %></label> <label><%= option.title %></label>
<%= text_field_tag "questions[#{question.id}][#{i}]", answer_result_value(question.id, i), placeholder: "0" %> <%= text_field_tag "questions[#{question.id}][#{i}]", answer_result_value(question.id, i), placeholder: "0" %>
</div> </div>
<% end %> <% end %>

View File

@@ -1,6 +1,6 @@
<div class="orbit margin-bottom" role="region" aria-label="<%= answer.title %>" data-orbit data-auto-play="false" data-use-m-u-i="false"> <div class="orbit margin-bottom" role="region" aria-label="<%= option.title %>" data-orbit data-auto-play="false" data-use-m-u-i="false">
<button type="button" data-toggle="answer_<%= answer.id %> zoom_<%= answer.id %>" class="zoom-link hide-for-small-only"> <button type="button" data-toggle="answer_<%= option.id %> zoom_<%= option.id %>" class="zoom-link hide-for-small-only">
<span id="zoom_<%= answer.id %>" class="icon-search-plus" data-toggler="icon-search-plus icon-search-minus"></span> <span id="zoom_<%= option.id %>" class="icon-search-plus" data-toggler="icon-search-plus icon-search-minus"></span>
<span class="show-for-sr"><%= t("polls.show.zoom_plus") %></span> <span class="show-for-sr"><%= t("polls.show.zoom_plus") %></span>
</button> </button>
@@ -16,7 +16,7 @@
</button> </button>
</li> </li>
<% answer.images.reverse.each_with_index do |image, index| %> <% option.images.reverse.each_with_index do |image, index| %>
<li class="orbit-slide <%= is_active_class(index) %>"> <li class="orbit-slide <%= is_active_class(index) %>">
<%= link_to image.attachment do %> <%= link_to image.attachment do %>
<%= image_tag image.attachment, <%= image_tag image.attachment,
@@ -30,7 +30,7 @@
</ul> </ul>
<nav class="orbit-bullets"> <nav class="orbit-bullets">
<% answer.images.each_with_index do |image, index| %> <% option.images.each_with_index do |image, index| %>
<button class="<%= is_active_class(index) %>" data-slide="<%= index %>"> <button class="<%= is_active_class(index) %>" data-slide="<%= index %>">
<span class="show-for-sr"><%= image.title.unicode_normalize %></span> <span class="show-for-sr"><%= image.title.unicode_normalize %></span>
</button> </button>

View File

@@ -49,7 +49,7 @@ section "Creating polls" do
end end
end end
section "Creating Poll Questions & Answers" do section "Creating Poll Questions & Options" do
Poll.find_each do |poll| Poll.find_each do |poll|
(3..5).to_a.sample.times do (3..5).to_a.sample.times do
question_title = Faker::Lorem.sentence(word_count: 3).truncate(60) + "?" question_title = Faker::Lorem.sentence(word_count: 3).truncate(60) + "?"
@@ -210,12 +210,12 @@ section "Creating Poll Results" do
author = Poll::Officer.first.user author = Poll::Officer.first.user
poll.questions.each do |question| poll.questions.each do |question|
question.question_options.each do |answer| question.question_options.each do |option|
Poll::PartialResult.create!(officer_assignment: officer_assignment, Poll::PartialResult.create!(officer_assignment: officer_assignment,
booth_assignment: booth_assignment, booth_assignment: booth_assignment,
date: Date.current, date: Date.current,
question: question, question: question,
answer: answer.title, answer: option.title,
author: author, author: author,
amount: rand(999), amount: rand(999),
origin: "booth") origin: "booth")

View File

@@ -2,17 +2,17 @@ require "rails_helper"
describe Admin::Poll::Questions::Options::Documents::IndexComponent do describe Admin::Poll::Questions::Options::Documents::IndexComponent do
before { sign_in(create(:administrator).user) } before { sign_in(create(:administrator).user) }
let(:future_answer) { create(:poll_question_option, poll: create(:poll, :future)) } let(:future_option) { create(:poll_question_option, poll: create(:poll, :future)) }
let(:current_answer) { create(:poll_question_option, poll: create(:poll)) } let(:current_option) { create(:poll_question_option, poll: create(:poll)) }
it "displays the 'Add new document' link when the poll has not started" do it "displays the 'Add new document' link when the poll has not started" do
render_inline Admin::Poll::Questions::Options::Documents::IndexComponent.new(future_answer) render_inline Admin::Poll::Questions::Options::Documents::IndexComponent.new(future_option)
expect(page).to have_link "Add new document" expect(page).to have_link "Add new document"
end end
it "does not display the 'Add new document' link when the poll has started" do it "does not display the 'Add new document' link when the poll has started" do
render_inline Admin::Poll::Questions::Options::Documents::IndexComponent.new(current_answer) render_inline Admin::Poll::Questions::Options::Documents::IndexComponent.new(current_option)
expect(page).not_to have_link "Add new document" expect(page).not_to have_link "Add new document"
end end

View File

@@ -1,11 +1,11 @@
require "rails_helper" require "rails_helper"
describe Admin::Poll::Questions::Options::Documents::TableActionsComponent, :admin do describe Admin::Poll::Questions::Options::Documents::TableActionsComponent, :admin do
let(:future_answer) { create(:poll_question_option, poll: create(:poll, :future)) } let(:future_option) { create(:poll_question_option, poll: create(:poll, :future)) }
let(:current_answer) { create(:poll_question_option, poll: create(:poll)) } let(:current_option) { create(:poll_question_option, poll: create(:poll)) }
it "displays the destroy action when the poll has not started" do it "displays the destroy action when the poll has not started" do
document = create(:document, documentable: future_answer) document = create(:document, documentable: future_option)
render_inline Admin::Poll::Questions::Options::Documents::TableActionsComponent.new(document) render_inline Admin::Poll::Questions::Options::Documents::TableActionsComponent.new(document)
@@ -15,7 +15,7 @@ describe Admin::Poll::Questions::Options::Documents::TableActionsComponent, :adm
end end
it "does not display the destroy action when the poll has started" do it "does not display the destroy action when the poll has started" do
document = create(:document, documentable: current_answer) document = create(:document, documentable: current_option)
render_inline Admin::Poll::Questions::Options::Documents::TableActionsComponent.new(document) render_inline Admin::Poll::Questions::Options::Documents::TableActionsComponent.new(document)

View File

@@ -1,18 +1,18 @@
require "rails_helper" require "rails_helper"
describe Polls::Questions::QuestionComponent do describe Polls::Questions::QuestionComponent do
it "renders more information links when any question answer has additional information" do it "renders more information links when any question option has additional information" do
question = create(:poll_question) question = create(:poll_question)
answer_a = create(:poll_question_option, question: question, title: "Answer A") option_a = create(:poll_question_option, question: question, title: "Answer A")
answer_b = create(:poll_question_option, question: question, title: "Answer B") option_b = create(:poll_question_option, question: question, title: "Answer B")
allow_any_instance_of(Poll::Question::Option).to receive(:with_read_more?).and_return(true) allow_any_instance_of(Poll::Question::Option).to receive(:with_read_more?).and_return(true)
render_inline Polls::Questions::QuestionComponent.new(question: question) render_inline Polls::Questions::QuestionComponent.new(question: question)
poll_question = page.find("#poll_question_#{question.id}") poll_question = page.find("#poll_question_#{question.id}")
expect(poll_question).to have_content("Read more about") expect(poll_question).to have_content("Read more about")
expect(poll_question).to have_link("Answer A", href: "#answer_#{answer_a.id}") expect(poll_question).to have_link("Answer A", href: "#answer_#{option_a.id}")
expect(poll_question).to have_link("Answer B", href: "#answer_#{answer_b.id}") expect(poll_question).to have_link("Answer B", href: "#answer_#{option_b.id}")
expect(poll_question).to have_content("Answer A, Answer B") expect(poll_question).to have_content("Answer A, Answer B")
end end
end end

View File

@@ -2,12 +2,12 @@ require "rails_helper"
describe DocumentsController do describe DocumentsController do
describe "DELETE destroy" do describe "DELETE destroy" do
context "Poll answers administration", :admin do context "Poll options administration", :admin do
let(:current_answer) { create(:poll_question_option, poll: create(:poll)) } let(:current_option) { create(:poll_question_option, poll: create(:poll)) }
let(:future_answer) { create(:poll_question_option, poll: create(:poll, :future)) } let(:future_option) { create(:poll_question_option, poll: create(:poll, :future)) }
it "is not possible for an already started poll" do it "is not possible for an already started poll" do
document = create(:document, documentable: current_answer) document = create(:document, documentable: current_option)
delete :destroy, params: { id: document } delete :destroy, params: { id: document }
expect(flash[:alert]).to eq "You do not have permission to " \ expect(flash[:alert]).to eq "You do not have permission to " \
@@ -16,11 +16,11 @@ describe DocumentsController do
end end
it "is possible for a not started poll" do it "is possible for a not started poll" do
document = create(:document, documentable: future_answer) document = create(:document, documentable: future_option)
request.env["HTTP_REFERER"] = admin_option_documents_path(future_answer) request.env["HTTP_REFERER"] = admin_option_documents_path(future_option)
delete :destroy, params: { id: document } delete :destroy, params: { id: document }
expect(response).to redirect_to admin_option_documents_path(future_answer) expect(response).to redirect_to admin_option_documents_path(future_option)
expect(flash[:notice]).to eq "Document was deleted successfully." expect(flash[:notice]).to eq "Document was deleted successfully."
expect(Document.count).to eq 0 expect(Document.count).to eq 0
end end

View File

@@ -114,7 +114,7 @@ describe "Polymorphic routes" do
expect(admin_polymorphic_path(question)).to eq(admin_question_path(question)) expect(admin_polymorphic_path(question)).to eq(admin_question_path(question))
end end
it "routes poll answer videos" do it "routes poll option videos" do
video = create(:poll_option_video) video = create(:poll_option_video)
expect(admin_polymorphic_path(video)).to eq admin_option_video_path(video.option, video) expect(admin_polymorphic_path(video)).to eq admin_option_video_path(video.option, video)

View File

@@ -1,12 +1,12 @@
module Polls module Polls
def vote_for_poll_via_web(poll, question, answer) def vote_for_poll_via_web(poll, question, option)
visit poll_path(poll) visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_answers") do
click_button answer click_button option
expect(page).to have_button("You have voted #{answer}") expect(page).to have_button("You have voted #{option}")
expect(page).not_to have_button("Vote #{answer}") expect(page).not_to have_button("Vote #{option}")
end end
end end

View File

@@ -119,7 +119,7 @@ describe "Admin polls", :admin do
expect(page).to have_content("There are no polls.") expect(page).to have_content("There are no polls.")
end end
scenario "Can destroy poll with questions and answers" do scenario "Can destroy poll with questions and options" do
poll = create(:poll, name: "Do you support CONSUL?") poll = create(:poll, name: "Do you support CONSUL?")
create(:poll_question, :yes_no, poll: poll) create(:poll_question, :yes_no, poll: poll)

View File

@@ -166,7 +166,7 @@ describe "Polls" do
expect(page).to have_css ".nested-fields", count: 1 expect(page).to have_css ".nested-fields", count: 1
end end
scenario "Edit poll allows users to remove answers" do scenario "Edit poll allows users to remove options" do
poll = create(:poll, related: proposal, starts_at: 1.week.from_now) poll = create(:poll, related: proposal, starts_at: 1.week.from_now)
create(:poll_question, :yes_no, poll: poll) create(:poll_question, :yes_no, poll: poll)
visit proposal_dashboard_polls_path(proposal) visit proposal_dashboard_polls_path(proposal)

View File

@@ -11,7 +11,7 @@ describe "Poll Questions" do
expect(proposal_question.title).to appear_before(normal_question.title) expect(proposal_question.title).to appear_before(normal_question.title)
end end
scenario "shows answers with an image and no description" do scenario "shows options with an image and no description" do
poll = create(:poll) poll = create(:poll)
option = create(:poll_question_option, poll: poll, title: "Pedestrian road", description: "") option = create(:poll_question_option, poll: poll, title: "Pedestrian road", description: "")
create(:image, imageable: option, title: "Trees on both sides of the road") create(:image, imageable: option, title: "Trees on both sides of the road")

View File

@@ -8,13 +8,13 @@ describe "Poll Results" do
poll = create(:poll, results_enabled: true) poll = create(:poll, results_enabled: true)
question1 = create(:poll_question, poll: poll) question1 = create(:poll_question, poll: poll)
answer1 = create(:poll_question_option, question: question1, title: "Yes") option1 = create(:poll_question_option, question: question1, title: "Yes")
answer2 = create(:poll_question_option, question: question1, title: "No") option2 = create(:poll_question_option, question: question1, title: "No")
question2 = create(:poll_question, poll: poll) question2 = create(:poll_question, poll: poll)
answer3 = create(:poll_question_option, question: question2, title: "Blue") option3 = create(:poll_question_option, question: question2, title: "Blue")
answer4 = create(:poll_question_option, question: question2, title: "Green") option4 = create(:poll_question_option, question: question2, title: "Green")
answer5 = create(:poll_question_option, question: question2, title: "Yellow") option5 = create(:poll_question_option, question: question2, title: "Yellow")
login_as user1 login_as user1
vote_for_poll_via_web(poll, question1, "Yes") vote_for_poll_via_web(poll, question1, "Yes")
@@ -39,18 +39,18 @@ describe "Poll Results" do
expect(page).to have_content(question2.title) expect(page).to have_content(question2.title)
within("#question_#{question1.id}_results_table") do within("#question_#{question1.id}_results_table") do
expect(find("#answer_#{answer1.id}_result")).to have_content("2 (66.67%)") expect(find("#answer_#{option1.id}_result")).to have_content("2 (66.67%)")
expect(find("#answer_#{answer2.id}_result")).to have_content("1 (33.33%)") expect(find("#answer_#{option2.id}_result")).to have_content("1 (33.33%)")
end end
within("#question_#{question2.id}_results_table") do within("#question_#{question2.id}_results_table") do
expect(find("#answer_#{answer3.id}_result")).to have_content("1 (33.33%)") expect(find("#answer_#{option3.id}_result")).to have_content("1 (33.33%)")
expect(find("#answer_#{answer4.id}_result")).to have_content("1 (33.33%)") expect(find("#answer_#{option4.id}_result")).to have_content("1 (33.33%)")
expect(find("#answer_#{answer5.id}_result")).to have_content("1 (33.33%)") expect(find("#answer_#{option5.id}_result")).to have_content("1 (33.33%)")
end end
end end
scenario "Results for polls with questions but without answers" do scenario "Results for polls with questions but without options" do
poll = create(:poll, :expired, results_enabled: true) poll = create(:poll, :expired, results_enabled: true)
question = create(:poll_question, poll: poll) question = create(:poll_question, poll: poll)