diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 660339844..4d70b34d1 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -1,5 +1,6 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController - before_action :load_question + before_action :load_question, except: [:show, :edit, :update] + before_action :load_answer, only: [:show, :edit, :update] load_and_authorize_resource :question, class: "::Poll::Question" @@ -18,6 +19,21 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController end end + def show + end + + def edit + end + + def update + if @answer.update(answer_params) + redirect_to admin_answer_path(@answer), + notice: t("flash.actions.save_changes.notice") + else + render :edit + end + end + private def answer_params @@ -27,4 +43,8 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController def load_question @question = ::Poll::Question.find(params[:question_id]) end + + def load_answer + @answer = ::Poll::Question::Answer.find(params[:id]) + end end diff --git a/app/views/admin/poll/questions/answers/_form.html.erb b/app/views/admin/poll/questions/answers/_form.html.erb index 72ffb4771..3eae62c2f 100644 --- a/app/views/admin/poll/questions/answers/_form.html.erb +++ b/app/views/admin/poll/questions/answers/_form.html.erb @@ -2,17 +2,14 @@ <%= render 'shared/errors', resource: @answer %> - <%= f.hidden_field :question_id, value: @question.id %> + <%= f.hidden_field :question_id, value: @answer.question_id || @question.id %> - <%= f.label :title, t('admin.questions.new.form.title') %> - <%= f.text_field :title, label: false %> + <%= f.text_field :title %>
+ <%= t("admin.answers.show.title") %>
+
+ <%= @answer.title %>
+
+ <%= t("admin.answers.show.description") %> + <%= @answer.description %> +
+ +
+ <%= t("admin.answers.show.images") %>
+
+ <%= link_to t("admin.answers.show.images_list"), admin_answer_images_path(@answer) %>
+
| + | <%= t('admin.questions.show.valid_answers') %> <%= link_to t("admin.questions.show.add_answer"), new_admin_question_answer_path(@question), @@ -47,7 +47,7 @@ <% @question.question_answers.each do |answer| %> | ||||
|---|---|---|---|---|---|
| <%= answer.title %> | +<%= link_to answer.title, admin_answer_path(answer) %> | <%= answer.description %> |
(<%= answer.images.count %>) diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 5ef1917d3..78435aa58 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -213,9 +213,9 @@ en: image: title: Title attachment: Attachment - poll/question_answer: - title: "Answer" - description: "Description" + poll/question/answer: + title: Answer + description: Description errors: models: user: diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 02d8bacdd..b2b6aca3a 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -609,7 +609,14 @@ en: images_list: Images list answers: new: - title: "New answer" + title: New answer + show: + title: Title + description: Description + images: Images + images_list: Images list + edit: + title: Edit answer recounts: index: title: "Recounts" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 9b3260680..03bcdfc60 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -207,9 +207,9 @@ es: image: title: Título attachment: Archivo adjunto - poll/question_answer: - title: "Respuesta" - description: "Descripción" + poll/question/answer: + title: Respuesta + description: Descripción errors: models: user: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 9e0de770e..d2b405fe7 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -611,9 +611,16 @@ es: images_list: Lista de imágenes answers: new: - title: "Nueva respuesta" + title: Nueva respuesta video_url: Video externo documents: Documentos (1) + show: + title: Título + description: Descripción + images: Imágenes + images_list: Lista de imágenes + edit: + title: Editar respuesta recounts: index: title: "Recuentos" diff --git a/config/locales/fr/activerecord.yml b/config/locales/fr/activerecord.yml index d6ab5db80..59350d85d 100644 --- a/config/locales/fr/activerecord.yml +++ b/config/locales/fr/activerecord.yml @@ -147,9 +147,9 @@ fr: name: Nom locale: Langue body: Contenu - poll/question_answer: - title: "Réponse" - description: "Description" + poll/question/answer: + title: Réponse + description: Description errors: models: user: diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index e000c8a28..df288a934 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -387,8 +387,15 @@ fr: description: Description preview: Voir l'aperçu answers: + show: + title: Titre + description: Description + images: Images + images_list: Liste des images new: - title: "Nouvelle réponse" + title: Nouvelle réponse + edit: + title: Modifier réponse recounts: index: title: "Dépouillements" diff --git a/config/routes.rb b/config/routes.rb index 387983d4b..3a8f4b9cd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -301,7 +301,7 @@ Rails.application.routes.draw do end resources :questions do - resources :answers, only: [:new, :create], controller: 'questions/answers', shallow: true do + resources :answers, except: [:index, :destroy, :delete], controller: 'questions/answers', shallow: true do resources :images, controller: 'questions/answers/images' end diff --git a/spec/features/admin/poll/questions/answers/answers_spec.rb b/spec/features/admin/poll/questions/answers/answers_spec.rb new file mode 100644 index 000000000..b3b3ad420 --- /dev/null +++ b/spec/features/admin/poll/questions/answers/answers_spec.rb @@ -0,0 +1,51 @@ +require 'rails_helper' + +feature 'Answers' do + + background do + admin = create(:administrator) + login_as (admin.user) + end + + scenario 'Create' do + question = create(:poll_question) + title = 'Whatever the question may be, the answer is always 42' + description = "The Hitchhiker's Guide To The Universe" + + visit admin_question_path(question) + click_link 'Add answer' + + fill_in 'poll_question_answer_title', with: title + fill_in 'poll_question_answer_description', with: description + + click_button 'Save' + + expect(page).to have_content(title) + expect(page).to have_content(description) + end + + scenario 'Update' do + question = create(:poll_question) + answer = create(:poll_question_answer, question: question) + + visit admin_answer_path(answer) + + click_link 'Edit' + + old_title = answer.title + new_title = 'Ex Machina' + + fill_in 'poll_question_answer_title', with: new_title + + click_button 'Save' + + expect(page).to have_content('Changes saved') + expect(page).to have_content(new_title) + + visit admin_question_path(question) + + expect(page).to have_content(new_title) + expect(page).to_not have_content(old_title) + end + +end | ||