diff --git a/spec/factories.rb b/spec/factories.rb index 8ada920b8..c0cbd1cc1 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -629,6 +629,7 @@ FactoryGirl.define do allegations_phase_enabled true draft_publication_enabled true result_publication_enabled true + published true trait :next do start_date Date.current + 2.days @@ -662,6 +663,11 @@ FactoryGirl.define do allegations_end_date Date.current + 3.days result_publication_date Date.current + 5.days end + + trait :not_published do + published false + end + end factory :legislation_draft_version, class: 'Legislation::DraftVersion' do diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index e945f6ce8..8ad2fa456 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -88,6 +88,7 @@ feature 'Admin legislation processes' do expect(page).to have_selector("h2", text: "An example legislation process") expect(find("#legislation_process_debate_phase_enabled")).to be_checked + expect(find("#legislation_process_published")).to be_checked fill_in 'legislation_process_summary', with: '' click_button "Save changes" diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb index 282b13191..0ef5e0c7c 100644 --- a/spec/features/legislation/processes_spec.rb +++ b/spec/features/legislation/processes_spec.rb @@ -2,6 +2,27 @@ require 'rails_helper' feature 'Legislation' do + let!(:administrator) { create(:administrator).user } + shared_examples "not published permissions" do |path| + + let(:not_published_process) { create(:legislation_process, :not_published, title: "Process not published") } + let!(:not_permission_message) { "You do not have permission to carry out the action" } + + it "is forbidden for a normal user" do + visit send(path, not_published_process) + + expect(page).to have_content not_permission_message + expect(page).to_not have_content("Process not published") + end + + it "is available for an administrator user" do + login_as(administrator) + visit send(path, not_published_process) + + expect(page).to have_content("Process not published") + end + end + context 'processes home page' do scenario 'Processes can be listed' do @@ -45,9 +66,57 @@ feature 'Legislation' do expect(page).to_not have_content('Process next') expect(page).to have_content('Process past') end + + context "not published processes" do + before do + create(:legislation_process, title: "published") + create(:legislation_process, :not_published, title: "not published") + [:next, :past].each do |trait| + create(:legislation_process, trait, title: "#{trait} published") + create(:legislation_process, :not_published, trait, title: "#{trait} not published") + end + end + + it "aren't listed" do + visit legislation_processes_path + expect(page).to_not have_content('not published') + expect(page).to have_content('published') + + login_as(administrator) + visit legislation_processes_path + expect(page).to_not have_content('not published') + expect(page).to have_content('published') + end + + it "aren't listed with next filter" do + visit legislation_processes_path(filter: 'next') + expect(page).to_not have_content('not published') + expect(page).to have_content('next published') + + login_as(administrator) + visit legislation_processes_path(filter: 'next') + expect(page).to_not have_content('not published') + expect(page).to have_content('next published') + end + + it "aren't listed with past filter" do + visit legislation_processes_path(filter: 'past') + expect(page).to_not have_content('not published') + expect(page).to have_content('past published') + + login_as(administrator) + visit legislation_processes_path(filter: 'past') + expect(page).to_not have_content('not published') + expect(page).to have_content('past published') + end + end end context 'process page' do + context "show" do + include_examples "not published permissions", :legislation_process_path + end + context 'debate phase' do scenario 'not open' do process = create(:legislation_process, debate_start_date: Date.current + 1.day, debate_end_date: Date.current + 2.days) @@ -64,6 +133,8 @@ feature 'Legislation' do expect(page).to have_content("Participate in the debate") end + + include_examples "not published permissions", :debate_legislation_process_path end context 'draft publication phase' do @@ -82,6 +153,8 @@ feature 'Legislation' do expect(page).to have_content("Nothing published yet") end + + include_examples "not published permissions", :draft_publication_legislation_process_path end context 'allegations phase' do @@ -100,6 +173,8 @@ feature 'Legislation' do expect(page).to have_content("Nothing published yet") end + + include_examples "not published permissions", :allegations_legislation_process_path end context 'final version publication phase' do @@ -118,6 +193,8 @@ feature 'Legislation' do expect(page).to have_content("Nothing published yet") end + + include_examples "not published permissions", :result_publication_legislation_process_path end end end