Remove instance variables in RSpec

Instance variables might lead to hard-to-detect issues, since using a
nonexistent instance variable will return `nil` instead of raising an
error.
This commit is contained in:
Javi Martín
2019-09-29 14:01:55 +02:00
parent f70e10fe9f
commit 91c21b0982
39 changed files with 639 additions and 667 deletions

View File

@@ -299,12 +299,13 @@ describe "Legislation Draft Versions" do
before do
create(:legislation_annotation, draft_version: draft_version, text: "my annotation", quote: "ipsum",
ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }])
@annotation = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", quote: "audiam",
ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }])
end
scenario "See one annotation with replies for a draft version" do
visit legislation_process_draft_version_annotation_path(draft_version.process, draft_version, @annotation)
annotation = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", quote: "audiam",
ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }])
visit legislation_process_draft_version_annotation_path(draft_version.process, draft_version, annotation)
expect(page).not_to have_content "ipsum"
expect(page).not_to have_content "my annotation"

View File

@@ -2,15 +2,20 @@ require "rails_helper"
describe "Legislation" do
context "process debate page" do
let(:process) do
create(:legislation_process,
debate_start_date: Date.current - 3.days,
debate_end_date: Date.current + 2.days)
end
before do
@process = create(:legislation_process, debate_start_date: Date.current - 3.days, debate_end_date: Date.current + 2.days)
create(:legislation_question, process: @process, title: "Question 1")
create(:legislation_question, process: @process, title: "Question 2")
create(:legislation_question, process: @process, title: "Question 3")
create(:legislation_question, process: process, title: "Question 1")
create(:legislation_question, process: process, title: "Question 2")
create(:legislation_question, process: process, title: "Question 3")
end
scenario "shows question list" do
visit legislation_process_path(@process)
visit legislation_process_path(process)
expect(page).to have_content("Participate in the debate")
@@ -35,14 +40,14 @@ describe "Legislation" do
end
scenario "shows question page" do
visit legislation_process_question_path(@process, @process.questions.first)
visit legislation_process_question_path(process, process.questions.first)
expect(page).to have_content("Question 1")
expect(page).to have_content("Open answers (0)")
end
scenario "shows next question link in question page" do
visit legislation_process_question_path(@process, @process.questions.first)
visit legislation_process_question_path(process, process.questions.first)
expect(page).to have_content("Question 1")
expect(page).to have_content("Next question")
@@ -59,7 +64,7 @@ describe "Legislation" do
end
scenario "answer question" do
question = @process.questions.first
question = process.questions.first
create(:legislation_question_option, question: question, value: "Yes")
create(:legislation_question_option, question: question, value: "No")
option = create(:legislation_question_option, question: question, value: "I don't know")
@@ -67,7 +72,7 @@ describe "Legislation" do
login_as(user)
visit legislation_process_question_path(@process, question)
visit legislation_process_question_path(process, question)
expect(page).to have_selector(:radio_button, "Yes")
expect(page).to have_selector(:radio_button, "No")
@@ -89,8 +94,8 @@ describe "Legislation" do
end
scenario "cannot answer question when phase not open" do
@process.update_attribute(:debate_end_date, Date.current - 1.day)
question = @process.questions.first
process.update_attribute(:debate_end_date, Date.current - 1.day)
question = process.questions.first
create(:legislation_question_option, question: question, value: "Yes")
create(:legislation_question_option, question: question, value: "No")
create(:legislation_question_option, question: question, value: "I don't know")
@@ -98,7 +103,7 @@ describe "Legislation" do
login_as(user)
visit legislation_process_question_path(@process, question)
visit legislation_process_question_path(process, question)
expect(page).to have_selector(:radio_button, "Yes", disabled: true)
expect(page).to have_selector(:radio_button, "No", disabled: true)

View File

@@ -17,37 +17,33 @@ describe "Legislation" do
end
context "process empty" do
before do
@process = create(:legislation_process, :empty, end_date: Date.current - 1.day)
end
let(:process) { create(:legislation_process, :empty, end_date: Date.current - 1.day) }
scenario "warning empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("The process have no phases.")
end
end
context "phases empty" do
before do
@process = create(:legislation_process, end_date: Date.current - 1.day)
end
let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
scenario "debates empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase")
expect(page).to have_content("No debates")
expect(page).to have_content("There aren't any questions")
end
scenario "proposals empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase")
expect(page).to have_content("No proposals")
expect(page).to have_content("There are no proposals")
end
scenario "text comments empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase")
expect(page).to have_content("No comments")
expect(page).to have_content("There are no text comments")
@@ -55,31 +51,29 @@ describe "Legislation" do
end
context "process empty" do
before do
@process = create(:legislation_process, :empty, end_date: Date.current - 1.day)
end
let(:process) { create(:legislation_process, :empty, end_date: Date.current - 1.day) }
scenario "warning empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("The process have no phases.")
end
end
context "only debates exist" do
let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
before do
user = create(:user, :level_two)
@process = create(:legislation_process, end_date: Date.current - 1.day)
@debate = create(:legislation_question, process: @process, title: "Question 1")
@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")
@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")
end
scenario "show debates list" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase")
expect(page).to have_content("2 debates")
@@ -97,7 +91,7 @@ describe "Legislation" do
expect(page).not_to have_content("Answer 3")
expect(page).not_to have_content("Answer 4")
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
click_link "Question 2"
expect(page).to have_content("Question 2")
expect(page).not_to have_content("Answer 1")
@@ -108,14 +102,14 @@ describe "Legislation" do
end
scenario "proposals empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase")
expect(page).to have_content("No proposals")
expect(page).to have_content("There are no proposals")
end
scenario "text comments empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase")
expect(page).to have_content("No comments")
expect(page).to have_content("There are no text comments")
@@ -123,27 +117,28 @@ describe "Legislation" do
end
context "only proposals exist" do
let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
before do
@process = create(:legislation_process, end_date: Date.current - 1.day)
create(:legislation_proposal, legislation_process_id: @process.id,
create(:legislation_proposal, legislation_process_id: process.id,
title: "Legislation proposal 1", selected: true)
create(:legislation_proposal, legislation_process_id: @process.id,
create(:legislation_proposal, legislation_process_id: process.id,
title: "Legislation proposal 2", selected: false)
create(:legislation_proposal, legislation_process_id: @process.id,
create(:legislation_proposal, legislation_process_id: process.id,
title: "Legislation proposal 3", selected: true)
create(:legislation_proposal, legislation_process_id: @process.id,
create(:legislation_proposal, legislation_process_id: process.id,
title: "Legislation proposal 4", selected: false)
end
scenario "debates empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase")
expect(page).to have_content("No debates")
expect(page).to have_content("There aren't any questions")
end
scenario "proposals empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase")
expect(page).to have_content("2 proposals")
@@ -155,14 +150,14 @@ describe "Legislation" do
click_link "Legislation proposal 1"
expect(page).to have_content("Legislation proposal 1")
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
click_link "Legislation proposal 3"
expect(page).to have_content("Legislation proposal 3")
end
scenario "text comments empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase")
expect(page).to have_content("No comments")
expect(page).to have_content("There are no text comments")
@@ -170,13 +165,14 @@ describe "Legislation" do
end
context "only text comments exist" do
let(:process) { create(:legislation_process, end_date: Date.current - 1.day) }
before do
user = create(:user, :level_two)
@process = create(:legislation_process, end_date: Date.current - 1.day)
draft_version_1 = create(:legislation_draft_version, process: @process,
draft_version_1 = create(:legislation_draft_version, process: process,
title: "Version 1", body: "Body of the first version",
status: "published")
draft_version_2 = create(:legislation_draft_version, process: @process,
draft_version_2 = create(:legislation_draft_version, process: process,
title: "Version 2", body: "Body of the second version and that's it all of it",
status: "published")
annotation0 = create(:legislation_annotation,
@@ -196,21 +192,21 @@ describe "Legislation" do
end
scenario "debates empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Debates phase")
expect(page).to have_content("No debates")
expect(page).to have_content("There aren't any questions")
end
scenario "proposals empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Proposal phase")
expect(page).to have_content("No proposals")
expect(page).to have_content("There are no proposals")
end
scenario "text comments empty" do
visit resume_legislation_process_path(@process)
visit resume_legislation_process_path(process)
expect(page).to have_content("Text comment phase (version Version 2")
expect(page).to have_content("5 comments")
expect(page).not_to have_content("Comment 0")
@@ -223,7 +219,7 @@ describe "Legislation" do
end
# scenario "excel download" do
# visit resume_legislation_process_path(@process)
# visit resume_legislation_process_path(process)
# click_link "Download"
# page.response_headers['Content-Type'].should eq "application/xlsx"
# end
@@ -234,9 +230,9 @@ describe "Legislation" do
before do
user = create(:user, :level_two)
@process = create(:legislation_process, end_date: Date.current - 1.day)
@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 1")
create(:comment, user: user, commentable: debate, body: "Answer 1")
create(:comment, user: user, commentable: debate, body: "Answer 2")
end
it "download execl file test" do