diff --git a/app/views/admin/poll/polls/_questions.html.erb b/app/views/admin/poll/polls/_questions.html.erb index f1dd818e8..1629e8c5b 100644 --- a/app/views/admin/poll/polls/_questions.html.erb +++ b/app/views/admin/poll/polls/_questions.html.erb @@ -1,4 +1,7 @@ -

<%= t("admin.polls.show.questions_title") %>

+

<%= t("admin.polls.show.questions_title") %>

+ +<%= link_to t("admin.questions.index.create"), new_admin_question_path(poll_id: @poll.id), + class: "button float-right" %> <% if @poll.questions.empty? %>
@@ -9,6 +12,7 @@ <%= t("admin.polls.show.table_title") %> + <%= t("admin.actions.actions") %> <% @poll.questions.each do |question| %> @@ -17,6 +21,20 @@ <%= link_to question.title, admin_question_path(question) %> + +
+ <%= link_to t("admin.polls.show.edit_answers"), admin_question_path(question), + class: "button hollow expanded" %> +
+
+ <%= link_to t("shared.edit"), edit_admin_question_path(question), + class: "button hollow expanded" %> +
+
+ <%= link_to t("shared.delete"), admin_question_path(question), + class: "button hollow alert expanded", + method: :delete %> +
<% end %> diff --git a/app/views/admin/poll/questions/_form.html.erb b/app/views/admin/poll/questions/_form.html.erb index 9637c14f8..2e763521b 100644 --- a/app/views/admin/poll/questions/_form.html.erb +++ b/app/views/admin/poll/questions/_form.html.erb @@ -7,13 +7,19 @@ <%= f.hidden_field :proposal_id %>
-
- <% select_options = Poll.all.map { |p| [p.name, p.id] } %> - <%= f.select :poll_id, - options_for_select(select_options), - prompt: t("admin.questions.index.select_poll"), - label: t("admin.questions.new.poll_label") %> -
+ <% if @poll.present? %> + <%= f.hidden_field :poll_id, value: @poll.id %> + <% elsif @question.poll.present? %> + <%= f.hidden_field :poll_id, value: @question.poll.id %> + <% else %> +
+ <% select_options = Poll.all.map { |p| [p.name, p.id] } %> + <%= f.select :poll_id, + options_for_select(select_options), + prompt: t("admin.questions.index.select_poll"), + label: t("admin.questions.new.poll_label") %> +
+ <% end %> <%= f.translatable_fields do |translations_form| %> <%= translations_form.text_field :title %> diff --git a/app/views/admin/poll/questions/new.html.erb b/app/views/admin/poll/questions/new.html.erb index 249464a0c..7dc2905ce 100644 --- a/app/views/admin/poll/questions/new.html.erb +++ b/app/views/admin/poll/questions/new.html.erb @@ -1,6 +1,12 @@ <%= back_link_to %> -

<%= t("admin.questions.new.title") %>

+

+ <% if @poll.present? %> + <%= t("admin.questions.new.title", poll: @poll.name) %> + <% else %> + <%= t("admin.questions.new.title_proposal") %> + <% end %> +

<%= render "form", form_url: admin_questions_path %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index b881f06bd..7142f403f 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -974,6 +974,7 @@ en: no_questions: "There are no questions assigned to this poll." questions_title: "List of questions" table_title: "Title" + edit_answers: Edit answers flash: question_added: "Question added to this poll" error_on_question_added: "Question could not be assigned to this poll" @@ -994,7 +995,8 @@ en: edit: title: "Edit Question" new: - title: "Create Question" + title: "Create question to poll %{poll}" + title_proposal: "Create question" poll_label: "Poll" answers: images: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 391a27b65..0b91ed8c6 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -973,6 +973,7 @@ es: no_questions: "No hay preguntas asignadas a esta votación." questions_title: "Listado de preguntas asignadas" table_title: "Título" + edit_answers: Editar respuestas flash: question_added: "Pregunta añadida a esta votación" error_on_question_added: "No se pudo asignar la pregunta" @@ -993,7 +994,8 @@ es: edit: title: "Editar pregunta ciudadana" new: - title: "Crear pregunta ciudadana" + title: "Crear pregunta ciudadana para la votación %{poll}" + title_proposal: "Crear pregunta ciudadana" poll_label: "Votación" answers: images: diff --git a/spec/features/admin/poll/questions_spec.rb b/spec/features/admin/poll/questions_spec.rb index 2306caf14..2da138b5b 100644 --- a/spec/features/admin/poll/questions_spec.rb +++ b/spec/features/admin/poll/questions_spec.rb @@ -17,16 +17,24 @@ feature "Admin poll questions" do question1 = create(:poll_question, poll: poll1) question2 = create(:poll_question, poll: poll2) - visit admin_questions_path + visit admin_poll_path(poll1) + expect(page).to have_content(poll1.name) within("#poll_question_#{question1.id}") do expect(page).to have_content(question1.title) - expect(page).to have_content(poll1.name) + expect(page).to have_content("Edit answers") + expect(page).to have_content("Edit") + expect(page).to have_content("Delete") end + visit admin_poll_path(poll2) + expect(page).to have_content(poll2.name) + within("#poll_question_#{question2.id}") do expect(page).to have_content(question2.title) - expect(page).to have_content(poll2.name) + expect(page).to have_content("Edit answers") + expect(page).to have_content("Edit") + expect(page).to have_content("Delete") end end @@ -35,7 +43,8 @@ feature "Admin poll questions" do poll = create(:poll, geozone_restricted: true, geozone_ids: [geozone.id]) question = create(:poll_question, poll: poll) - visit admin_question_path(question) + visit admin_poll_path(poll) + click_link "#{question.title}" expect(page).to have_content(question.title) expect(page).to have_content(question.author.name) @@ -44,17 +53,13 @@ feature "Admin poll questions" do scenario "Create" do poll = create(:poll, name: "Movies") title = "Star Wars: Episode IV - A New Hope" - description = %{ - During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the DEATH STAR, an armored space station - with enough power to destroy an entire planet. - Pursued by the Empire's sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her - people and restore freedom to the galaxy.... - } - visit admin_questions_path + visit admin_poll_path(poll) click_link "Create question" - select "Movies", from: "poll_question_poll_id" + expect(page).to have_content("Create question to poll Movies") + expect(page).to have_selector("input[id='poll_question_poll_id'][value='#{poll.id}']", + visible: false) fill_in "Question", with: title click_button "Save" @@ -101,9 +106,11 @@ feature "Admin poll questions" do end scenario "Update" do - question1 = create(:poll_question) + poll = create(:poll) + question1 = create(:poll_question, poll: poll) + + visit admin_poll_path(poll) - visit admin_questions_path within("#poll_question_#{question1.id}") do click_link "Edit" end @@ -116,18 +123,15 @@ feature "Admin poll questions" do expect(page).to have_content "Changes saved" expect(page).to have_content new_title - - visit admin_questions_path - - expect(page).to have_content(new_title) expect(page).not_to have_content(old_title) end scenario "Destroy" do - question1 = create(:poll_question) - question2 = create(:poll_question) + poll = create(:poll) + question1 = create(:poll_question, poll: poll) + question2 = create(:poll_question, poll: poll) - visit admin_questions_path + visit admin_poll_path(poll) within("#poll_question_#{question1.id}") do click_link "Delete" @@ -141,29 +145,20 @@ feature "Admin poll questions" do context "Poll select box" do - let(:poll) { create(:poll, name_en: "Name in English", - name_es: "Nombre en Español", - summary_en: "Summary in English", - summary_es: "Resumen en Español", - description_en: "Description in English", - description_es: "Descripción en Español") } - - let(:question) { create(:poll_question, poll: poll, - title_en: "Question in English", - title_es: "Pregunta en Español") } - - before do - @edit_question_url = edit_admin_question_path(question) - end - scenario "translates the poll name in options", :js do - visit @edit_question_url - expect(page).to have_select("poll_question_poll_id", options: [poll.name_en]) + poll = create(:poll, name_en: "Name in English", name_es: "Nombre en Español") + proposal = create(:proposal) + + visit admin_proposal_path(proposal) + click_link "Add this proposal to a poll to be voted" + + expect(page).to have_select("poll_question_poll_id", options: ["Select Poll", poll.name_en]) select("Español", from: "locale-switcher") - expect(page).to have_select("poll_question_poll_id", options: [poll.name_es]) + expect(page).to have_select("poll_question_poll_id", + options: ["Seleccionar votación", poll.name_es]) end scenario "uses fallback if name is not translated to current locale", :js do @@ -171,13 +166,18 @@ feature "Admin poll questions" do skip("Spec only useful when French falls back to Spanish") end - visit @edit_question_url + poll = create(:poll, name_en: "Name in English", name_es: "Nombre en Español") + proposal = create(:proposal) - expect(page).to have_select("poll_question_poll_id", options: [poll.name_en]) + visit admin_proposal_path(proposal) + click_link "Add this proposal to a poll to be voted" + + expect(page).to have_select("poll_question_poll_id", options: ["Select Poll", poll.name_en]) select("Français", from: "locale-switcher") - expect(page).to have_select("poll_question_poll_id", options: [poll.name_es]) + expect(page).to have_select("poll_question_poll_id", + options: ["Sélectionner un vote", poll.name_es]) end end