From 1ec793863b1c5fd4687dcec68ca42d305de2e45e Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 9 Sep 2022 12:54:03 +0200 Subject: [PATCH] Add missing system specs for poll question answer videos Minor change for replace @video.answer_id to @video.answer. --- .../questions/answers/videos_controller.rb | 3 +- .../questions/answers/videos/index.html.erb | 2 +- .../questions/answers/videos/videos_spec.rb | 47 +++++++++++++++---- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/app/controllers/admin/poll/questions/answers/videos_controller.rb b/app/controllers/admin/poll/questions/answers/videos_controller.rb index 2df3ea80c..0fb13ee46 100644 --- a/app/controllers/admin/poll/questions/answers/videos_controller.rb +++ b/app/controllers/admin/poll/questions/answers/videos_controller.rb @@ -25,8 +25,7 @@ class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseContr def update if @video.update(video_params) - redirect_to admin_answer_videos_path(@video.answer_id), - notice: t("flash.actions.save_changes.notice") + redirect_to admin_answer_videos_path(@video.answer), notice: t("flash.actions.save_changes.notice") else render :edit end diff --git a/app/views/admin/poll/questions/answers/videos/index.html.erb b/app/views/admin/poll/questions/answers/videos/index.html.erb index 2889db68a..cedfe1b4d 100644 --- a/app/views/admin/poll/questions/answers/videos/index.html.erb +++ b/app/views/admin/poll/questions/answers/videos/index.html.erb @@ -1,4 +1,4 @@ -<%= back_link_to admin_question_path(@answer.question_id) %> +<%= back_link_to admin_question_path(@answer.question) %>
diff --git a/spec/system/admin/poll/questions/answers/videos/videos_spec.rb b/spec/system/admin/poll/questions/answers/videos/videos_spec.rb index d3ced3080..1488b4a73 100644 --- a/spec/system/admin/poll/questions/answers/videos/videos_spec.rb +++ b/spec/system/admin/poll/questions/answers/videos/videos_spec.rb @@ -1,26 +1,53 @@ require "rails_helper" describe "Videos", :admin do - 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" + let!(:question) { create(:poll_question) } + let!(:answer) { create(:poll_question_answer, question: question) } + let(:title) { "'Magical' by Junko Ohashi" } + let(:url) { "https://www.youtube.com/watch?v=-JMf43st-1A" } + scenario "Create" do visit admin_question_path(question) within("#poll_question_answer_#{answer.id}") do click_link "Video list" 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 + fill_in "Title", with: title + fill_in "External video", with: url click_button "Save" - expect(page).to have_content(video_title) - expect(page).to have_content(video_url) + expect(page).to have_content title + expect(page).to have_content url + end + + scenario "Update" do + video = create(:poll_answer_video, answer: answer) + + visit edit_admin_video_path(video) + + fill_in "Title", with: title + fill_in "External video", with: url + + click_button "Save" + + expect(page).to have_content title + expect(page).to have_content url + end + + scenario "Destroy" do + video = create(:poll_answer_video, answer: answer) + + visit admin_answer_videos_path(answer) + + within("#poll_question_answer_video_#{video.id}") do + accept_confirm("Are you sure? This action will delete \"#{video.title}\" and can't be undone.") do + click_button "Delete" + end + end + + expect(page).to have_content "Answer video deleted successfully." end end