Extract draft version variable to a let block

This way we can reuse the code (in some cases) and we can avoid instance
variables (in some other cases).
This commit is contained in:
Javi Martín
2019-09-22 21:37:29 +02:00
parent c6808c9c12
commit 297466fc80

View File

@@ -142,12 +142,12 @@ describe "Legislation Draft Versions" do
context "Annotations", :js do context "Annotations", :js do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:draft_version) { create(:legislation_draft_version, :published) }
before { login_as user } before { login_as user }
scenario "Visit as anonymous" do scenario "Visit as anonymous" do
logout logout
draft_version = create(:legislation_draft_version, :published)
visit legislation_process_draft_version_path(draft_version.process, draft_version) visit legislation_process_draft_version_path(draft_version.process, draft_version)
@@ -158,8 +158,6 @@ describe "Legislation Draft Versions" do
end end
scenario "Create" do scenario "Create" do
draft_version = create(:legislation_draft_version, :published)
visit legislation_process_draft_version_path(draft_version.process, draft_version) visit legislation_process_draft_version_path(draft_version.process, draft_version)
page.find(:css, ".legislation-annotatable").double_click page.find(:css, ".legislation-annotatable").double_click
@@ -182,7 +180,6 @@ describe "Legislation Draft Versions" do
end end
scenario "View annotations and comments" do scenario "View annotations and comments" do
draft_version = create(:legislation_draft_version, :published)
annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation",
ranges: [{ "start" => "/p[1]", "startOffset" => 5, "end" => "/p[1]", "endOffset" => 10 }]) ranges: [{ "start" => "/p[1]", "startOffset" => 5, "end" => "/p[1]", "endOffset" => 10 }])
create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", create(:legislation_annotation, draft_version: draft_version, text: "my other annotation",
@@ -201,7 +198,6 @@ describe "Legislation Draft Versions" do
end end
scenario "Publish new comment for an annotation from comments box" do scenario "Publish new comment for an annotation from comments box" do
draft_version = create(:legislation_draft_version, :published)
annotation = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", annotation = create(:legislation_annotation, draft_version: draft_version, text: "my annotation",
ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }]) ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }])
@@ -219,13 +215,12 @@ describe "Legislation Draft Versions" do
end end
context "Merged annotations", :js do context "Merged annotations", :js do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:draft_version) { create(:legislation_draft_version, :published) }
before { login_as user } before { login_as user }
scenario "View annotations and comments in an included range" do scenario "View annotations and comments in an included range" do
draft_version = create(:legislation_draft_version, :published)
annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation",
ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 5 }]) ranges: [{ "start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 5 }])
annotation2 = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", annotation2 = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation",
@@ -246,16 +241,17 @@ describe "Legislation Draft Versions" do
end end
context "Annotations page" do context "Annotations page" do
let(:draft_version) { create(:legislation_draft_version, :published) }
before do before do
@draft_version = create(:legislation_draft_version, :published) create(:legislation_annotation, draft_version: draft_version, text: "my annotation", quote: "ipsum",
create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "ipsum",
ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }]) ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }])
create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "audiam", create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", quote: "audiam",
ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }]) ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }])
end end
scenario "See all annotations for a draft version" do scenario "See all annotations for a draft version" do
visit legislation_process_draft_version_annotations_path(@draft_version.process, @draft_version) visit legislation_process_draft_version_annotations_path(draft_version.process, draft_version)
expect(page).to have_content "ipsum" expect(page).to have_content "ipsum"
expect(page).to have_content "audiam" expect(page).to have_content "audiam"
@@ -298,16 +294,17 @@ describe "Legislation Draft Versions" do
end end
context "Annotation comments page" do context "Annotation comments page" do
let(:draft_version) { create(:legislation_draft_version, :published) }
before do before do
@draft_version = create(:legislation_draft_version, :published) create(:legislation_annotation, draft_version: draft_version, text: "my annotation", quote: "ipsum",
create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "ipsum",
ranges: [{ "start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11 }]) 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", @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 }]) ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }])
end end
scenario "See one annotation with replies for a draft version" do scenario "See one annotation with replies for a draft version" do
visit legislation_process_draft_version_annotation_path(@draft_version.process, @draft_version, @annotation) 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 "ipsum"
expect(page).not_to have_content "my annotation" expect(page).not_to have_content "my annotation"