Add draft/publish status for procedure.

This commit is contained in:
Guillaume Lazzara 2016-06-09 17:49:38 +02:00
parent b987b86bd8
commit 2791988da2
22 changed files with 341 additions and 71 deletions

View file

@ -7,7 +7,7 @@ class Admin::ProceduresController < AdminController
def index def index
@procedures = smart_listing_create :procedures, @procedures = smart_listing_create :procedures,
current_administrateur.procedures.where(archived: false), current_administrateur.procedures.where(published: true, archived: false),
partial: "admin/procedures/list", partial: "admin/procedures/list",
array: true array: true
@ -25,6 +25,18 @@ class Admin::ProceduresController < AdminController
render 'index' render 'index'
end end
def draft
@procedures = smart_listing_create :procedures,
current_administrateur.procedures.where(published: false, archived: false),
partial: "admin/procedures/draft_list",
array: true
draft_class
render 'index'
end
def show def show
@facade = AdminProceduresShowFacades.new @procedure.decorate @facade = AdminProceduresShowFacades.new @procedure.decorate
end end
@ -63,16 +75,12 @@ class Admin::ProceduresController < AdminController
redirect_to edit_admin_procedure_path(id: @procedure.id) redirect_to edit_admin_procedure_path(id: @procedure.id)
end end
def publish
change_status({published: params[:published]})
end
def archive def archive
@procedure = current_administrateur.procedures.find(params[:procedure_id]) change_status({archived: params[:archive]})
@procedure.update_attributes({archived: params[:archive]})
flash.notice = 'Procédure éditée'
redirect_to admin_procedures_path
rescue ActiveRecord::RecordNotFound
flash.alert = 'Procédure inéxistante'
redirect_to admin_procedures_path
end end
def active_class def active_class
@ -83,6 +91,10 @@ class Admin::ProceduresController < AdminController
@archived_class = 'active' @archived_class = 'active'
end end
def draft_class
@draft_class = 'active'
end
private private
def create_procedure_params def create_procedure_params
@ -92,4 +104,16 @@ class Admin::ProceduresController < AdminController
def create_module_api_carto_params def create_module_api_carto_params
params.require(:procedure).require(:module_api_carto_attributes).permit(:id, :use_api_carto, :quartiers_prioritaires, :cadastre) params.require(:procedure).require(:module_api_carto_attributes).permit(:id, :use_api_carto, :quartiers_prioritaires, :cadastre)
end end
def change_status(status_options)
@procedure = current_administrateur.procedures.find(params[:procedure_id])
@procedure.update_attributes(status_options)
flash.notice = 'Procédure éditée'
redirect_to admin_procedures_path
rescue ActiveRecord::RecordNotFound
flash.alert = 'Procédure inéxistante'
redirect_to admin_procedures_path
end
end end

View file

@ -23,7 +23,7 @@ class Users::DossiersController < UsersController
end end
def new def new
procedure = Procedure.where(archived: false).find(params[:procedure_id]) procedure = Procedure.where(archived: false, published: true).find(params[:procedure_id])
@dossier = Dossier.new(procedure: procedure) @dossier = Dossier.new(procedure: procedure)
@siret = params[:siret] || current_user.siret @siret = params[:siret] || current_user.siret

View file

@ -12,7 +12,7 @@ class Users::SessionsController < Sessions::SessionsController
# GET /resource/sign_in # GET /resource/sign_in
def new def new
unless user_return_to_procedure_id.nil? unless user_return_to_procedure_id.nil?
@dossier = Dossier.new(procedure: Procedure.not_archived(user_return_to_procedure_id)) @dossier = Dossier.new(procedure: Procedure.active(user_return_to_procedure_id))
end end
@user = User.new @user = User.new

View file

@ -33,6 +33,10 @@ class Procedure < ActiveRecord::Base
Procedure.where(archived: false).find(id) Procedure.where(archived: false).find(id)
end end
def self.active id
Procedure.where(archived: false, published: true).find(id)
end
def switch_types_de_champ index_of_first_element def switch_types_de_champ index_of_first_element
switch_list_order(types_de_champ_ordered, index_of_first_element) switch_list_order(types_de_champ_ordered, index_of_first_element)
end end
@ -51,6 +55,7 @@ class Procedure < ActiveRecord::Base
end end
def locked? def locked?
dossiers.where.not(state: :draft).count > 0 published?
end end
end end

View file

@ -0,0 +1,19 @@
- unless smart_listing.empty?
%table.table
%thead
%th#ID= smart_listing.sortable 'ID', 'id'
%th#libelle= smart_listing.sortable 'Libellé', 'libelle'
- @procedures.each do |procedure|
- procedure = procedure.decorate
%tr
%td.col-md-1.col-lg-1= procedure.id
%td.col-md-6.col-lg-6
= link_to(procedure.libelle, "/admin/procedures/#{procedure.id}")
= smart_listing.paginate
= smart_listing.pagination_per_page_links
- else
%h4.center
Aucune procédure

View file

@ -1,5 +1,10 @@
#onglets #onglets
%ul.nav.nav-tabs %ul.nav.nav-tabs
%li{class: @draft_class}
%a{:href => "#{url_for :admin_procedures_draft}"}
%h5{style: 'color: black'}
="Brouillons"
%li{class: @active_class} %li{class: @active_class}
%a{:href => "#{url_for :admin_procedures}"} %a{:href => "#{url_for :admin_procedures}"}
%h5.text-success %h5.text-success

View file

@ -1,30 +1,48 @@
#procedure_show #procedure_show
=render partial: 'head', locals: {active: 'Informations'} =render partial: 'head', locals: {active: 'Informations'}
= form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put, style:'float: right; margin-top: 10px' do -if ! @facade.procedure.published?
%button#archive.btn.btn-small.btn-default.text-info{type: :button} = form_tag admin_procedure_publish_path(procedure_id: @facade.procedure.id, publish: true), method: :put, style:'float: right; margin-top: 10px' do
%i.fa.fa-eraser %button#archive.btn.btn-small.btn-success.text-info{type: :button}
- if @facade.procedure.archived %i.fa.fa-eraser
= 'Réactiver' Publier
- else #confirm
= 'Archiver' %button#valid.btn.btn-small.btn-success{type: :submit}
#confirm %i.fa.fa-check
%button#valid.btn.btn-small.btn-success{type: :submit} Valider
%i.fa.fa-check %button#cancel.btn.btn-small.btn-danger{type: :button}
Valider %i.fa.fa-remove
%button#cancel.btn.btn-small.btn-danger{type: :button} Annuler
%i.fa.fa-remove
Annuler -else
= form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put, style:'float: right; margin-top: 10px' do
%button#archive.btn.btn-small.btn-default.text-info{type: :button}
%i.fa.fa-eraser
- if @facade.procedure.archived
= 'Réactiver'
- else
= 'Archiver'
#confirm
%button#valid.btn.btn-small.btn-success{type: :submit}
%i.fa.fa-check
Valider
%button#cancel.btn.btn-small.btn-danger{type: :button}
%i.fa.fa-remove
Annuler
- if @facade.procedure.locked? - if @facade.procedure.locked?
#procedure_locked.center #procedure_locked.center
%h5 %h5
.label.label-info La procédure ne peut plus être modifiée car un usagé a déjà déposé un dossier .label.label-info La procédure ne peut plus être modifiée car elle a été publiée
%div %div
%h3 Lien procédure %h3 Lien procédure
%div{style:'margin-left:3%'} %div{style:'margin-left:3%'}
= @facade.procedure.lien -if @facade.procedure.published?
= @facade.procedure.lien
-else
%b
Cette procédure n'a pas encore été publiée et n'est donc pas accessible par le public.
%br %br
%h3 Détails %h3 Détails

View file

@ -82,6 +82,7 @@ Rails.application.routes.draw do
namespace :admin do namespace :admin do
get 'sign_in' => '/administrateurs/sessions#new' get 'sign_in' => '/administrateurs/sessions#new'
get 'procedures/archived' => 'procedures#archived' get 'procedures/archived' => 'procedures#archived'
get 'procedures/draft' => 'procedures#draft'
get 'profile' => 'profile#show', as: :profile get 'profile' => 'profile#show', as: :profile
resources :procedures do resources :procedures do
@ -95,6 +96,7 @@ Rails.application.routes.draw do
end end
put 'archive' => 'procedures#archive', as: :archive put 'archive' => 'procedures#archive', as: :archive
put 'publish' => 'procedures#publish', as: :publish
resource :accompagnateurs, only: [:show, :update] resource :accompagnateurs, only: [:show, :update]

View file

@ -0,0 +1,12 @@
class AddProcedureStatus < ActiveRecord::Migration
class Procedure < ActiveRecord::Base
end
def change
add_column :procedures, :published, :boolean, default: false, null: false
Procedure.all.each do |procedure|
procedure.published = true
procedure.save!
end
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160607150440) do ActiveRecord::Schema.define(version: 20160609125949) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -242,6 +242,7 @@ ActiveRecord::Schema.define(version: 20160607150440) do
t.string "logo" t.string "logo"
t.boolean "cerfa_flag", default: false t.boolean "cerfa_flag", default: false
t.string "logo_secure_token" t.string "logo_secure_token"
t.boolean "published", default: false, null: false
end end
create_table "quartier_prioritaires", force: :cascade do |t| create_table "quartier_prioritaires", force: :cascade do |t|

View file

@ -2,7 +2,8 @@ require 'spec_helper'
describe Admin::PiecesJustificativesController, type: :controller do describe Admin::PiecesJustificativesController, type: :controller do
let(:admin) { create(:administrateur) } let(:admin) { create(:administrateur) }
let(:procedure) { create(:procedure, administrateur: admin) } let(:published) { false }
let(:procedure) { create(:procedure, administrateur: admin, published: published) }
before do before do
sign_in admin sign_in admin
end end
@ -17,8 +18,8 @@ describe Admin::PiecesJustificativesController, type: :controller do
it { expect(subject.status).to eq(404) } it { expect(subject.status).to eq(404) }
end end
context 'when procedure have at least a file' do context 'when procedure is published' do
let!(:dossier) { create(:dossier, procedure: procedure, state: :initiated) } let(:published) { true }
it { is_expected.to redirect_to admin_procedure_path id: procedure_id } it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
end end

View file

@ -46,8 +46,15 @@ describe Admin::ProceduresController, type: :controller do
it { expect(response.status).to eq(200) } it { expect(response.status).to eq(200) }
end end
describe 'GET #published' do
subject { get :published }
it { expect(response.status).to eq(200) }
end
describe 'GET #edit' do describe 'GET #edit' do
let(:procedure) { create(:procedure, administrateur: admin) } let(:published) { false }
let(:procedure) { create(:procedure, administrateur: admin, published: published) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
subject { get :edit, id: procedure_id } subject { get :edit, id: procedure_id }
@ -66,8 +73,8 @@ describe Admin::ProceduresController, type: :controller do
it { expect(subject).to have_http_status(:success) } it { expect(subject).to have_http_status(:success) }
end end
context 'when procedure have at least a file' do context 'when procedure is published' do
let!(:dossier) { create(:dossier, procedure: procedure, state: :initiated) } let(:published) { true }
it { is_expected.to redirect_to admin_procedure_path id: procedure_id } it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
end end

View file

@ -9,7 +9,8 @@ describe Admin::TypesDeChampController, type: :controller do
end end
describe 'GET #show' do describe 'GET #show' do
let(:procedure) { create(:procedure, administrateur: admin) } let(:published) { false }
let(:procedure) { create(:procedure, administrateur: admin, published: published) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
subject { get :show, procedure_id: procedure_id } subject { get :show, procedure_id: procedure_id }
@ -19,8 +20,8 @@ describe Admin::TypesDeChampController, type: :controller do
it { expect(subject.status).to eq(404) } it { expect(subject.status).to eq(404) }
end end
context 'when procedure have at least a file' do context 'when procedure is published' do
let!(:dossier) { create(:dossier, procedure: procedure, state: :initiated) } let(:published) { true }
it { is_expected.to redirect_to admin_procedure_path id: procedure_id } it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
end end

View file

@ -3,7 +3,7 @@ require 'spec_helper'
describe Users::DossiersController, type: :controller do describe Users::DossiersController, type: :controller do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure, :published) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
@ -80,6 +80,16 @@ describe Users::DossiersController, type: :controller do
it { is_expected.to redirect_to users_dossiers_path } it { is_expected.to redirect_to users_dossiers_path }
end end
context 'when procedure is not published' do
let(:procedure) { create(:procedure, published: false) }
before do
sign_in create(:user)
end
it { is_expected.to redirect_to users_dossiers_path }
end
end end
end end

View file

@ -85,8 +85,18 @@ describe Users::SessionsController, type: :controller do
it { expect(subject).to redirect_to root_path } it { expect(subject).to redirect_to root_path }
end end
context 'when procedure is not published' do
let(:procedure) { create :procedure, published: false }
before do
session["user_return_to"] = "?procedure_id=#{procedure.id}"
end
it { expect(subject.status).to eq 302}
it { expect(subject).to redirect_to root_path }
end
context 'when procedure_id exist' do context 'when procedure_id exist' do
let(:procedure) { create :procedure } let(:procedure) { create :procedure, published: true }
before do before do
session["user_return_to"] = "?procedure_id=#{procedure.id}" session["user_return_to"] = "?procedure_id=#{procedure.id}"

View file

@ -5,6 +5,7 @@ FactoryGirl.define do
description "Demande de subvention à l'intention des associations" description "Demande de subvention à l'intention des associations"
organisation "Orga SGMAP" organisation "Orga SGMAP"
direction "direction SGMAP" direction "direction SGMAP"
published false
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
if procedure.module_api_carto.nil? if procedure.module_api_carto.nil?
@ -44,5 +45,11 @@ FactoryGirl.define do
procedure.types_de_piece_justificative << msa procedure.types_de_piece_justificative << msa
end end
end end
trait :published do
after(:build) do |procedure, _evaluator|
procedure.published = true
end
end
end end
end end

View file

@ -3,26 +3,27 @@ require 'spec_helper'
feature 'procedure locked' do feature 'procedure locked' do
let(:administrateur) { create(:administrateur) } let(:administrateur) { create(:administrateur) }
let(:procedure) { create(:procedure, administrateur: administrateur) } let(:published) { false }
let(:procedure) { create(:procedure, administrateur: administrateur, published: published) }
before do before do
login_as administrateur, scope: :administrateur login_as administrateur, scope: :administrateur
visit admin_procedure_path(procedure) visit admin_procedure_path(procedure)
end end
context 'when procedure have no file' do context 'when procedure is not published' do
scenario 'info label is not present' do scenario 'info label is not present' do
expect(page).not_to have_content('La procédure ne peut plus être modifiée car un usagé a déjà déposé un dossier') expect(page).not_to have_content('La procédure ne peut plus être modifiée car elle a été publiée')
end end
end end
context 'when procedure have at least a file' do context 'when procedure is published' do
let(:published) { true }
before do before do
create(:dossier, procedure: procedure, state: :initiated)
visit admin_procedure_path(procedure) visit admin_procedure_path(procedure)
end end
scenario 'info label is present' do scenario 'info label is present' do
expect(page).to have_content('La procédure ne peut plus être modifiée car un usagé a déjà déposé un dossier') expect(page).to have_content('La procédure ne peut plus être modifiée car elle a été publiée')
end end
context 'when user click on Description tab' do context 'when user click on Description tab' do
@ -45,7 +46,7 @@ feature 'procedure locked' do
end end
end end
context 'when user click on Pieces Justificatiives tab' do context 'when user click on Pieces Justificatives tab' do
before do before do
page.click_on 'Pièces justificatives' page.click_on 'Pièces justificatives'
end end

View file

@ -2,9 +2,10 @@ require 'spec_helper'
feature 'user path for dossier creation' do feature 'user path for dossier creation' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure, :published) }
let(:siret) { '53272417600013' } let(:siret) { '53272417600013' }
let(:siren) { siret[0...9] } let(:siren) { siret[0...9] }
context 'user arrives on siret page' do context 'user arrives on siret page' do
before do before do
visit new_users_dossiers_path(procedure_id: procedure.id) visit new_users_dossiers_path(procedure_id: procedure.id)
@ -65,4 +66,15 @@ feature 'user path for dossier creation' do
end end
end end
end end
context 'user cannot access non-published procedures' do
let(:procedure) { create(:procedure) }
before do
visit new_users_dossiers_path(procedure_id: procedure.id)
end
scenario 'user is on home page', vcr: { cassette_name: 'complete_demande_spec' } do
expect(page).to have_content('La procédure n\'existe pas')
end
end
end end

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
feature 'user arrive on siret page' do feature 'user arrive on siret page' do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure, :published) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:siret) { '42149333900020' } let(:siret) { '42149333900020' }
let(:siren) { siret[0...9] } let(:siren) { siret[0...9] }

View file

@ -0,0 +1,101 @@
---
http_interactions:
- request:
method: get
uri: https://api.github.com/repos/sgmap/tps/releases/latest
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Ruby
response:
status:
code: 200
message: OK
headers:
Server:
- GitHub.com
Date:
- Thu, 09 Jun 2016 14:42:08 GMT
Content-Type:
- application/json; charset=utf-8
Transfer-Encoding:
- chunked
Status:
- 200 OK
X-Ratelimit-Limit:
- '60'
X-Ratelimit-Remaining:
- '43'
X-Ratelimit-Reset:
- '1465485629'
Cache-Control:
- public, max-age=60, s-maxage=60
Vary:
- Accept
- Accept-Encoding
Etag:
- W/"0962b5ade3f87b4e0092d56f4719512e"
Last-Modified:
- Fri, 03 Jun 2016 10:05:19 GMT
X-Github-Media-Type:
- github.v3
Access-Control-Expose-Headers:
- ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin:
- "*"
Content-Security-Policy:
- default-src 'none'
Strict-Transport-Security:
- max-age=31536000; includeSubdomains; preload
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- deny
X-Xss-Protection:
- 1; mode=block
X-Served-By:
- c6c65e5196703428e7641f7d1e9bc353
Content-Encoding:
- gzip
X-Github-Request-Id:
- B918B84A:B215:2AB0D00D:5759803F
body:
encoding: ASCII-8BIT
string: !binary |-
H4sIAAAAAAAAA6VW7WobRxR9lWH/+I/jlSrjEuE2mEAhYEogTiltihjtXq0m
zM5s5mMjR/hdQn9Fz7Ev1nNHK1lSZAdRsJFXe++Ze88994yXWXQ6G2fzEBo/
znPZqItKhXmcXhS2zh011ue+qmWTIwDPmqQnn49GV1ejwc/ZeSa9p+An/wsm
X4MALTbayvIAbf2lP6WwHnH5ysiazrWckn4A/DzU+gB8p9sjfQZZ5e3wYoRc
VWbjvu3zDN9PGBrU9a+DdBWFCVirVVB+jje19IEcUncixVjczGZUBBmUNaIk
L2SBpEZWRgaKzgsKolHdtwKvPkYf1EwVCG7xWN4DSX2K5AFaOjkL2XgmtSeM
IYa5ddl4mWlbKYPT//wY9ZthX/hwNBhevrwaILCVKPVwXunLDcPRkyusCWRC
UkHMN+mv2l+Yisr1KMxJxmN7TkQM5/NtOc/PYBs2s1rbz8g8LHVfobvg+TYH
Ja3/VqY6OR85y9yGOYEllM66qZT/kcb3Cknxy5w/JqpkBA9+HR0q+2Dd9jD6
DJTy2aCKZVrGBBWnvnCqYQGdws5eHnCsq6RRX5IQT8FBHusvecMJ5KZ45FEL
XZ2SuE5Y5o1TrSzumQJHBWEjysnJYAeZwAr3Da/xe4yayVWBJrKseYXSaj2c
Z42j3vi261Y4wraWE4kNzH4aDK9eDPAzuhu8HA/xM/gLUE2cahjBkajhYDy4
HF+OOKq3vvHf/7CruKnUhw71A0/ukzY29UU1p2P0SRuMqS3v0df1fPTr7za2
BHPpVv46x/MH98FcR73+1Cp9vjdCGjiUchFuZqS+9yRqqdhB8EKQEYHqxgvX
rUiLYBGm2c5sEWsWg/gUFaKCw6/w0QktRaNB8My6mi7SmXl/2PXm0KDA7qNl
HrpoQygccHt1tPaeXDLdx7NLBU2gPg4uqYmKixMzHRd4FOzneCMRhCQ8zyX8
F+neK3Ln3Fuj0Q9jPuXaVEtTonVEWDTHbq+7Fa4GPqhHOt7kLXiQFYK4EGNo
wXdGAolGxEcGBPm9TpN7L0KUoAgHi+5rotTZoluV0ZHwShSko3pR9MQn2u/e
vhOV6/4tUgaO0Ar94XCzVsHzxbIMeHFgek7yVSYaintlyXTzoe+ETrsFHbsI
fdOtClx/fOEx0TNriv7WFPgnREzJW2X8hWCB3J7tK0AAvyXnWEmYDw9trbk0
uH5gW0Kg27hAjOYYpROf62q71cFo8o36sQ03dbfSyqJdDGa7H8d25Ba4OwNj
KXjffSsPJMqstCjVK2gErfPwtqIEo71a1hogs9HzekCp+OMiPC6vOxsDUp5O
Ex5C2l2hOYZrXRIVcwpdp0EmfeB4ZtyzRpm/VB43gH9osPObk/oQuAGC0tIp
31ijplwGpqxVZZ7Y+T26MUJcAQ5C2PeHzXzSt5jRa4uLN+nm0cGOTegxjhWv
z2SJApORaZaCKuZpGNKAsDNaNNYF8frdH6I8w6Js5tIqibc3b9/wLh0nHWuy
u7m8BrwmSaXSFXPVdiuu4KgxpMJ7B/xNLcQ0Vj0N3/vm97RkD/8BJlYZoPAL
AAA=
http_version:
recorded_at: Thu, 09 Jun 2016 14:42:08 GMT
recorded_with: VCR 3.0.1

View file

@ -79,28 +79,47 @@ describe Procedure do
end end
describe 'locked?' do describe 'locked?' do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure, published: published) }
subject { procedure.locked? } subject { procedure.locked? }
context 'when procedure does not have dossier' do context 'when procedure is in draft status' do
let(:published) { false }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
context 'when procedure have dossier with state draft' do context 'when procedure is in draft status' do
before do let(:published) { true }
create(:dossier, procedure: procedure, state: :draft)
end
it { is_expected.to be_falsey }
end
context 'when procedure have dossier with state initiated' do
before do
create(:dossier, procedure: procedure, state: :initiated)
end
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
end end
describe 'active' do
let(:procedure) { create(:procedure, published: published, archived: archived) }
subject { Procedure.active(procedure.id) }
context 'when procedure is in draft status and not archived' do
let(:published) { false }
let(:archived) { false }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end
context 'when procedure is published and not archived' do
let(:published) { true }
let(:archived) { false }
it { is_expected.to be_truthy }
end
context 'when procedure is published and archived' do
let(:published) { true }
let(:archived) { true }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end
context 'when procedure is in draft status and archived' do
let(:published) { false }
let(:archived) { true }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end
end
end end

View file

@ -1,7 +1,9 @@
require 'spec_helper' require 'spec_helper'
describe 'admin/procedures/show.html.haml', type: :view do describe 'admin/procedures/show.html.haml', type: :view do
let(:procedure) { create(:procedure) } let(:archived) { false }
let(:published) { false }
let(:procedure) { create(:procedure, published: published, archived: archived) }
before do before do
assign(:facade, AdminProceduresShowFacades.new(procedure.decorate)) assign(:facade, AdminProceduresShowFacades.new(procedure.decorate))
@ -9,19 +11,32 @@ describe 'admin/procedures/show.html.haml', type: :view do
render render
end end
describe 'publish button' do
it { expect(rendered).to have_content('Publier') }
end
describe 'archive and unarchive button' do describe 'archive and unarchive button' do
context 'when procedure is active' do let(:published) { true }
context 'when procedure is published' do
it { expect(rendered).to have_content('Archiver') } it { expect(rendered).to have_content('Archiver') }
end end
context 'when procedure is archived' do context 'when procedure is archived' do
let(:procedure) { create(:procedure, archived: true) } let(:archived) { true }
it { expect(rendered).to have_content('Réactiver') } it { expect(rendered).to have_content('Réactiver') }
end end
end end
describe 'procedure link is present' do describe 'procedure link' do
it { expect(rendered).to have_content(new_users_dossiers_url(procedure_id: procedure.id)) }
context 'is not present when not published' do
it { expect(rendered).to have_content('Cette procédure n\'a pas encore été publiée et n\'est donc pas accessible par le public.') }
end
context 'is present when already published' do
let(:published) { true }
it { expect(rendered).to have_content(new_users_dossiers_url(procedure_id: procedure.id)) }
end
end end
end end