Allow deleting polls with answers including videos

If a poll has a question with an answer containing a related video,
an error was raised because the poll ID was referenced in another
table.
This commit is contained in:
Julian Herrero
2020-06-25 11:33:40 +07:00
committed by Javi Martín
parent 8059c55fef
commit 89962ba61a
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)