diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/components/admin/poll/questions/answers/documents/index_component.html.erb similarity index 77% rename from app/views/admin/poll/questions/answers/documents.html.erb rename to app/components/admin/poll/questions/answers/documents/index_component.html.erb index 4c0396849..9c6b95c20 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/components/admin/poll/questions/answers/documents/index_component.html.erb @@ -1,18 +1,15 @@ -<%= back_link_to %> +<%= back_link_to admin_question_path(@answer.question) %>

<%= t("admin.questions.show.answers.documents_list") %>

- <%= form_for(Poll::Question::Answer.new, - url: admin_answer_path(@answer), - method: :put) do |f| %> - - <%= render "shared/errors", resource: @answer %> + <%= form_for(Poll::Question::Answer.new, url: admin_answer_documents_path(answer)) do |f| %> + <%= render "shared/errors", resource: answer %>
<%= render "documents/nested_documents", f: f %> @@ -23,14 +20,14 @@
<% end %> - <% if @answer.documents.present? %> + <% if answer.documents.present? %> - <% @answer.documents.each do |document| %> + <% answer.documents.each do |document| %> - <% @answer.videos.each do |video| %> + <% @videos.each do |video| %> diff --git a/app/views/admin/poll/questions/answers/videos/new.html.erb b/app/views/admin/poll/questions/answers/videos/new.html.erb index 564817e3f..9552916ea 100644 --- a/app/views/admin/poll/questions/answers/videos/new.html.erb +++ b/app/views/admin/poll/questions/answers/videos/new.html.erb @@ -5,5 +5,5 @@
- <%= render "form", form_url: admin_answer_videos_path %> + <%= render "form", form_url: admin_answer_videos_path(@answer) %>
diff --git a/app/views/admin/poll/questions/edit.html.erb b/app/views/admin/poll/questions/edit.html.erb index 52c37badd..6c16a0ddf 100644 --- a/app/views/admin/poll/questions/edit.html.erb +++ b/app/views/admin/poll/questions/edit.html.erb @@ -1,4 +1,4 @@ -<%= back_link_to %> +<%= back_link_to admin_poll_path(@question.poll) %>

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

diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 4072a0614..954767747 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -1,4 +1,4 @@ -<%= back_link_to %> +<%= back_link_to admin_poll_path(@question.poll) %> <%= link_to t("admin.questions.show.edit_question"), edit_admin_question_path(@question), class: "button hollow float-right" %> @@ -35,24 +35,22 @@
<%= t("admin.questions.show.answers.document_title") %> <%= t("admin.questions.show.answers.document_actions") %>
<%= link_to document.title, document.attachment %> diff --git a/app/components/admin/poll/questions/answers/documents/index_component.rb b/app/components/admin/poll/questions/answers/documents/index_component.rb new file mode 100644 index 000000000..ca72d4f98 --- /dev/null +++ b/app/components/admin/poll/questions/answers/documents/index_component.rb @@ -0,0 +1,7 @@ +class Admin::Poll::Questions::Answers::Documents::IndexComponent < ApplicationComponent + attr_reader :answer + + def initialize(answer) + @answer = answer + end +end diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 8cfa00136..68ba02a01 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -4,22 +4,21 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController include ReportAttributes load_and_authorize_resource - before_action :load_search, only: [:search_booths, :search_officers] before_action :load_geozones, only: [:new, :create, :edit, :update] def index - @polls = Poll.not_budget.created_by_admin.order(starts_at: :desc) + @polls = @polls.not_budget.created_by_admin.order(starts_at: :desc) end def show - @poll = Poll.find(params[:id]) end def new end def create - @poll = Poll.new(poll_params.merge(author: current_user)) + @poll.author = current_user + if @poll.save notice = t("flash.actions.create.poll") if @poll.budget.present? @@ -43,18 +42,6 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController end end - def add_question - question = ::Poll::Question.find(params[:question_id]) - - if question.present? - @poll.questions << question - notice = t("admin.polls.flash.question_added") - else - notice = t("admin.polls.flash.error_on_question_added") - end - redirect_to admin_poll_path(@poll), notice: notice - end - def booth_assignments @polls = Poll.current.created_by_admin end @@ -85,16 +72,4 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController [*attributes, *report_attributes, translation_params(Poll)] end - - def search_params - params.permit(:poll_id, :search) - end - - def load_search - @search = search_params[:search] - end - - def resource - @poll ||= Poll.find(params[:id]) - end end diff --git a/app/controllers/admin/poll/questions/answers/documents_controller.rb b/app/controllers/admin/poll/questions/answers/documents_controller.rb new file mode 100644 index 000000000..3210896d6 --- /dev/null +++ b/app/controllers/admin/poll/questions/answers/documents_controller.rb @@ -0,0 +1,29 @@ +class Admin::Poll::Questions::Answers::DocumentsController < Admin::Poll::BaseController + include DocumentAttributes + + load_and_authorize_resource :answer, class: "::Poll::Question::Answer" + + def index + end + + def create + @answer.attributes = documents_params + + if @answer.save + redirect_to admin_answer_documents_path(@answer), + notice: t("admin.documents.create.success_notice") + else + render :new + end + end + + private + + def documents_params + params.require(:poll_question_answer).permit(allowed_params) + end + + def allowed_params + [documents_attributes: document_attributes] + end +end diff --git a/app/controllers/admin/poll/questions/answers/images_controller.rb b/app/controllers/admin/poll/questions/answers/images_controller.rb index f91389daa..a209b058f 100644 --- a/app/controllers/admin/poll/questions/answers/images_controller.rb +++ b/app/controllers/admin/poll/questions/answers/images_controller.rb @@ -1,7 +1,7 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseController include ImageAttributes - before_action :load_answer, except: :destroy + load_and_authorize_resource :answer, class: "::Poll::Question::Answer" def index end @@ -38,8 +38,4 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr def allowed_params [:answer_id, images_attributes: image_attributes] end - - def load_answer - @answer = ::Poll::Question::Answer.find(params[:answer_id]) - end end diff --git a/app/controllers/admin/poll/questions/answers/videos_controller.rb b/app/controllers/admin/poll/questions/answers/videos_controller.rb index 2df3ea80c..c198540b1 100644 --- a/app/controllers/admin/poll/questions/answers/videos_controller.rb +++ b/app/controllers/admin/poll/questions/answers/videos_controller.rb @@ -1,17 +1,14 @@ 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] + load_and_authorize_resource :answer, class: "::Poll::Question::Answer" + load_and_authorize_resource class: "::Poll::Question::Answer::Video", through: :answer 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") @@ -25,20 +22,16 @@ 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(@answer), notice: t("flash.actions.save_changes.notice") else render :edit end end def destroy - notice = if @video.destroy - t("flash.actions.destroy.poll_question_answer_video") - else - t("flash.actions.destroy.error") - end - redirect_back(fallback_location: (request.referer || root_path), notice: notice) + @video.destroy! + notice = t("flash.actions.destroy.poll_question_answer_video") + redirect_to admin_answer_videos_path(@answer), notice: notice end private @@ -48,14 +41,6 @@ class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseContr end def allowed_params - [: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]) + [:title, :url] end end diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 5e224a514..c015f1ebe 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -1,19 +1,15 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController include Translatable - include DocumentAttributes - - before_action :load_answer, only: [:show, :edit, :update, :documents] load_and_authorize_resource :question, class: "::Poll::Question" + load_and_authorize_resource class: "::Poll::Question::Answer", + through: :question, + through_association: :question_answers def new - @answer = ::Poll::Question::Answer.new end def create - @answer = ::Poll::Question::Answer.new(answer_params) - @question = @answer.question - if @answer.save redirect_to admin_question_path(@question), notice: t("flash.actions.create.poll_question_answer") @@ -22,27 +18,18 @@ 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), + redirect_to admin_question_path(@question), notice: t("flash.actions.save_changes.notice") else render :edit end end - def documents - @documents = @answer.documents - - render "admin/poll/questions/answers/documents" - end - def order_answers ::Poll::Question::Answer.order_answers(params[:ordered_list]) head :ok @@ -55,18 +42,8 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController end def allowed_params - attributes = [:title, :description, :given_order, :question_id, - documents_attributes: document_attributes] + attributes = [:title, :description, :given_order] [*attributes, translation_params(Poll::Question::Answer)] end - - def load_answer - @answer = ::Poll::Question::Answer.find(params[:id] || params[:answer_id]) - end - - def resource - load_answer unless @answer - @answer - end end diff --git a/app/controllers/admin/poll/questions_controller.rb b/app/controllers/admin/poll/questions_controller.rb index bb07a5ac2..598e664e7 100644 --- a/app/controllers/admin/poll/questions_controller.rb +++ b/app/controllers/admin/poll/questions_controller.rb @@ -43,12 +43,8 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController end def destroy - if @question.destroy - notice = "Question destroyed succesfully" - else - notice = t("flash.actions.destroy.error") - end - redirect_to admin_questions_path, notice: notice + @question.destroy! + redirect_to admin_poll_path(@question.poll), notice: t("admin.questions.destroy.notice") end private @@ -66,8 +62,4 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController def search_params params.permit(:poll_id, :search) end - - def resource - @poll_question ||= Poll::Question.find(params[:id]) - end end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 0f492cd0b..e9a455c3c 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -83,13 +83,18 @@ module Abilities can [:index, :create, :update, :destroy], Geozone - can [:read, :create, :update, :destroy, :add_question, :search_booths, :search_officers, :booth_assignments], Poll + can [:read, :create, :update, :destroy, :booth_assignments], Poll can [:read, :create, :update, :destroy, :available], Poll::Booth can [:search, :create, :index, :destroy], ::Poll::Officer can [:create, :destroy, :manage], ::Poll::BoothAssignment can [:create, :destroy], ::Poll::OfficerAssignment can [:read, :create, :update], Poll::Question can :destroy, Poll::Question + can :manage, Poll::Question::Answer + can :manage, Poll::Question::Answer::Video + can [:create, :destroy], Image do |image| + image.imageable_type == "Poll::Question::Answer" + end can :manage, SiteCustomization::Page can :manage, SiteCustomization::Image diff --git a/app/views/admin/poll/polls/edit.html.erb b/app/views/admin/poll/polls/edit.html.erb index f7bd93212..2fd150b35 100644 --- a/app/views/admin/poll/polls/edit.html.erb +++ b/app/views/admin/poll/polls/edit.html.erb @@ -1,4 +1,4 @@ -<%= back_link_to %> +<%= back_link_to admin_polls_path %>

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

diff --git a/app/views/admin/poll/polls/new.html.erb b/app/views/admin/poll/polls/new.html.erb index 528b7ff69..899de8223 100644 --- a/app/views/admin/poll/polls/new.html.erb +++ b/app/views/admin/poll/polls/new.html.erb @@ -1,6 +1,6 @@
- <%= back_link_to %> + <%= back_link_to admin_polls_path %>

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

diff --git a/app/views/admin/poll/questions/answers/_form.html.erb b/app/views/admin/poll/questions/answers/_form.html.erb index 53eceae17..ef32b93e5 100644 --- a/app/views/admin/poll/questions/answers/_form.html.erb +++ b/app/views/admin/poll/questions/answers/_form.html.erb @@ -7,8 +7,6 @@ <%= f.hidden_field :given_order, value: @answer.persisted? ? @answer.given_order : @answer.class.last_position(@answer.question_id || @question.id) + 1 %> - <%= f.hidden_field :question_id, value: @answer.question_id || @question.id %> -
<%= f.translatable_fields do |translations_form| %>
diff --git a/app/views/admin/poll/questions/answers/documents/index.html.erb b/app/views/admin/poll/questions/answers/documents/index.html.erb new file mode 100644 index 000000000..037ab68f2 --- /dev/null +++ b/app/views/admin/poll/questions/answers/documents/index.html.erb @@ -0,0 +1 @@ +<%= render Admin::Poll::Questions::Answers::Documents::IndexComponent.new(@answer) %> diff --git a/app/views/admin/poll/questions/answers/edit.html.erb b/app/views/admin/poll/questions/answers/edit.html.erb index 46a8784cc..3abeef3b6 100644 --- a/app/views/admin/poll/questions/answers/edit.html.erb +++ b/app/views/admin/poll/questions/answers/edit.html.erb @@ -1,4 +1,4 @@ -<%= back_link_to %> +<%= back_link_to admin_question_path(@question) %>
<%= video.title %> <%= link_to video.url, video.url %>
- - - - - - - - - - - + + + + + + + + + + + <% @question.question_answers.each do |answer| %> - + + <% end %> diff --git a/config/initializers/routes_hierarchy.rb b/config/initializers/routes_hierarchy.rb index 7fda048ff..e66c8386c 100644 --- a/config/initializers/routes_hierarchy.rb +++ b/config/initializers/routes_hierarchy.rb @@ -25,7 +25,7 @@ module ActionDispatch::Routing::UrlFor def namespaced_polymorphic_path(namespace, resource, options = {}) if %w[Budget::Group Budget::Heading Poll::Booth Poll::BoothAssignment Poll::Officer - Poll::Question Poll::Question::Answer::Video Poll::Shift + Poll::Question Poll::Question::Answer Poll::Question::Answer::Video Poll::Shift SDG::LocalTarget].include?(resource.class.name) resolve = resolve_for(resource) resolve_options = resolve.pop diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index f615458c3..cfc5bf653 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1103,9 +1103,6 @@ en: table_title: "Title" edit_answers: Edit answers see_proposal: "(See proposal)" - flash: - question_added: "Question added to this poll" - error_on_question_added: "Question could not be assigned to this poll" destroy: alert: "This action will remove the poll and all its associated questions." success_notice: "Poll deleted successfully" @@ -1129,6 +1126,8 @@ en: new: title: "Create question to poll %{poll}" title_proposal: "Create question" + destroy: + notice: "Question deleted succesfully" answers: images: add_image: "Add image" @@ -1155,12 +1154,6 @@ en: answers: new: title: New answer - show: - title: Title - description: Description - images: Images - images_list: Images list - edit: Edit answer edit: title: Edit answer videos: diff --git a/config/locales/en/responders.yml b/config/locales/en/responders.yml index 7fb544b97..371cbaf71 100644 --- a/config/locales/en/responders.yml +++ b/config/locales/en/responders.yml @@ -32,7 +32,6 @@ en: translation: "Translation updated successfully" destroy: budget_investment: "Investment project deleted succesfully." - error: "Could not delete" topic: "Topic deleted successfully." poll_question_answer_video: "Answer video deleted successfully." valuator_group: "Valuator group deleted successfully" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index aa861ab09..8e997a466 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1102,9 +1102,6 @@ es: table_title: "Título" edit_answers: Editar respuestas see_proposal: "(Ver propuesta)" - flash: - question_added: "Pregunta añadida a esta votación" - error_on_question_added: "No se pudo asignar la pregunta" destroy: alert: "Esta acción eliminará la votación y todas sus preguntas asociadas." success_notice: "Votación eliminada correctamente" @@ -1128,6 +1125,8 @@ es: new: title: "Crear pregunta ciudadana para la votación %{poll}" title_proposal: "Crear pregunta ciudadana" + destroy: + notice: "Pregunta eliminada correctamente" answers: images: add_image: "Añadir imagen" @@ -1154,12 +1153,6 @@ es: answers: new: title: Nueva respuesta - show: - title: Título - description: Descripción - images: Imágenes - images_list: Lista de imágenes - edit: Editar respuesta edit: title: Editar respuesta videos: diff --git a/config/locales/es/responders.yml b/config/locales/es/responders.yml index 6092cf9ff..4a0b7d415 100644 --- a/config/locales/es/responders.yml +++ b/config/locales/es/responders.yml @@ -32,7 +32,6 @@ es: translation: "Traducción actualizada correctamente" destroy: budget_investment: "Proyecto de gasto eliminado." - error: "No se pudo borrar" topic: "Tema eliminado." poll_question_answer_video: "Vídeo de respuesta eliminado." valuator_group: "Grupo de evaluadores eliminado correctamente" diff --git a/config/routes/admin.rb b/config/routes/admin.rb index bae512e69..84d3e6b68 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -141,7 +141,6 @@ namespace :admin do scope module: :poll do resources :polls do get :booth_assignments, on: :collection - patch :add_question, on: :member resources :booth_assignments, only: [:index, :show, :create, :destroy] do get :search_booths, on: :collection @@ -170,10 +169,11 @@ namespace :admin do end resources :questions, shallow: true do - resources :answers, except: [:index, :destroy], controller: "questions/answers" do + resources :answers, except: [:index, :show, :destroy], controller: "questions/answers", shallow: false + resources :answers, only: [], controller: "questions/answers" do resources :images, controller: "questions/answers/images" - resources :videos, controller: "questions/answers/videos" - get :documents, to: "questions/answers#documents" + resources :videos, controller: "questions/answers/videos", shallow: false + resources :documents, only: [:index, :create], controller: "questions/answers/documents" end post "/answers/order_answers", to: "questions/answers#order_answers" end @@ -323,6 +323,10 @@ resolve "Poll::Officer" do |officer, options| [:officer, options.merge(id: officer)] end -resolve "Poll::Question::Answer::Video" do |video, options| - [:video, options.merge(id: video)] +resolve "Poll::Question::Answer" do |answer, options| + [:question, :answer, options.merge(question_id: answer.question, id: answer)] +end + +resolve "Poll::Question::Answer::Video" do |video, options| + [:answer, :video, options.merge(answer_id: video.answer, id: video)] end diff --git a/config/routes/document.rb b/config/routes/document.rb index 164153b50..03aca1e64 100644 --- a/config/routes/document.rb +++ b/config/routes/document.rb @@ -1,7 +1 @@ -resources :documents, only: [:new, :create, :destroy] do - collection do - get :new_nested - delete :destroy_upload - post :upload - end -end +resources :documents, only: [:destroy] diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index 424638a1b..72e1722ee 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -18,6 +18,8 @@ describe Abilities::Administrator do let(:legislation_question) { create(:legislation_question) } let(:poll) { create(:poll) } let(:poll_question) { create(:poll_question) } + let(:poll_question_answer) { create(:poll_question_answer) } + let(:answer_image) { build(:image, imageable: poll_question_answer) } let(:past_process) { create(:legislation_process, :past) } let(:past_draft_process) { create(:legislation_process, :past, :not_published) } @@ -114,6 +116,13 @@ describe Abilities::Administrator do it { should be_able_to(:create, Poll::Question) } it { should be_able_to(:update, Poll::Question) } + it { should be_able_to(:manage, Poll::Question::Answer) } + + it { should be_able_to(:manage, Poll::Question::Answer::Video) } + + it { should be_able_to(:create, answer_image) } + it { should be_able_to(:destroy, answer_image) } + it { is_expected.to be_able_to :manage, Dashboard::AdministratorTask } it { is_expected.to be_able_to :manage, dashboard_administrator_task } diff --git a/spec/routing/polymorphic_routes_spec.rb b/spec/routing/polymorphic_routes_spec.rb index 814e67b01..5ff9bef09 100644 --- a/spec/routing/polymorphic_routes_spec.rb +++ b/spec/routing/polymorphic_routes_spec.rb @@ -97,7 +97,7 @@ describe "Polymorphic routes" do it "routes poll answer videos" do video = create(:poll_answer_video) - expect(admin_polymorphic_path(video)).to eq admin_video_path(video) + expect(admin_polymorphic_path(video)).to eq admin_answer_video_path(video.answer, video) end it "routes milestones for resources with no hierarchy" do diff --git a/spec/system/admin/poll/polls_spec.rb b/spec/system/admin/poll/polls_spec.rb index a677ca0cc..ede4bd5f3 100644 --- a/spec/system/admin/poll/polls_spec.rb +++ b/spec/system/admin/poll/polls_spec.rb @@ -61,6 +61,7 @@ describe "Admin polls", :admin do expect(page).not_to have_css("#poll_results_enabled") expect(page).not_to have_css("#poll_stats_enabled") + expect(page).to have_link "Go back", href: admin_polls_path click_button "Create poll" @@ -83,6 +84,7 @@ describe "Admin polls", :admin do end_date = 1.year.from_now.to_date expect(page).to have_css("img[alt='#{poll.image.title}']") + expect(page).to have_link "Go back", href: admin_polls_path fill_in "Name", with: "Next Poll" fill_in "poll_ends_at", with: end_date diff --git a/spec/system/admin/poll/questions/answers/answers_spec.rb b/spec/system/admin/poll/questions/answers/answers_spec.rb index 262ed7d7f..3b12ce770 100644 --- a/spec/system/admin/poll/questions/answers/answers_spec.rb +++ b/spec/system/admin/poll/questions/answers/answers_spec.rb @@ -7,6 +7,8 @@ describe "Answers", :admin do visit admin_question_path(question) click_link "Add answer" + expect(page).to have_link "Go back", href: admin_question_path(question) + fill_in "Answer", with: "The answer is always 42" fill_in_ckeditor "Description", with: "The Hitchhiker's Guide To The Universe" @@ -33,15 +35,15 @@ describe "Answers", :admin do scenario "Update" do question = create(:poll_question) - answer = create(:poll_question_answer, question: question, title: "Answer title", given_order: 2) + create(:poll_question_answer, question: question, title: "Answer title", given_order: 2) create(:poll_question_answer, question: question, title: "Another title", given_order: 1) - visit admin_answer_path(answer) + visit admin_question_path(question) + within("tr", text: "Answer title") { click_link "Edit" } - click_link "Edit answer" + expect(page).to have_link "Go back", href: admin_question_path(question) fill_in "Answer", with: "New title" - click_button "Save" expect(page).to have_content "Changes saved" diff --git a/spec/system/admin/poll/questions/answers/documents/documents_spec.rb b/spec/system/admin/poll/questions/answers/documents/documents_spec.rb index c64b52bb4..1ab90af53 100644 --- a/spec/system/admin/poll/questions/answers/documents/documents_spec.rb +++ b/spec/system/admin/poll/questions/answers/documents/documents_spec.rb @@ -9,6 +9,7 @@ describe "Documents", :admin do visit admin_answer_documents_path(answer) expect(page).not_to have_content(document.title) + expect(page).to have_link "Go back", href: admin_question_path(answer.question) end scenario "Answer with documents" do @@ -21,6 +22,18 @@ describe "Documents", :admin do end end + scenario "Create document for answer" do + answer = create(:poll_question_answer) + + visit admin_answer_documents_path(answer) + + documentable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.pdf")) + click_button "Save" + + expect(page).to have_content "Document uploaded succesfully" + expect(page).to have_link "clippy.pdf" + end + scenario "Remove document from answer" do answer = create(:poll_question_answer) document = create(:document, documentable: answer) 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..b4d2cdfab 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,55 @@ 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_answer_video_path(answer, video) + + expect(page).to have_link "Go back", href: admin_answer_videos_path(answer) + + 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 diff --git a/spec/system/admin/poll/questions_spec.rb b/spec/system/admin/poll/questions_spec.rb index f7062ea67..14a622e37 100644 --- a/spec/system/admin/poll/questions_spec.rb +++ b/spec/system/admin/poll/questions_spec.rb @@ -50,8 +50,9 @@ describe "Admin poll questions", :admin do visit admin_poll_path(poll) click_link "Edit answers" - expect(page).to have_content(question.title) - expect(page).to have_content(question.author.name) + expect(page).to have_link "Go back", href: admin_poll_path(poll) + expect(page).to have_content question.title + expect(page).to have_content question.author.name end scenario "Create" do @@ -123,6 +124,7 @@ describe "Admin poll questions", :admin do click_link "Edit" end + expect(page).to have_link "Go back", href: admin_poll_path(poll) old_title = question1.title new_title = "Potatoes are great and everyone should have one" fill_in "Question", with: new_title @@ -147,8 +149,9 @@ describe "Admin poll questions", :admin do end end - expect(page).not_to have_content(question1.title) - expect(page).to have_content(question2.title) + expect(page).not_to have_content question1.title + expect(page).to have_content question2.title + expect(page).to have_current_path admin_poll_path(poll) end context "Poll select box" do diff --git a/spec/system/admin/translatable_spec.rb b/spec/system/admin/translatable_spec.rb index fe9d80a8d..09602ae16 100644 --- a/spec/system/admin/translatable_spec.rb +++ b/spec/system/admin/translatable_spec.rb @@ -216,7 +216,7 @@ describe "Admin edit translatable records", :admin do context "CKEditor fields" do let(:translatable) { create(:poll_question_answer) } - let(:path) { edit_admin_answer_path(translatable) } + let(:path) { edit_admin_question_answer_path(translatable.question, translatable) } scenario "Changes the existing translation" do visit path
- <%= t("admin.questions.show.valid_answers") %> -
<%= t("admin.questions.show.answers.title") %><%= t("admin.questions.show.answers.description") %><%= t("admin.questions.show.answers.images") %><%= t("admin.questions.show.answers.documents") %><%= t("admin.questions.show.answers.videos") %>
<%= t("admin.questions.show.valid_answers") %>
<%= t("admin.questions.show.answers.title") %><%= t("admin.questions.show.answers.description") %><%= t("admin.questions.show.answers.images") %><%= t("admin.questions.show.answers.documents") %><%= t("admin.questions.show.answers.videos") %><%= t("admin.actions.actions") %>
<%= link_to answer.title, admin_answer_path(answer) %><%= answer.title %> <%= wysiwyg(answer.description) %> (<%= answer.images.count %>) @@ -72,6 +70,9 @@ <%= link_to t("admin.questions.show.answers.video_list"), admin_answer_videos_path(answer) %> + <%= render Admin::TableActionsComponent.new(answer, actions: [:edit]) %> +