Merge pull request #4054 from consul/allow_delete_polls_with_videos

Allow deleting polls with answers including videos
This commit is contained in:
Javier Martín
2020-07-09 13:50:35 +02:00
committed by GitHub
2 changed files with 14 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ class Poll::Question::Answer < ApplicationRecord
accepts_nested_attributes_for :documents, allow_destroy: true
belongs_to :question, class_name: "Poll::Question"
has_many :videos, class_name: "Poll::Question::Answer::Video"
has_many :videos, class_name: "Poll::Question::Answer::Video", dependent: :destroy
validates_translation :title, presence: true
validates :given_order, presence: true, uniqueness: { scope: :question_id }

View File

@@ -145,6 +145,19 @@ describe "Admin polls" do
expect(Poll::Question::Answer.count).to eq(0)
end
scenario "Can destroy polls with answers including videos", :js do
poll = create(:poll, name: "Do you support CONSUL?")
create(:poll_answer_video, poll: poll)
visit admin_polls_path
within(".poll", text: "Do you support CONSUL?") do
accept_confirm { click_link "Delete" }
end
expect(page).to have_content "Poll deleted successfully"
end
scenario "Can't destroy poll with votes", :js do
poll = create(:poll)
create(:poll_question, poll: poll)