From a83c259a04904c4448bfccd58818af7d1363fa99 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Wed, 4 Oct 2017 15:49:15 -0400 Subject: [PATCH 1/6] Remove 'description' attribute from Poll::Question This avoid an exception when seeding the database See PR #1977 --- db/dev_seeds.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index b151a45cf..3ce1a439f 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -559,7 +559,6 @@ print "Creating Poll Questions" open_at = rand(2.months.ago..2.months.from_now) question = Poll::Question.create!(author: author, title: Faker::Lorem.sentence(3).truncate(60), - description: description, valid_answers: Faker::Lorem.words((2..7).to_a.sample).join(', '), poll: poll) end From f4774894e7ee94a904c5501d3e2c30529b48ca9e Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Wed, 4 Oct 2017 16:59:23 -0400 Subject: [PATCH 2/6] Adapt Admin::Poll::Question 'show' action to new design MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes required as per issues #1855 and #1951 Fixes PR #1977, note n° 2 --- app/views/admin/poll/questions/show.html.erb | 48 +++++++++++--------- config/locales/en/admin.yml | 4 +- config/locales/es/admin.yml | 5 +- config/locales/fr/admin.yml | 10 ++-- 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 7037afd5f..1cde20f5c 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -24,29 +24,35 @@ <%= link_to @question.author.name, user_path(@question.author) %>

- - - - - +
- <%= t('admin.questions.show.valid_answers') %> - - <%= link_to t("admin.questions.show.add_answer"), - new_admin_question_answer_path(@question), - class: "button hollow float-right" %> -
+ + + + + - - - - + + + + + + - <% @question.question_answers.each do |answer| %> - - - - - <% end %> + + <% @question.question_answers.each do |answer| %> + + + + + + <% end %> +
+ <%= t('admin.questions.show.valid_answers') %> + + <%= link_to t("admin.questions.show.add_answer"), + new_admin_question_answer_path(@question), + class: "button hollow float-right" %> +
<%= t("admin.questions.show.answers.title") %><%= t("admin.questions.show.answers.description") %>
<%= t("admin.questions.show.answers.title") %><%= t("admin.questions.show.answers.description") %><%= t("admin.questions.show.answers.videos") %>
<%= answer.title %><%= answer.description %>
<%= answer.title %><%= answer.description %><%= link_to t("admin.questions.show.answers.video_list", count: 0), "#" %>
<% if @question.video_url.present? %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 8202695f1..e28c7f40b 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -592,12 +592,14 @@ en: author: Author title: Title valid_answers: Valid answers - add_answer: "Add answer" + add_answer: Add answer video_url: External video documents: Documents (1) answers: title: Answer description: Description + videos: Videos + video_list: Video list (%{count}) answers: new: title: "New answer" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 3ff3abcb5..f025437cf 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -592,14 +592,15 @@ es: author: Autor title: Título valid_answers: Respuestas válidas - add_answer: "Añadir respuesta" - description: Descripción + add_answer: Añadir respuesta video_url: Video externo documents: Documentos (1) preview: Ver en la web answers: title: Respuesta description: Descripción + videos: Vídeos + video_list: Lista de vídeos (%{count}) answers: new: title: "Nueva respuesta" diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index e000c8a28..0217c9217 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -382,10 +382,14 @@ fr: author: Auteur title: Titre valid_answers: Réponses valides - add_answer: "Ajouter une réponse" - answer: "Réponse" - description: Description + add_answer: Ajouter une réponse + documents: Documents (1) preview: Voir l'aperçu + answers: + title: Réponse + description: Description + videos: Vidéos + video_list: Liste des vidéos (%{count}) answers: new: title: "Nouvelle réponse" From 32f3b643b009bda6e4c8bb654aa9d6a855967451 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Wed, 4 Oct 2017 17:25:51 -0400 Subject: [PATCH 3/6] Create 'poll_question_answer_videos' table and model --- app/models/poll/question/answer.rb | 1 + app/models/poll/question/answer/video.rb | 16 ++++++++++++++++ ...4210108_create_poll_question_answer_videos.rb | 11 +++++++++++ db/schema.rb | 11 ++++++++++- 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 app/models/poll/question/answer/video.rb create mode 100644 db/migrate/20171004210108_create_poll_question_answer_videos.rb diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index 3f8f4a172..cb43e2d44 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -1,5 +1,6 @@ class Poll::Question::Answer < ActiveRecord::Base belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id' + has_many :videos, class_name: 'Poll::Question::Answer::Video' validates :title, presence: true diff --git a/app/models/poll/question/answer/video.rb b/app/models/poll/question/answer/video.rb new file mode 100644 index 000000000..3d214af96 --- /dev/null +++ b/app/models/poll/question/answer/video.rb @@ -0,0 +1,16 @@ +class Poll::Question::Answer::Video < ActiveRecord::Base + belongs_to :answer, class_name: 'Poll::Question::Answer', foreign_key: 'answer_id' + + VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/ + YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ + + validates :title, presence: true + validate :valid_url? + + def valid_url? + return if url.blank? + return if url.match(VIMEO_REGEX) + return if url.match(YOUTUBE_REGEX) + errors.add(:url, :invalid) + end +end diff --git a/db/migrate/20171004210108_create_poll_question_answer_videos.rb b/db/migrate/20171004210108_create_poll_question_answer_videos.rb new file mode 100644 index 000000000..7cce33b29 --- /dev/null +++ b/db/migrate/20171004210108_create_poll_question_answer_videos.rb @@ -0,0 +1,11 @@ +class CreatePollQuestionAnswerVideos < ActiveRecord::Migration + def change + create_table :poll_question_answer_videos do |t| + t.string :title + t.string :url + t.integer :answer_id, index: true + end + + add_foreign_key :poll_question_answer_videos, :poll_question_answers, column: :answer_id + end +end diff --git a/db/schema.rb b/db/schema.rb index dbbd3ec46..22e362a1f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171004151553) do +ActiveRecord::Schema.define(version: 20171004210108) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -668,6 +668,14 @@ ActiveRecord::Schema.define(version: 20171004151553) do add_index "poll_partial_results", ["origin"], name: "index_poll_partial_results_on_origin", using: :btree add_index "poll_partial_results", ["question_id"], name: "index_poll_partial_results_on_question_id", using: :btree + create_table "poll_question_answer_videos", force: :cascade do |t| + t.string "title" + t.string "url" + t.integer "answer_id" + end + + add_index "poll_question_answer_videos", ["answer_id"], name: "index_poll_question_answer_videos_on_answer_id", using: :btree + create_table "poll_question_answers", force: :cascade do |t| t.string "title" t.text "description" @@ -1152,6 +1160,7 @@ ActiveRecord::Schema.define(version: 20171004151553) do add_foreign_key "poll_partial_results", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_partial_results", "poll_questions", column: "question_id" add_foreign_key "poll_partial_results", "users", column: "author_id" + add_foreign_key "poll_question_answer_videos", "poll_question_answers", column: "answer_id" add_foreign_key "poll_question_answers", "poll_questions", column: "question_id" add_foreign_key "poll_questions", "polls" add_foreign_key "poll_questions", "proposals" From ab09bde7dd3481be9071f0c2bd9e865a2fbb9405 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Thu, 5 Oct 2017 08:11:15 -0400 Subject: [PATCH 4/6] Fix broken translations for Poll::Question::Answer model Poll::QuestionAnswer model was renamed to Poll::Question::Answer which made the previous I18n keys unavailable for the views See PR #1977, commit 461410a --- config/locales/en/activerecord.yml | 2 +- config/locales/es/activerecord.yml | 2 +- config/locales/fr/activerecord.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 5ef1917d3..6a6e2ad85 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -213,7 +213,7 @@ en: image: title: Title attachment: Attachment - poll/question_answer: + poll/question/answer: title: "Answer" description: "Description" errors: diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 9b3260680..9b83d9516 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -207,7 +207,7 @@ es: image: title: Título attachment: Archivo adjunto - poll/question_answer: + poll/question/answer: title: "Respuesta" description: "Descripción" errors: diff --git a/config/locales/fr/activerecord.yml b/config/locales/fr/activerecord.yml index d6ab5db80..5c6117d31 100644 --- a/config/locales/fr/activerecord.yml +++ b/config/locales/fr/activerecord.yml @@ -147,7 +147,7 @@ fr: name: Nom locale: Langue body: Contenu - poll/question_answer: + poll/question/answer: title: "Réponse" description: "Description" errors: From 5f6d218a15542b8a213e099881fae49e557f5073 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Thu, 5 Oct 2017 10:32:09 -0400 Subject: [PATCH 5/6] Rename param in Admin::Poll::Questions::AnswersController 'poll_question_id' attribute was renamed to 'question_id' on PR #1977, commit 4aaf681 --- app/controllers/admin/poll/questions/answers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index d0a7c4cc7..660339844 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -21,7 +21,7 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController private def answer_params - params.require(:poll_question_answer).permit(:title, :description, :poll_question_id) + params.require(:poll_question_answer).permit(:title, :description, :question_id) end def load_question From 5862eea516c2cb03bb11e29c04952b0b3b1b1908 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Thu, 5 Oct 2017 12:34:20 -0400 Subject: [PATCH 6/6] Add controllers/views for Poll::Question::Answer::Video --- .../questions/answers/videos_controller.rb | 57 +++++++++++++++++++ .../questions/answers/videos/_form.html.erb | 21 +++++++ .../questions/answers/videos/edit.html.erb | 9 +++ .../questions/answers/videos/index.html.erb | 47 +++++++++++++++ .../questions/answers/videos/new.html.erb | 9 +++ app/views/admin/poll/questions/show.html.erb | 16 +++--- config/locales/en/activerecord.yml | 3 + config/locales/en/admin.yml | 12 +++- config/locales/en/responders.yml | 2 + config/locales/es/activerecord.yml | 3 + config/locales/es/admin.yml | 10 ++++ config/locales/es/responders.yml | 2 + config/locales/fr/activerecord.yml | 3 + config/locales/fr/admin.yml | 10 ++++ config/locales/fr/responders.yml | 3 + config/routes.rb | 6 +- .../questions/answers/videos/videos_spec.rb | 33 +++++++++++ 17 files changed, 236 insertions(+), 10 deletions(-) create mode 100644 app/controllers/admin/poll/questions/answers/videos_controller.rb create mode 100644 app/views/admin/poll/questions/answers/videos/_form.html.erb create mode 100644 app/views/admin/poll/questions/answers/videos/edit.html.erb create mode 100644 app/views/admin/poll/questions/answers/videos/index.html.erb create mode 100644 app/views/admin/poll/questions/answers/videos/new.html.erb create mode 100644 spec/features/admin/poll/questions/answers/videos/videos_spec.rb diff --git a/app/controllers/admin/poll/questions/answers/videos_controller.rb b/app/controllers/admin/poll/questions/answers/videos_controller.rb new file mode 100644 index 000000000..a231c1a20 --- /dev/null +++ b/app/controllers/admin/poll/questions/answers/videos_controller.rb @@ -0,0 +1,57 @@ +class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseController + before_action :load_answer, only: [:index, :new, :create] + before_action :load_video, only: [:edit, :update, :destroy] + + def index + end + + def new + @video = ::Poll::Question::Answer::Video.new + end + + def create + @video = ::Poll::Question::Answer::Video.new(video_params) + + if @video.save + redirect_to admin_answer_videos_path(@answer), + notice: t("flash.actions.create.poll_question_answer_video") + else + render :new + end + end + + def edit + end + + def update + if @video.update(video_params) + redirect_to admin_answer_videos_path(@video.answer_id), + notice: t("flash.actions.save_changes.notice") + else + render :edit + end + end + + def destroy + if @video.destroy + notice = t("flash.actions.destroy.poll_question_answer_video") + else + notice = t("flash.actions.destroy.error") + end + redirect_to :back, notice: notice + end + + private + + def video_params + params.require(:poll_question_answer_video).permit(:title, :url, :answer_id) + end + + def load_answer + @answer = ::Poll::Question::Answer.find(params[:answer_id]) + end + + def load_video + @video = ::Poll::Question::Answer::Video.find(params[:id]) + end +end diff --git a/app/views/admin/poll/questions/answers/videos/_form.html.erb b/app/views/admin/poll/questions/answers/videos/_form.html.erb new file mode 100644 index 000000000..28035c397 --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/_form.html.erb @@ -0,0 +1,21 @@ +<%= form_for(@video, url: form_url) do |f| %> + + <%= render 'shared/errors', resource: @video %> + + <%= f.hidden_field :answer_id, value: @video.answer_id || @answer.id %> + +
+
+ + <%= f.text_field :title %> + <%= f.text_field :url %> + +
+
+ <%= f.submit(class: "button expanded", value: t("shared.save")) %> +
+
+ +
+
+<% end %> diff --git a/app/views/admin/poll/questions/answers/videos/edit.html.erb b/app/views/admin/poll/questions/answers/videos/edit.html.erb new file mode 100644 index 000000000..31b59c2dd --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/edit.html.erb @@ -0,0 +1,9 @@ +<%= back_link_to %> + +

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

+ +
+ <%= render "form", form_url: admin_video_path(@video) %> +
diff --git a/app/views/admin/poll/questions/answers/videos/index.html.erb b/app/views/admin/poll/questions/answers/videos/index.html.erb new file mode 100644 index 000000000..0ea64c570 --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/index.html.erb @@ -0,0 +1,47 @@ +<%= back_link_to admin_question_path(@answer.question_id) %> + +
+ +

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

+ +<%= link_to t("admin.answers.videos.index.add_video"), + new_admin_answer_video_path, + class: "button success float-right" %> + +
+ + + + + + + + + + + + <% @answer.videos.each do |video| %> + + + + + + <% end %> + +
<%= t("admin.answers.videos.index.video_title") %><%= t("admin.answers.videos.index.video_url") %> + <%= t("admin.actions.actions") %> +
<%= video.title %><%= link_to "#{video.url}", video.url %> + + <%= link_to t("shared.edit"), + edit_admin_video_path(video), + class: "button hollow" %> + + <%= link_to t("shared.delete"), + admin_video_path(video), + class: "button hollow alert", + method: :delete %> +
+ +
diff --git a/app/views/admin/poll/questions/answers/videos/new.html.erb b/app/views/admin/poll/questions/answers/videos/new.html.erb new file mode 100644 index 000000000..d114b9104 --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/new.html.erb @@ -0,0 +1,9 @@ +<%= back_link_to admin_answer_videos_path(@answer) %> + +

+ <%= t('admin.answers.videos.new.title') %> +

+ +
+ <%= render "form", form_url: admin_answer_videos_path %> +
diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 1cde20f5c..84a07622f 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -24,13 +24,13 @@ <%= link_to @question.author.name, user_path(@question.author) %>

- +
- - - - - + + + @@ -49,7 +49,9 @@ - + <% end %> diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 6a6e2ad85..f6b6be383 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -216,6 +216,9 @@ en: poll/question/answer: title: "Answer" description: "Description" + poll/question/answer/video: + title: Title + url: External video errors: models: user: diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index e28c7f40b..981eca84e 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -602,7 +602,17 @@ en: video_list: Video list (%{count}) answers: new: - title: "New answer" + title: New answer + videos: + index: + title: Videos + add_video: Add video + video_title: Title + video_url: External video + new: + title: New video + edit: + title: Edit video recounts: index: title: "Recounts" diff --git a/config/locales/en/responders.yml b/config/locales/en/responders.yml index fd187c495..88f68a955 100644 --- a/config/locales/en/responders.yml +++ b/config/locales/en/responders.yml @@ -9,6 +9,7 @@ en: poll: "Poll created successfully." poll_booth: "Booth created successfully." poll_question_answer: "Answer created successfully" + poll_question_answer_video: "Video 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}" @@ -31,3 +32,4 @@ en: budget_investment: "Investment project deleted succesfully." error: "Could not delete" topic: "Topic deleted successfully." + poll_question_answer_video: "Answer video deleted successfully." diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 9b83d9516..d04eb72da 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -210,6 +210,9 @@ es: poll/question/answer: title: "Respuesta" description: "Descripción" + poll/question/answer/video: + title: Título + url: Vídeo externo errors: models: user: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index f025437cf..f57c4fbea 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -606,6 +606,16 @@ es: title: "Nueva respuesta" video_url: Video externo documents: Documentos (1) + videos: + index: + title: Vídeos + add_video: Añadir vídeo + video_title: Título + video_url: External video + new: + title: Nuevo video + edit: + title: Editar vídeo recounts: index: title: "Recuentos" diff --git a/config/locales/es/responders.yml b/config/locales/es/responders.yml index a35387ff3..01f19d96e 100644 --- a/config/locales/es/responders.yml +++ b/config/locales/es/responders.yml @@ -9,6 +9,7 @@ es: poll: "Votación creada correctamente." poll_booth: "Urna creada correctamente." poll_question_answer: "Respuesta creada correctamente" + poll_question_answer_video: "Vídeo creado 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}" @@ -31,3 +32,4 @@ es: budget_investment: "Propuesta de inversión eliminada." error: "No se pudo borrar" topic: "Tema eliminado." + poll_question_answer_video: "Vídeo de respuesta eliminado." diff --git a/config/locales/fr/activerecord.yml b/config/locales/fr/activerecord.yml index 5c6117d31..bd8acfd50 100644 --- a/config/locales/fr/activerecord.yml +++ b/config/locales/fr/activerecord.yml @@ -150,6 +150,9 @@ fr: poll/question/answer: title: "Réponse" description: "Description" + poll/question/answer/video: + title: Titre + url: Vidéo externe errors: models: user: diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index 0217c9217..ba29e068b 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -393,6 +393,16 @@ fr: answers: new: title: "Nouvelle réponse" + videos: + index: + title: Vidéos + add_video: Ajouter une vidéo + video_title: Titre + video_url: Vidéo externe + new: + title: Nouveau vidéo + edit: + title: Modifier la vidéo recounts: index: title: "Dépouillements" diff --git a/config/locales/fr/responders.yml b/config/locales/fr/responders.yml index 9897e3455..1d1cfae0c 100644 --- a/config/locales/fr/responders.yml +++ b/config/locales/fr/responders.yml @@ -8,6 +8,8 @@ fr: direct_message: "Votre message a été envoyé avec succès." poll: "Vote créé avec succès." poll_booth: "Urne créée avec succès." + poll_question_answer: "Réponse créée avec succès" + poll_question_answer_video: "Vidéo créée avec succès" proposal: "Proposition créée avec succès." proposal_notification: "Votre message a correctement été envoyé." spending_proposal: "Proposition de dépense créée avec succès. Vous pouvez y accéder depuis %{activity}" @@ -27,3 +29,4 @@ fr: spending_proposal: "Proposition de dépense supprimée avec succès." budget_investment: "Budget d'investissement supprimé avec succès." error: "Suppression impossible" + poll_question_answer_video: "Réponse vidéo supprimée avec succès." diff --git a/config/routes.rb b/config/routes.rb index 89691feac..1428dc4fa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -300,8 +300,10 @@ Rails.application.routes.draw do end end - resources :questions do - resources :answers, only: [:new, :create], controller: 'questions/answers' + resources :questions, shallow: true do + resources :answers, only: [:new, :create], controller: 'questions/answers' do + resources :videos, controller: 'questions/answers/videos' + end end end diff --git a/spec/features/admin/poll/questions/answers/videos/videos_spec.rb b/spec/features/admin/poll/questions/answers/videos/videos_spec.rb new file mode 100644 index 000000000..ee04ce128 --- /dev/null +++ b/spec/features/admin/poll/questions/answers/videos/videos_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +feature 'Videos' do + + background do + admin = create(:administrator) + login_as(admin.user) + end + + scenario "Create" do + question = create(:poll_question) + answer = create(:poll_question_answer, question: question) + video_title = "'Magical' by Junko Ohashi" + video_url = "https://www.youtube.com/watch?v=-JMf43st-1A" + + visit admin_question_path(question) + + within("#poll_question_answer_#{answer.id}") do + click_link "Video list (#{answer.videos.count})" + end + + click_link "Add video" + + fill_in 'poll_question_answer_video_title', with: video_title + fill_in 'poll_question_answer_video_url', with: video_url + + click_button "Save" + + expect(page).to have_content(video_title) + expect(page).to have_content(video_url) + end + +end
+ <%= t('admin.questions.show.valid_answers') %> + <%= link_to t("admin.questions.show.add_answer"), new_admin_question_answer_path(@question), class: "button hollow float-right" %> @@ -38,9 +38,9 @@
<%= t("admin.questions.show.answers.title") %><%= t("admin.questions.show.answers.description") %><%= t("admin.questions.show.answers.videos") %><%= t("admin.questions.show.answers.title") %><%= t("admin.questions.show.answers.description") %><%= t("admin.questions.show.answers.videos") %>
<%= answer.title %> <%= answer.description %><%= link_to t("admin.questions.show.answers.video_list", count: 0), "#" %><%= link_to t("admin.questions.show.answers.video_list", + count: answer.videos.count), + admin_answer_videos_path(answer) %>