diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index de3524492..72b18fbfd 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -8,69 +8,76 @@ describe "Legislation Draft Versions" do end context "See draft text page" do + let(:process) { create(:legislation_process) } + + let!(:original) do + create(:legislation_draft_version, process: process, title: "Original", + body: "Original version", status: "published") + end + + let!(:draft) do + create(:legislation_draft_version, process: process, title: "Draft", + body: "Draft version", status: "draft") + end + before do - @process = create(:legislation_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, title: "Version 2", - body: "Body of the second version", status: "published") - @draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", - body: "Body of the third version", status: "draft") + create(:legislation_draft_version, process: process, title: "Current", + body: "Current version", status: "published") end it "shows the text body for this version" do - visit legislation_process_draft_version_path(@process, @draft_version_1) + visit legislation_process_draft_version_path(process, original) - expect(page).to have_content("Body of the first version") + expect(page).to have_content("Original version") within("select#draft_version_id") do - expect(page).to have_content("Version 1") - expect(page).to have_content("Version 2") - expect(page).not_to have_content("Version 3") + expect(page).to have_content("Original") + expect(page).to have_content("Current") + expect(page).not_to have_content("Draft") end end it "shows an unpublished version to admins" do login_as(administrator) - visit legislation_process_draft_version_path(@process, @draft_version_3) + visit legislation_process_draft_version_path(process, draft) - expect(page).to have_content("Body of the third version") + expect(page).to have_content("Draft version") within("select#draft_version_id") do - expect(page).to have_content("Version 1") - expect(page).to have_content("Version 2") - expect(page).to have_content("Version 3 *") + expect(page).to have_content("Original") + expect(page).to have_content("Current") + expect(page).to have_content("Draft *") end end it "switches to another version without js" do - visit legislation_process_draft_version_path(@process, @draft_version_1) - expect(page).to have_content("Body of the first version") + visit legislation_process_draft_version_path(process, original) + expect(page).to have_content("Original version") - select("Version 2") + select("Current") click_button "see" - expect(page).not_to have_content("Body of the first version") - expect(page).to have_content("Body of the second version") + expect(page).not_to have_content("Original version") + expect(page).to have_content("Current version") end it "switches to another version with js", :js do - visit legislation_process_draft_version_path(@process, @draft_version_1) - expect(page).to have_content("Body of the first version") + visit legislation_process_draft_version_path(process, original) + expect(page).to have_content("Original version") - select("Version 2") + select("Current") - expect(page).not_to have_content("Body of the first version") - expect(page).to have_content("Body of the second version") + expect(page).not_to have_content("Original version") + expect(page).to have_content("Current version") end context "for final versions" do it "does not show the comments panel" do - final_version = create(:legislation_draft_version, process: @process, title: "Final version", + final_version = create(:legislation_draft_version, process: process, title: "Final version", body: "Final body", status: "published", final_version: true) - visit legislation_process_draft_version_path(@process, final_version) + visit legislation_process_draft_version_path(process, final_version) expect(page).to have_content("Final body") expect(page).not_to have_content("See all comments") @@ -82,47 +89,54 @@ describe "Legislation Draft Versions" do end context "See changes page" do + let(:process) { create(:legislation_process) } + + let!(:original) do + create(:legislation_draft_version, process: process, title: "Original", body: "Original version", + changelog: "Changes for first version", status: "published") + end + + let!(:draft) do + create(:legislation_draft_version, process: process, title: "Draft", body: "Draft version", + changelog: "Changes for third version", status: "draft") + end + before do - @process = create(:legislation_process) - @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", - changelog: "Changes for first version", status: "published") - @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", - changelog: "Changes for second version", status: "published") - @draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", body: "Body of the third version", - changelog: "Changes for third version", status: "draft") + create(:legislation_draft_version, process: process, title: "Current", body: "Current version", + changelog: "Changes for second version", status: "published") end it "shows the changes for this version" do - visit legislation_process_draft_version_changes_path(@process, @draft_version_1) + visit legislation_process_draft_version_changes_path(process, original) expect(page).to have_content("Changes for first version") within("select#draft_version_id") do - expect(page).to have_content("Version 1") - expect(page).to have_content("Version 2") - expect(page).not_to have_content("Version 3") + expect(page).to have_content("Original") + expect(page).to have_content("Current") + expect(page).not_to have_content("Draft") end end it "shows an unpublished version to admins" do login_as(administrator) - visit legislation_process_draft_version_changes_path(@process, @draft_version_3) + visit legislation_process_draft_version_changes_path(process, draft) expect(page).to have_content("Changes for third version") within("select#draft_version_id") do - expect(page).to have_content("Version 1") - expect(page).to have_content("Version 2") - expect(page).to have_content("Version 3 *") + expect(page).to have_content("Original") + expect(page).to have_content("Current") + expect(page).to have_content("Draft *") end end it "switches to another version without js" do - visit legislation_process_draft_version_changes_path(@process, @draft_version_1) + visit legislation_process_draft_version_changes_path(process, original) expect(page).to have_content("Changes for first version") - select("Version 2") + select("Current") click_button "see" expect(page).not_to have_content("Changes for first version") @@ -130,10 +144,10 @@ describe "Legislation Draft Versions" do end it "switches to another version with js", :js do - visit legislation_process_draft_version_changes_path(@process, @draft_version_1) + visit legislation_process_draft_version_changes_path(process, original) expect(page).to have_content("Changes for first version") - select("Version 2") + select("Current") expect(page).not_to have_content("Changes for first version") expect(page).to have_content("Changes for second version") @@ -258,23 +272,22 @@ describe "Legislation Draft Versions" do end context "switching versions" do + let(:process) { create(:legislation_process) } + let(:original) { create(:legislation_draft_version, :published, process: process, title: "Original") } + let(:current) { create(:legislation_draft_version, :published, process: process, title: "Current") } + before do - @process = create(:legislation_process) - @draft_version_1 = create(:legislation_draft_version, :published, process: @process, - title: "Version 1", body: "Text with quote for version 1") - create(:legislation_annotation, draft_version: @draft_version_1, text: "annotation for version 1", quote: "quote for version 1", - ranges: [{ "start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30 }]) - @draft_version_2 = create(:legislation_draft_version, :published, process: @process, - title: "Version 2", body: "Text with quote for version 2") - create(:legislation_annotation, draft_version: @draft_version_2, text: "annotation for version 2", quote: "quote for version 2", - ranges: [{ "start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30 }]) + create(:legislation_annotation, draft_version: original, quote: "quote for version 1", + ranges: [{ "start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30 }]) + create(:legislation_annotation, draft_version: current, quote: "quote for version 2", + ranges: [{ "start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30 }]) end scenario "without js" do - visit legislation_process_draft_version_annotations_path(@process, @draft_version_1) + visit legislation_process_draft_version_annotations_path(process, original) expect(page).to have_content("quote for version 1") - select("Version 2") + select("Current") click_button "see" expect(page).not_to have_content("quote for version 1") @@ -282,10 +295,10 @@ describe "Legislation Draft Versions" do end scenario "with js", :js do - visit legislation_process_draft_version_annotations_path(@process, @draft_version_1) + visit legislation_process_draft_version_annotations_path(process, original) expect(page).to have_content("quote for version 1") - select("Version 2") + select("Current") expect(page).not_to have_content("quote for version 1") expect(page).to have_content("quote for version 2")