Simplify creating videos for a poll in specs

This commit is contained in:
Javi Martín
2019-09-28 01:26:11 +02:00
parent 11723fbb72
commit f535d81877
2 changed files with 10 additions and 6 deletions

View File

@@ -129,16 +129,22 @@ FactoryBot.define do
end end
factory :poll_question_answer, class: "Poll::Question::Answer" do factory :poll_question_answer, class: "Poll::Question::Answer" do
association :question, factory: :poll_question
sequence(:title) { |n| "Answer title #{n}" } sequence(:title) { |n| "Answer title #{n}" }
sequence(:description) { |n| "Answer description #{n}" } sequence(:description) { |n| "Answer description #{n}" }
sequence(:given_order) { |n| n } sequence(:given_order) { |n| n }
transient { poll { association(:poll) } }
question { association(:poll_question, poll: poll) }
end end
factory :poll_answer_video, class: "Poll::Question::Answer::Video" do factory :poll_answer_video, class: "Poll::Question::Answer::Video" do
association :answer, factory: :poll_question_answer
title { "Sample video title" } title { "Sample video title" }
url { "https://youtu.be/nhuNb0XtRhQ" } url { "https://youtu.be/nhuNb0XtRhQ" }
transient { poll { association(:poll) } }
answer { association(:poll_question_answer, poll: poll) }
end end
factory :poll_booth, class: "Poll::Booth" do factory :poll_booth, class: "Poll::Booth" do

View File

@@ -136,13 +136,11 @@ describe "Polls" do
end end
scenario "Show answers with videos" do scenario "Show answers with videos" do
question = create(:poll_question, poll: poll) create(:poll_answer_video, poll: poll, title: "Awesome video", url: "youtube.com/watch?v=123")
answer = create(:poll_question_answer, question: question, title: "Chewbacca")
video = create(:poll_answer_video, answer: answer, title: "Awesome project video", url: "https://www.youtube.com/watch?v=123")
visit poll_path(poll) visit poll_path(poll)
expect(page).to have_link("Awesome project video", href: "https://www.youtube.com/watch?v=123") expect(page).to have_link("Awesome video", href: "youtube.com/watch?v=123")
end end
scenario "Lists questions from proposals as well as regular ones" do scenario "Lists questions from proposals as well as regular ones" do