From 5c81a70fa7080cc4d55b7c2525f0fc80f0bb6e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 29 Sep 2019 16:11:34 +0200 Subject: [PATCH] Use factory bot blocks to create complex data Having two questions, each of them with two comments, made the code hard to follow. Grouping the comments inside the block creating the questions makes it easier to know which comment belongs to which question, even if the code is still not 100% readable. We also remove instance variables, which by the way used the same variable name for two different things. --- spec/features/legislation/resume_spec.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/spec/features/legislation/resume_spec.rb b/spec/features/legislation/resume_spec.rb index f00055315..4c035b733 100644 --- a/spec/features/legislation/resume_spec.rb +++ b/spec/features/legislation/resume_spec.rb @@ -64,12 +64,16 @@ describe "Legislation" do before do user = create(:user, :level_two) - @debate = create(:legislation_question, process: process, title: "Question 1") - create(:comment, user: user, commentable: @debate, body: "Answer 1") - create(:comment, user: user, commentable: @debate, body: "Answer 2") - @debate = create(:legislation_question, process: process, title: "Question 2") - create(:comment, user: user, commentable: @debate, body: "Answer 3") - create(:comment, user: user, commentable: @debate, body: "Answer 4") + + create(:legislation_question, process: process, title: "Question 1") do |question| + create(:comment, user: user, commentable: question, body: "Answer 1") + create(:comment, user: user, commentable: question, body: "Answer 2") + end + + create(:legislation_question, process: process, title: "Question 2") do |question| + create(:comment, user: user, commentable: question, body: "Answer 3") + create(:comment, user: user, commentable: question, body: "Answer 4") + end end scenario "show debates list" do