From 2791988da2923ae8eccdf2edcbd82a3671459d44 Mon Sep 17 00:00:00 2001 From: Guillaume Lazzara Date: Thu, 9 Jun 2016 17:49:38 +0200 Subject: [PATCH] Add draft/publish status for procedure. --- .../admin/procedures_controller.rb | 44 ++++++-- app/controllers/users/dossiers_controller.rb | 2 +- app/controllers/users/sessions_controller.rb | 2 +- app/models/procedure.rb | 7 +- .../admin/procedures/_draft_list.html.haml | 19 ++++ app/views/admin/procedures/_onglets.html.haml | 5 + app/views/admin/procedures/show.html.haml | 50 ++++++--- config/routes.rb | 2 + .../20160609125949_add_procedure_status.rb | 12 +++ db/schema.rb | 3 +- .../pieces_justificatives_controller_spec.rb | 7 +- .../admin/procedures_controller_spec.rb | 13 ++- .../admin/types_de_champ_controller_spec.rb | 7 +- .../users/dossiers_controller_spec.rb | 12 ++- .../users/sessions_controller_spec.rb | 12 ++- spec/factories/procedure.rb | 7 ++ spec/features/admin/procedure_locked_spec.rb | 15 +-- spec/features/users/complete_demande_spec.rb | 14 ++- spec/features/users/start_demande_spec.rb | 2 +- .../cassettes/complete_demande_spec.yml | 101 ++++++++++++++++++ spec/models/procedure_spec.rb | 49 ++++++--- .../admin/procedures/show.html.haml_spec.rb | 27 +++-- 22 files changed, 341 insertions(+), 71 deletions(-) create mode 100644 app/views/admin/procedures/_draft_list.html.haml create mode 100644 db/migrate/20160609125949_add_procedure_status.rb create mode 100644 spec/fixtures/cassettes/complete_demande_spec.yml diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 8ee4befa2..bf5a137e3 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -7,7 +7,7 @@ class Admin::ProceduresController < AdminController def index @procedures = smart_listing_create :procedures, - current_administrateur.procedures.where(archived: false), + current_administrateur.procedures.where(published: true, archived: false), partial: "admin/procedures/list", array: true @@ -25,6 +25,18 @@ class Admin::ProceduresController < AdminController render 'index' 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 @facade = AdminProceduresShowFacades.new @procedure.decorate end @@ -63,16 +75,12 @@ class Admin::ProceduresController < AdminController redirect_to edit_admin_procedure_path(id: @procedure.id) end + def publish + change_status({published: params[:published]}) + end + def archive - @procedure = current_administrateur.procedures.find(params[:procedure_id]) - @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 + change_status({archived: params[:archive]}) end def active_class @@ -83,6 +91,10 @@ class Admin::ProceduresController < AdminController @archived_class = 'active' end + def draft_class + @draft_class = 'active' + end + private def create_procedure_params @@ -92,4 +104,16 @@ class Admin::ProceduresController < AdminController def create_module_api_carto_params params.require(:procedure).require(:module_api_carto_attributes).permit(:id, :use_api_carto, :quartiers_prioritaires, :cadastre) 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 diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 3faaad661..a6aa36f39 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -23,7 +23,7 @@ class Users::DossiersController < UsersController end 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) @siret = params[:siret] || current_user.siret diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 40c598220..c69384199 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -12,7 +12,7 @@ class Users::SessionsController < Sessions::SessionsController # GET /resource/sign_in def new 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 @user = User.new diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 1d85633a3..00aa073b6 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -33,6 +33,10 @@ class Procedure < ActiveRecord::Base Procedure.where(archived: false).find(id) end + def self.active id + Procedure.where(archived: false, published: true).find(id) + end + def switch_types_de_champ index_of_first_element switch_list_order(types_de_champ_ordered, index_of_first_element) end @@ -51,6 +55,7 @@ class Procedure < ActiveRecord::Base end def locked? - dossiers.where.not(state: :draft).count > 0 + published? end + end diff --git a/app/views/admin/procedures/_draft_list.html.haml b/app/views/admin/procedures/_draft_list.html.haml new file mode 100644 index 000000000..7d3505614 --- /dev/null +++ b/app/views/admin/procedures/_draft_list.html.haml @@ -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 diff --git a/app/views/admin/procedures/_onglets.html.haml b/app/views/admin/procedures/_onglets.html.haml index 80fd9d40a..5c8e0a8c0 100644 --- a/app/views/admin/procedures/_onglets.html.haml +++ b/app/views/admin/procedures/_onglets.html.haml @@ -1,5 +1,10 @@ #onglets %ul.nav.nav-tabs + %li{class: @draft_class} + %a{:href => "#{url_for :admin_procedures_draft}"} + %h5{style: 'color: black'} + ="Brouillons" + %li{class: @active_class} %a{:href => "#{url_for :admin_procedures}"} %h5.text-success diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index 6bb99288b..8626a87e2 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -1,30 +1,48 @@ #procedure_show =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 - %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.published? + = form_tag admin_procedure_publish_path(procedure_id: @facade.procedure.id, publish: true), method: :put, style:'float: right; margin-top: 10px' do + %button#archive.btn.btn-small.btn-success.text-info{type: :button} + %i.fa.fa-eraser + Publier + #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 + + -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? #procedure_locked.center %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 %h3 Lien procédure %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 %h3 Détails diff --git a/config/routes.rb b/config/routes.rb index 9df3fd5df..3b5f6ebb2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -82,6 +82,7 @@ Rails.application.routes.draw do namespace :admin do get 'sign_in' => '/administrateurs/sessions#new' get 'procedures/archived' => 'procedures#archived' + get 'procedures/draft' => 'procedures#draft' get 'profile' => 'profile#show', as: :profile resources :procedures do @@ -95,6 +96,7 @@ Rails.application.routes.draw do end put 'archive' => 'procedures#archive', as: :archive + put 'publish' => 'procedures#publish', as: :publish resource :accompagnateurs, only: [:show, :update] diff --git a/db/migrate/20160609125949_add_procedure_status.rb b/db/migrate/20160609125949_add_procedure_status.rb new file mode 100644 index 000000000..6d4ea7e2e --- /dev/null +++ b/db/migrate/20160609125949_add_procedure_status.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index cb89f0cce..4839009ec 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # 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 enable_extension "plpgsql" @@ -242,6 +242,7 @@ ActiveRecord::Schema.define(version: 20160607150440) do t.string "logo" t.boolean "cerfa_flag", default: false t.string "logo_secure_token" + t.boolean "published", default: false, null: false end create_table "quartier_prioritaires", force: :cascade do |t| diff --git a/spec/controllers/admin/pieces_justificatives_controller_spec.rb b/spec/controllers/admin/pieces_justificatives_controller_spec.rb index 09ca67188..5c33da67e 100644 --- a/spec/controllers/admin/pieces_justificatives_controller_spec.rb +++ b/spec/controllers/admin/pieces_justificatives_controller_spec.rb @@ -2,7 +2,8 @@ require 'spec_helper' describe Admin::PiecesJustificativesController, type: :controller do let(:admin) { create(:administrateur) } - let(:procedure) { create(:procedure, administrateur: admin) } + let(:published) { false } + let(:procedure) { create(:procedure, administrateur: admin, published: published) } before do sign_in admin end @@ -17,8 +18,8 @@ describe Admin::PiecesJustificativesController, type: :controller do it { expect(subject.status).to eq(404) } end - context 'when procedure have at least a file' do - let!(:dossier) { create(:dossier, procedure: procedure, state: :initiated) } + context 'when procedure is published' do + let(:published) { true } it { is_expected.to redirect_to admin_procedure_path id: procedure_id } end diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index c4d414b0a..11587b94d 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -46,8 +46,15 @@ describe Admin::ProceduresController, type: :controller do it { expect(response.status).to eq(200) } end + describe 'GET #published' do + subject { get :published } + + it { expect(response.status).to eq(200) } + end + 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 } subject { get :edit, id: procedure_id } @@ -66,8 +73,8 @@ describe Admin::ProceduresController, type: :controller do it { expect(subject).to have_http_status(:success) } end - context 'when procedure have at least a file' do - let!(:dossier) { create(:dossier, procedure: procedure, state: :initiated) } + context 'when procedure is published' do + let(:published) { true } it { is_expected.to redirect_to admin_procedure_path id: procedure_id } end diff --git a/spec/controllers/admin/types_de_champ_controller_spec.rb b/spec/controllers/admin/types_de_champ_controller_spec.rb index 5227c56ae..c334ccb0c 100644 --- a/spec/controllers/admin/types_de_champ_controller_spec.rb +++ b/spec/controllers/admin/types_de_champ_controller_spec.rb @@ -9,7 +9,8 @@ describe Admin::TypesDeChampController, type: :controller do end 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 } subject { get :show, procedure_id: procedure_id } @@ -19,8 +20,8 @@ describe Admin::TypesDeChampController, type: :controller do it { expect(subject.status).to eq(404) } end - context 'when procedure have at least a file' do - let!(:dossier) { create(:dossier, procedure: procedure, state: :initiated) } + context 'when procedure is published' do + let(:published) { true } it { is_expected.to redirect_to admin_procedure_path id: procedure_id } end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index f996114da..637f39710 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Users::DossiersController, type: :controller do let(:user) { create(:user) } - let(:procedure) { create(:procedure) } + let(:procedure) { create(:procedure, :published) } let(:procedure_id) { procedure.id } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } let(:dossier_id) { dossier.id } @@ -80,6 +80,16 @@ describe Users::DossiersController, type: :controller do it { is_expected.to redirect_to users_dossiers_path } 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 diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 256913b1f..9728aba35 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -85,8 +85,18 @@ describe Users::SessionsController, type: :controller do it { expect(subject).to redirect_to root_path } 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 - let(:procedure) { create :procedure } + let(:procedure) { create :procedure, published: true } before do session["user_return_to"] = "?procedure_id=#{procedure.id}" diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index c8dea5a80..2614d06e6 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -5,6 +5,7 @@ FactoryGirl.define do description "Demande de subvention à l'intention des associations" organisation "Orga SGMAP" direction "direction SGMAP" + published false after(:build) do |procedure, _evaluator| if procedure.module_api_carto.nil? @@ -44,5 +45,11 @@ FactoryGirl.define do procedure.types_de_piece_justificative << msa end end + + trait :published do + after(:build) do |procedure, _evaluator| + procedure.published = true + end + end end end diff --git a/spec/features/admin/procedure_locked_spec.rb b/spec/features/admin/procedure_locked_spec.rb index 3dea1b3b0..4676e9043 100644 --- a/spec/features/admin/procedure_locked_spec.rb +++ b/spec/features/admin/procedure_locked_spec.rb @@ -3,26 +3,27 @@ require 'spec_helper' feature 'procedure locked' do let(:administrateur) { create(:administrateur) } - let(:procedure) { create(:procedure, administrateur: administrateur) } + let(:published) { false } + let(:procedure) { create(:procedure, administrateur: administrateur, published: published) } before do login_as administrateur, scope: :administrateur visit admin_procedure_path(procedure) end - context 'when procedure have no file' do + context 'when procedure is not published' 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 - context 'when procedure have at least a file' do + context 'when procedure is published' do + let(:published) { true } before do - create(:dossier, procedure: procedure, state: :initiated) visit admin_procedure_path(procedure) end 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 context 'when user click on Description tab' do @@ -45,7 +46,7 @@ feature 'procedure locked' do end end - context 'when user click on Pieces Justificatiives tab' do + context 'when user click on Pieces Justificatives tab' do before do page.click_on 'Pièces justificatives' end diff --git a/spec/features/users/complete_demande_spec.rb b/spec/features/users/complete_demande_spec.rb index 46b766c06..a1f8dc0f8 100644 --- a/spec/features/users/complete_demande_spec.rb +++ b/spec/features/users/complete_demande_spec.rb @@ -2,9 +2,10 @@ require 'spec_helper' feature 'user path for dossier creation' do let(:user) { create(:user) } - let(:procedure) { create(:procedure) } + let(:procedure) { create(:procedure, :published) } let(:siret) { '53272417600013' } let(:siren) { siret[0...9] } + context 'user arrives on siret page' do before do visit new_users_dossiers_path(procedure_id: procedure.id) @@ -65,4 +66,15 @@ feature 'user path for dossier creation' do 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 \ No newline at end of file diff --git a/spec/features/users/start_demande_spec.rb b/spec/features/users/start_demande_spec.rb index 135b7f499..480550df1 100644 --- a/spec/features/users/start_demande_spec.rb +++ b/spec/features/users/start_demande_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' feature 'user arrive on siret page' do - let(:procedure) { create(:procedure) } + let(:procedure) { create(:procedure, :published) } let(:user) { create(:user) } let(:siret) { '42149333900020' } let(:siren) { siret[0...9] } diff --git a/spec/fixtures/cassettes/complete_demande_spec.yml b/spec/fixtures/cassettes/complete_demande_spec.yml new file mode 100644 index 000000000..95841bbea --- /dev/null +++ b/spec/fixtures/cassettes/complete_demande_spec.yml @@ -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 diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 6b6118104..b36e64837 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -79,28 +79,47 @@ describe Procedure do end describe 'locked?' do - let(:procedure) { create(:procedure) } + let(:procedure) { create(:procedure, published: published) } 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 } end - context 'when procedure have dossier with state draft' do - before do - 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 - + context 'when procedure is in draft status' do + let(:published) { true } it { is_expected.to be_truthy } 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 diff --git a/spec/views/admin/procedures/show.html.haml_spec.rb b/spec/views/admin/procedures/show.html.haml_spec.rb index 3f3474aa8..7e5c272a1 100644 --- a/spec/views/admin/procedures/show.html.haml_spec.rb +++ b/spec/views/admin/procedures/show.html.haml_spec.rb @@ -1,7 +1,9 @@ require 'spec_helper' 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 assign(:facade, AdminProceduresShowFacades.new(procedure.decorate)) @@ -9,19 +11,32 @@ describe 'admin/procedures/show.html.haml', type: :view do render end + describe 'publish button' do + it { expect(rendered).to have_content('Publier') } + end + 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') } end context 'when procedure is archived' do - let(:procedure) { create(:procedure, archived: true) } - + let(:archived) { true } it { expect(rendered).to have_content('Réactiver') } end end - describe 'procedure link is present' do - it { expect(rendered).to have_content(new_users_dossiers_url(procedure_id: procedure.id)) } + describe 'procedure link' do + + 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 \ No newline at end of file