Add tests to check visibility of processes depending on published attribute

This commit is contained in:
Eduardo Martinez Echevarria
2017-06-29 17:53:20 +02:00
parent 3e5c5d7e49
commit 0bc318c823
3 changed files with 84 additions and 0 deletions

View File

@@ -629,6 +629,7 @@ FactoryGirl.define do
allegations_phase_enabled true allegations_phase_enabled true
draft_publication_enabled true draft_publication_enabled true
result_publication_enabled true result_publication_enabled true
published true
trait :next do trait :next do
start_date Date.current + 2.days start_date Date.current + 2.days
@@ -662,6 +663,11 @@ FactoryGirl.define do
allegations_end_date Date.current + 3.days allegations_end_date Date.current + 3.days
result_publication_date Date.current + 5.days result_publication_date Date.current + 5.days
end end
trait :not_published do
published false
end
end end
factory :legislation_draft_version, class: 'Legislation::DraftVersion' do factory :legislation_draft_version, class: 'Legislation::DraftVersion' do

View File

@@ -88,6 +88,7 @@ feature 'Admin legislation processes' do
expect(page).to have_selector("h2", text: "An example legislation process") 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_debate_phase_enabled")).to be_checked
expect(find("#legislation_process_published")).to be_checked
fill_in 'legislation_process_summary', with: '' fill_in 'legislation_process_summary', with: ''
click_button "Save changes" click_button "Save changes"

View File

@@ -2,6 +2,27 @@ require 'rails_helper'
feature 'Legislation' do 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 context 'processes home page' do
scenario 'Processes can be listed' 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_not have_content('Process next')
expect(page).to have_content('Process past') expect(page).to have_content('Process past')
end 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 end
context 'process page' do context 'process page' do
context "show" do
include_examples "not published permissions", :legislation_process_path
end
context 'debate phase' do context 'debate phase' do
scenario 'not open' do scenario 'not open' do
process = create(:legislation_process, debate_start_date: Date.current + 1.day, debate_end_date: Date.current + 2.days) 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") expect(page).to have_content("Participate in the debate")
end end
include_examples "not published permissions", :debate_legislation_process_path
end end
context 'draft publication phase' do context 'draft publication phase' do
@@ -82,6 +153,8 @@ feature 'Legislation' do
expect(page).to have_content("Nothing published yet") expect(page).to have_content("Nothing published yet")
end end
include_examples "not published permissions", :draft_publication_legislation_process_path
end end
context 'allegations phase' do context 'allegations phase' do
@@ -100,6 +173,8 @@ feature 'Legislation' do
expect(page).to have_content("Nothing published yet") expect(page).to have_content("Nothing published yet")
end end
include_examples "not published permissions", :allegations_legislation_process_path
end end
context 'final version publication phase' do context 'final version publication phase' do
@@ -118,6 +193,8 @@ feature 'Legislation' do
expect(page).to have_content("Nothing published yet") expect(page).to have_content("Nothing published yet")
end end
include_examples "not published permissions", :result_publication_legislation_process_path
end end
end end
end end