From 44f28ec5651be6e342c833636f277db02b0064a1 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 6 Mar 2019 14:42:27 +0100 Subject: [PATCH] Remove feature flag for publish draft --- .../admin/procedures_controller.rb | 7 ++---- app/models/procedure.rb | 8 +++---- app/views/admin/procedures/_onglets.html.haml | 5 +--- app/views/admin/procedures/new.html.haml | 2 +- ...admin_procedurescontroller_index.html.haml | 5 +--- config/features.rb | 1 - .../admin/procedures_controller_spec.rb | 8 ++----- spec/features/admin/procedure_cloning_spec.rb | 1 - .../features/admin/procedure_creation_spec.rb | 24 ------------------- spec/features/admin/procedure_update_spec.rb | 1 - spec/models/gestionnaire_spec.rb | 12 +++++----- spec/models/procedure_spec.rb | 10 ++++---- spec/spec_helper.rb | 5 +++- .../admin/procedures/show.html.haml_spec.rb | 4 ++-- 14 files changed, 28 insertions(+), 65 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 9f9ded6e7..6c70a29c2 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -99,7 +99,7 @@ class Admin::ProceduresController < AdminController @availability = @procedure.path_availability(@path) end render 'edit' - elsif Flipflop.publish_draft? && @procedure.brouillon? + elsif @procedure.brouillon? reset_procedure flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.' redirect_to edit_admin_procedure_path(id: @procedure.id) @@ -273,10 +273,7 @@ class Admin::ProceduresController < AdminController if @procedure&.locked? params.require(:procedure).permit(*editable_params) else - if Flipflop.publish_draft? - editable_params << :path - end - params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :for_individual, :individual_with_siret, :ask_birthday).merge(administrateur_id: current_administrateur.id) + params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :for_individual, :individual_with_siret, :ask_birthday, :path).merge(administrateur_id: current_administrateur.id) end end end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 59943c98a..4c97baefe 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -124,7 +124,7 @@ class Procedure < ApplicationRecord # This method is needed for transition. Eventually this will be the same as brouillon?. def brouillon_avec_lien? - Flipflop.publish_draft? && brouillon? && path.present? + brouillon? && path.present? end def publiee_ou_archivee? @@ -472,10 +472,8 @@ class Procedure < ApplicationRecord end def ensure_path_exists - if Flipflop.publish_draft? - if self.path.nil? - self.path = SecureRandom.uuid - end + if self.path.nil? + self.path = SecureRandom.uuid end end end diff --git a/app/views/admin/procedures/_onglets.html.haml b/app/views/admin/procedures/_onglets.html.haml index c741591cc..b797ca951 100644 --- a/app/views/admin/procedures/_onglets.html.haml +++ b/app/views/admin/procedures/_onglets.html.haml @@ -3,10 +3,7 @@ %li{ class: @draft_class } %a{ :href => "#{url_for :admin_procedures_draft}" } %h5.text-primary - - if Flipflop.publish_draft? - En test - - else - Brouillons + En test %li{ class: @active_class } %a{ :href => "#{url_for :admin_procedures}" } diff --git a/app/views/admin/procedures/new.html.haml b/app/views/admin/procedures/new.html.haml index 8451872a9..d79f2ef01 100644 --- a/app/views/admin/procedures/new.html.haml +++ b/app/views/admin/procedures/new.html.haml @@ -6,7 +6,7 @@ = form_for @procedure, url: { controller: 'admin/procedures', action: :create }, multipart: true do |f| = render partial: 'informations', locals: { f: f } .text-right - - if !Flipflop.publish_draft? || @availability.in?(Procedure::PATH_CAN_PUBLISH) + - if @availability.in?(Procedure::PATH_CAN_PUBLISH) = f.button 'Valider', class: 'btn btn-info', id: 'save-procedure' - else = f.button 'Valider', class: 'btn btn-info', id: 'save-procedure', disabled: true diff --git a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml index bdf47c5e3..508fafc9d 100644 --- a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml +++ b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml @@ -11,10 +11,7 @@ #procedure-list %a#draft-procedures{ :href => "#{url_for :admin_procedures_draft}" } .procedure-list-element{ class: @draft_class } - - if Flipflop.publish_draft? - En test - - else - Brouillons + En test .badge.progress-bar-default = current_administrateur.procedures.brouillons.count diff --git a/config/features.rb b/config/features.rb index 55d02a7bc..f07f6d559 100644 --- a/config/features.rb +++ b/config/features.rb @@ -14,7 +14,6 @@ Flipflop.configure do end feature :web_hook - feature :publish_draft feature :enable_email_login_token feature :new_champs_editor diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index f7dac8b68..9bc8a6421 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -303,10 +303,6 @@ describe Admin::ProceduresController, type: :controller do let!(:dossiers_count) { procedure.dossiers.count } describe 'dossiers are dropped' do - before do - Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true) - end - subject { update_procedure } it { @@ -378,7 +374,7 @@ describe Admin::ProceduresController, type: :controller do it 'does not publish the given procedure' do expect(procedure.publiee?).to be_falsey - expect(procedure.path).to be_nil + expect(procedure.path).not_to match(path) expect(response.status).to eq 200 end @@ -394,7 +390,7 @@ describe Admin::ProceduresController, type: :controller do it 'does not publish the given procedure' do expect(procedure.publiee?).to be_falsey - expect(procedure.path).to be_nil + expect(procedure.path).not_to match(path) expect(response).to redirect_to :admin_procedures expect(flash[:alert]).to have_content 'Lien de la démarche invalide' end diff --git a/spec/features/admin/procedure_cloning_spec.rb b/spec/features/admin/procedure_cloning_spec.rb index 9546cda29..72a7b9727 100644 --- a/spec/features/admin/procedure_cloning_spec.rb +++ b/spec/features/admin/procedure_cloning_spec.rb @@ -7,7 +7,6 @@ feature 'As an administrateur I wanna clone a procedure', js: true do let(:administrateur) { create(:administrateur) } before do - Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true) login_as administrateur, scope: :administrateur visit new_from_existing_admin_procedures_path end diff --git a/spec/features/admin/procedure_creation_spec.rb b/spec/features/admin/procedure_creation_spec.rb index 26666d5fa..98de47e0d 100644 --- a/spec/features/admin/procedure_creation_spec.rb +++ b/spec/features/admin/procedure_creation_spec.rb @@ -8,7 +8,6 @@ feature 'As an administrateur I wanna create a new procedure', js: true do let(:test_strategy) { Flipflop::FeatureSet.current.test! } before do - test_strategy.switch!(:publish_draft, true) test_strategy.switch!(:new_champs_editor, true) login_as administrateur, scope: :administrateur visit root_path @@ -50,29 +49,6 @@ feature 'As an administrateur I wanna create a new procedure', js: true do expect(page).to have_current_path(champs_procedure_path(Procedure.last)) end end - - context "when publish_draft disabled" do - before do - test_strategy.switch!(:publish_draft, false) - end - - scenario 'Finding save button for new procedure, libelle, description and cadre_juridique required' do - expect(page).to have_selector('#new-procedure') - find('#new-procedure').click - click_on 'from-scratch' - - expect(page).to have_current_path(new_admin_procedure_path) - fill_in 'procedure_duree_conservation_dossiers_dans_ds', with: '3' - fill_in 'procedure_duree_conservation_dossiers_hors_ds', with: '6' - click_on 'save-procedure' - - expect(page).to have_text('Libelle doit être rempli') - fill_in_dummy_procedure_details(fill_path: false) - click_on 'save-procedure' - - expect(page).to have_current_path(champs_procedure_path(Procedure.last)) - end - end end context 'Editing a new procedure' do diff --git a/spec/features/admin/procedure_update_spec.rb b/spec/features/admin/procedure_update_spec.rb index b80714274..3986fb9ab 100644 --- a/spec/features/admin/procedure_update_spec.rb +++ b/spec/features/admin/procedure_update_spec.rb @@ -14,7 +14,6 @@ feature 'Administrateurs can edit procedures', js: true do end before do - Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true) login_as administrateur, scope: :administrateur end diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 2a28e5f6e..6b7a6febb 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -14,14 +14,14 @@ describe Gestionnaire, type: :model do describe '#visible_procedures' do let(:procedure_not_assigned) { create :procedure, administrateur: admin } - let(:procedure_without_link) { create :procedure, administrateur: admin } - let(:procedure_with_link) { create :procedure, :with_path, administrateur: admin } + let(:procedure_with_default_path) { create :procedure, administrateur: admin } + let(:procedure_with_custom_path) { create :procedure, :with_path, administrateur: admin } let(:procedure_archived_manually) { create :procedure, :archived, administrateur: admin } let(:procedure_archived_automatically) { create :procedure, :archived_automatically, administrateur: admin } before do - assign(procedure_without_link) - assign(procedure_with_link) + assign(procedure_with_default_path) + assign(procedure_with_custom_path) assign(procedure_archived_manually) assign(procedure_archived_automatically) end @@ -30,8 +30,8 @@ describe Gestionnaire, type: :model do it do expect(subject).not_to include(procedure_not_assigned) - expect(subject).not_to include(procedure_without_link) - expect(subject).to include(procedure_with_link) + expect(subject).to include(procedure_with_default_path) + expect(subject).to include(procedure_with_custom_path) expect(subject).to include(procedure_archived_manually) expect(subject).to include(procedure_archived_automatically) end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 7ff80f12f..4092951a1 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -386,7 +386,7 @@ describe Procedure do cloned_procedure = subject cloned_procedure.parent_procedure_id = nil - expect(cloned_procedure).to have_same_attributes_as(procedure) + expect(cloned_procedure).to have_same_attributes_as(procedure, except: ["path"]) end it 'should not clone piece justificatives but create corresponding champs' do @@ -479,7 +479,7 @@ describe Procedure do expect(subject.published_at).to be_nil expect(subject.test_started_at).to be_nil expect(subject.aasm_state).to eq "brouillon" - expect(subject.path).to be_nil + expect(subject.path).not_to be_nil end end @@ -638,9 +638,11 @@ describe Procedure do end context "without a path" do - let(:procedure) { create(:procedure) } + let(:procedure) { create(:procedure, :archived) } - it { is_expected.to eq("dossiers_procedure-#{procedure.id}_2018-01-02_23-11.csv") } + it do + is_expected.to eq("dossiers_procedure-#{procedure.id}_2018-01-02_23-11.csv") + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7c9d40bcc..6072acede 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -158,9 +158,12 @@ RSpec.configure do |config| end } - RSpec::Matchers.define :have_same_attributes_as do |expected| + RSpec::Matchers.define :have_same_attributes_as do |expected, options| match do |actual| ignored = [:id, :procedure_id, :updated_at, :created_at] + if options.present? && options[:except] + ignored = ignored + options[:except] + end actual.attributes.with_indifferent_access.except(*ignored) == expected.attributes.with_indifferent_access.except(*ignored) 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 d645c0881..da43dba97 100644 --- a/spec/views/admin/procedures/show.html.haml_spec.rb +++ b/spec/views/admin/procedures/show.html.haml_spec.rb @@ -33,8 +33,8 @@ describe 'admin/procedures/show.html.haml', type: :view do it { expect(rendered).not_to have_css('a#reopen-procedure') } end - describe 'procedure link is not present' do - it { expect(rendered).to have_content('Cette démarche n’a pas encore de lien, et n’est pas accessible par le public.') } + describe 'procedure path is not customized' do + it { expect(rendered).to have_content('Cette démarche est actuellement en test') } end end end