diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 2bc442fe5..45f0abcd7 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_answer, only: [:update, :documents] + before_action :load_question, except: [:show, :edit, :update] + before_action :load_answer, only: [:show, :edit, :update, :documents] load_and_authorize_resource :question, class: "::Poll::Question" @@ -18,9 +19,16 @@ 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_question_path(@answer.question), notice: t("flash.actions.save_changes.notice") + redirect_to admin_answer_path(@answer), + notice: t("flash.actions.save_changes.notice") else redirect_to :back end @@ -42,4 +50,8 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController @answer = ::Poll::Question::Answer.find(params[:id] || params[:answer_id]) end + def load_question + @question = ::Poll::Question.find(params[:question_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 fc16e7e36..3bb2ebe39 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 %>
- <%= f.label :description, t('admin.questions.new.form.description') %> <%= f.cktext_area :description, maxlength: Poll::Question.description_max_length, - ckeditor: { language: I18n.locale }, - label: false %> + ckeditor: { language: I18n.locale } %>
diff --git a/app/views/admin/poll/questions/answers/edit.html.erb b/app/views/admin/poll/questions/answers/edit.html.erb new file mode 100644 index 000000000..48fb4ad5d --- /dev/null +++ b/app/views/admin/poll/questions/answers/edit.html.erb @@ -0,0 +1,14 @@ +<%= back_link_to %> + + + +

+ <%= t("admin.answers.edit.title") %> +

+ +
+ <%= render "form", form_url: admin_answer_path(@answer) %> +
diff --git a/app/views/admin/poll/questions/answers/show.html.erb b/app/views/admin/poll/questions/answers/show.html.erb new file mode 100644 index 000000000..e6e0244a0 --- /dev/null +++ b/app/views/admin/poll/questions/answers/show.html.erb @@ -0,0 +1,32 @@ +<%= back_link_to %> + +<%= link_to t('shared.edit'), edit_admin_answer_path(@answer), + class: "button hollow float-right" %> + + + +
+ +
+
+

+ <%= 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) %> +

+
+
diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 8a2d34c7c..123d2ec13 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -49,7 +49,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 f6b6be383..bf2cbb712 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -214,8 +214,8 @@ en: title: Title attachment: Attachment poll/question/answer: - title: "Answer" - description: "Description" + title: Answer + description: Description poll/question/answer/video: title: Title url: External video diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 020803b91..b16214a2a 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -587,9 +587,6 @@ en: new: title: "Create Question" poll_label: "Poll" - form: - title: Title - description: Description answers: images: add_image: "Add image" @@ -615,6 +612,13 @@ en: answers: new: title: New answer + show: + title: Title + description: Description + images: Images + images_list: Images list + edit: + title: Edit answer videos: index: title: Videos diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index d04eb72da..f61e3bd53 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -208,8 +208,8 @@ es: title: Título attachment: Archivo adjunto poll/question/answer: - title: "Respuesta" - description: "Descripción" + title: Respuesta + description: Descripción poll/question/answer/video: title: Título url: Vídeo externo diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 3b9ff16ff..75fa73dff 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -587,9 +587,6 @@ es: new: title: "Crear pregunta ciudadana" poll_label: "Votación" - form: - title: Título - description: Descripción answers: images: add_image: "Añadir imagen" @@ -614,9 +611,16 @@ es: document_actions: Acciones 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 videos: index: title: Vídeos diff --git a/config/locales/fr/activerecord.yml b/config/locales/fr/activerecord.yml index bd8acfd50..82e9d180e 100644 --- a/config/locales/fr/activerecord.yml +++ b/config/locales/fr/activerecord.yml @@ -148,8 +148,8 @@ fr: locale: Langue body: Contenu poll/question/answer: - title: "Réponse" - description: "Description" + title: Réponse + description: Description poll/question/answer/video: title: Titre url: Vidéo externe diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index ba29e068b..d80e55fc9 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -391,8 +391,15 @@ fr: videos: Vidéos video_list: Liste des vidéos (%{count}) 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 videos: index: title: Vidéos diff --git a/config/routes.rb b/config/routes.rb index 156605801..83b5754d7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -300,8 +300,8 @@ Rails.application.routes.draw do end end - resources :questions do - resources :answers, only: [:new, :create, :update], controller: 'questions/answers', shallow: true do + resources :questions, shallow: true do + resources :answers, except: [:index, :destroy], controller: 'questions/answers', shallow: true do resources :images, controller: 'questions/answers/images' resources :videos, controller: 'questions/answers/videos' get :documents, to: 'questions/answers#documents' 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