adds specs for answer's index and create
This commit is contained in:
@@ -11,7 +11,8 @@ class Admin::Poll::AnswersController < Admin::Poll::BaseController
|
||||
@answer = Poll::QuestionAnswer.new(answer_params)
|
||||
|
||||
if @answer.save
|
||||
redirect_to admin_question_path(@question)
|
||||
redirect_to admin_question_path(@question),
|
||||
notice: t("flash.actions.create.poll_question_answer")
|
||||
else
|
||||
render :new
|
||||
end
|
||||
|
||||
@@ -26,21 +26,27 @@
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th colspan="1" scope="colgroup"><%= t('admin.questions.show.valid_answers') %></th>
|
||||
<th colspan="1" scope="colgroup"><%= link_to t("admin.questions.show.add_answer"), new_admin_question_answer_path(@question), class: "button hollow float-right" %></th>
|
||||
<th colspan="1" scope="colgroup">
|
||||
<%= t('admin.questions.show.valid_answers') %>
|
||||
</th>
|
||||
<th colspan="1" scope="colgroup">
|
||||
<%= link_to t("admin.questions.show.add_answer"),
|
||||
new_admin_question_answer_path(@question),
|
||||
class: "button hollow float-right" %>
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="col"><%= t("admin.questions.show.answer") %></th>
|
||||
<th scope="col"><%= t("admin.questions.show.description") %></th>
|
||||
<th scope="col"><%= t("admin.questions.show.answers.title") %></th>
|
||||
<th scope="col"><%= t("admin.questions.show.answers.description") %></th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<% @question.question_answers.each do |answer| %>
|
||||
<% @question.question_answers.each do |answer| %>
|
||||
<tr id="<%= dom_id(answer) %>" class="poll_question_answer">
|
||||
<th scope="col"><%= answer.title %></th>
|
||||
<th scope="col"><%= answer.description %></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<% if @question.video_url.present? %>
|
||||
|
||||
@@ -593,10 +593,12 @@ en:
|
||||
title: Title
|
||||
valid_answers: Valid answers
|
||||
add_answer: "Add answer"
|
||||
answer: "Answer"
|
||||
description: Description
|
||||
video_url: External video
|
||||
documents: Documents (1)
|
||||
answers:
|
||||
title: Answer
|
||||
description: Description
|
||||
answers:
|
||||
new:
|
||||
title: "New answer"
|
||||
|
||||
@@ -8,6 +8,7 @@ en:
|
||||
direct_message: "You message has been sent successfully."
|
||||
poll: "Poll created successfully."
|
||||
poll_booth: "Booth created successfully."
|
||||
poll_question_answer: "Answer created successfully"
|
||||
proposal: "Proposal created successfully."
|
||||
proposal_notification: "Your message has been sent correctly."
|
||||
spending_proposal: "Spending proposal created successfully. You can access it from %{activity}"
|
||||
|
||||
@@ -593,11 +593,13 @@ es:
|
||||
title: Título
|
||||
valid_answers: Respuestas válidas
|
||||
add_answer: "Añadir respuesta"
|
||||
answer: "Respuesta"
|
||||
description: Descripción
|
||||
video_url: Video externo
|
||||
documents: Documentos (1)
|
||||
preview: Ver en la web
|
||||
answers:
|
||||
title: Respuesta
|
||||
description: Descripción
|
||||
answers:
|
||||
new:
|
||||
title: "Nueva respuesta"
|
||||
|
||||
@@ -8,6 +8,7 @@ es:
|
||||
direct_message: "Tu mensaje ha sido enviado correctamente."
|
||||
poll: "Votación creada correctamente."
|
||||
poll_booth: "Urna creada correctamente."
|
||||
poll_question_answer: "Respuesta creada correctamente"
|
||||
proposal: "Propuesta creada correctamente."
|
||||
proposal_notification: "Tu message ha sido enviado correctamente."
|
||||
spending_proposal: "Propuesta de inversión creada correctamente. Puedes acceder a ella desde %{activity}"
|
||||
|
||||
@@ -501,6 +501,12 @@ FactoryGirl.define do
|
||||
valid_answers { Faker::Lorem.words(3).join(', ') }
|
||||
end
|
||||
|
||||
factory :poll_question_answer, class: 'Poll::QuestionAnswer' do
|
||||
association :question, factory: :poll_question
|
||||
sequence(:title) { |n| "Question title #{n}" }
|
||||
sequence(:description) { |n| "Question description #{n}" }
|
||||
end
|
||||
|
||||
factory :poll_booth, class: 'Poll::Booth' do
|
||||
sequence(:name) { |n| "Booth #{n}" }
|
||||
sequence(:location) { |n| "Street #{n}" }
|
||||
|
||||
41
spec/features/polls/answers_spec.rb
Normal file
41
spec/features/polls/answers_spec.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Answers' do
|
||||
|
||||
background do
|
||||
admin = create(:administrator)
|
||||
login_as(admin.user)
|
||||
end
|
||||
|
||||
scenario "Index" do
|
||||
question = create(:poll_question)
|
||||
answer1 = create(:poll_question_answer, question: question)
|
||||
answer2 = create(:poll_question_answer, question: question)
|
||||
|
||||
visit admin_question_path(question)
|
||||
|
||||
expect(page).to have_css(".poll_question_answer", count: 2)
|
||||
|
||||
within("#poll_question_answer_#{answer1.id}") do
|
||||
expect(page).to have_content answer1.title
|
||||
expect(page).to have_content answer1.description
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Create" do
|
||||
question = create(:poll_question)
|
||||
|
||||
visit admin_question_path(question)
|
||||
|
||||
click_link "Add answer"
|
||||
fill_in "poll_question_answer_title", with: "¿Would you like to reform Central Park?"
|
||||
fill_in "poll_question_answer_description", with: "Adding more trees, creating a play area..."
|
||||
click_button "Save"
|
||||
|
||||
expect(page).to have_content "Answer created successfully"
|
||||
end
|
||||
|
||||
pending "Update"
|
||||
pending "Destroy"
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user