Merge pull request #5357 from Keirua/reenable-validator-on-pj
#4926 Reenable validator on piece_justificative
This commit is contained in:
commit
5fb2dbfdb4
5 changed files with 29 additions and 60 deletions
|
@ -17,30 +17,9 @@
|
|||
class Champs::PieceJustificativeChamp < Champ
|
||||
MAX_SIZE = 200.megabytes
|
||||
|
||||
ACCEPTED_FORMATS = [
|
||||
"text/plain",
|
||||
"application/pdf",
|
||||
"application/msword",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"application/vnd.ms-excel",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"application/vnd.ms-powerpoint",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||
"application/vnd.oasis.opendocument.text",
|
||||
"application/vnd.oasis.opendocument.presentation",
|
||||
"application/vnd.oasis.opendocument.spreadsheet",
|
||||
"image/png",
|
||||
"image/jpeg"
|
||||
]
|
||||
|
||||
# TODO: once we're running on Rails 6, re-enable this validation.
|
||||
# See https://github.com/betagouv/demarches-simplifiees.fr/issues/4926
|
||||
#
|
||||
# validates :piece_justificative_file,
|
||||
# content_type: ACCEPTED_FORMATS,
|
||||
# size: { less_than: MAX_SIZE }
|
||||
|
||||
before_save :update_skip_pj_validation
|
||||
validates :piece_justificative_file,
|
||||
size: { less_than: MAX_SIZE },
|
||||
if: -> { !type_de_champ.skip_pj_validation }
|
||||
|
||||
def main_value_name
|
||||
:piece_justificative_file
|
||||
|
@ -63,8 +42,4 @@ class Champs::PieceJustificativeChamp < Champ
|
|||
piece_justificative_file.service_url
|
||||
end
|
||||
end
|
||||
|
||||
def update_skip_pj_validation
|
||||
type_de_champ.update(skip_pj_validation: true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,3 +2,4 @@ fr:
|
|||
errors:
|
||||
messages:
|
||||
content_type_invalid: n’est pas d’un type accepté
|
||||
file_size_out_of_range: "est trop lourde, elle doit faire au plus 200 Mo."
|
||||
|
|
|
@ -176,6 +176,13 @@ feature 'The user' do
|
|||
create(:procedure, :published, :for_individual, types_de_champ: tdcs)
|
||||
end
|
||||
|
||||
let(:old_procedure_with_disabled_pj_validation) do
|
||||
tdcs = [
|
||||
create(:type_de_champ_piece_justificative, mandatory: true, libelle: 'Pièce justificative 1', order_place: 1, skip_pj_validation: true)
|
||||
]
|
||||
create(:procedure, :published, :for_individual, types_de_champ: tdcs)
|
||||
end
|
||||
|
||||
scenario 'add an attachment', js: true do
|
||||
log_in(user, procedure_with_pjs)
|
||||
fill_individual
|
||||
|
@ -200,25 +207,14 @@ feature 'The user' do
|
|||
expect(page).to have_text('RIB.pdf')
|
||||
end
|
||||
|
||||
# TODO: once we're running on Rails 6, re-enable the validator on PieceJustificativeChamp,
|
||||
# and unmark this spec as pending.
|
||||
#
|
||||
# See piece_justificative_champ.rb
|
||||
# See https://github.com/betagouv/demarches-simplifiees.fr/issues/4926
|
||||
scenario 'add an invalid attachment', js: true, pending: true do
|
||||
log_in(user, procedure_with_pjs)
|
||||
scenario 'add an invalid attachment on an old procedure where pj validation is disabled', js: true do
|
||||
log_in(user, old_procedure_with_disabled_pj_validation)
|
||||
fill_individual
|
||||
|
||||
# Test invalid file type
|
||||
attach_file('Pièce justificative 1', Rails.root + 'spec/fixtures/files/invalid_file_format.json')
|
||||
expect(page).to have_text('La pièce justificative n’est pas d’un type accepté')
|
||||
expect(page).to have_no_button('Ré-essayer', visible: true)
|
||||
|
||||
# Replace the file by another with a valid type
|
||||
attach_file('Pièce justificative 1', Rails.root + 'spec/fixtures/files/piece_justificative_0.pdf')
|
||||
expect(page).to have_no_text('La pièce justificative n’est pas d’un type accepté')
|
||||
expect(page).to have_text('analyse antivirus en cours')
|
||||
expect(page).to have_text('piece_justificative_0.pdf')
|
||||
expect(page).to have_text('analyse antivirus en cours', count: 1)
|
||||
end
|
||||
|
||||
scenario 'retry on transcient upload error', js: true do
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'active_storage_validations/matchers'
|
|||
describe Champs::PieceJustificativeChamp do
|
||||
include ActiveStorageValidations::Matchers
|
||||
|
||||
describe "update_skip_validation" do
|
||||
describe "skip_validation is not set anymore" do
|
||||
subject { champ_pj.type_de_champ.skip_pj_validation }
|
||||
|
||||
context 'before_save' do
|
||||
|
@ -12,19 +12,24 @@ describe Champs::PieceJustificativeChamp do
|
|||
end
|
||||
context 'after_save' do
|
||||
let(:champ_pj) { create (:champ_piece_justificative) }
|
||||
it { is_expected.to be_truthy }
|
||||
it { is_expected.to be_falsy }
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: once we're running on Rails 6, re-enable the PieceJustificativeChamp validator,
|
||||
# and re-enable this spec.
|
||||
#
|
||||
# See https://github.com/betagouv/demarches-simplifiees.fr/issues/4926
|
||||
describe "validations", pending: true do
|
||||
subject(:champ_pj) { build(:champ_piece_justificative) }
|
||||
describe "validations" do
|
||||
let(:champ_pj) { create(:champ_piece_justificative) }
|
||||
subject { champ_pj }
|
||||
|
||||
it { is_expected.to validate_size_of(:piece_justificative_file).less_than(Champs::PieceJustificativeChamp::MAX_SIZE) }
|
||||
it { is_expected.to validate_content_type_of(:piece_justificative_file).allowing(Champs::PieceJustificativeChamp::ACCEPTED_FORMATS) }
|
||||
context "by default" do
|
||||
it { is_expected.to validate_size_of(:piece_justificative_file).less_than(Champs::PieceJustificativeChamp::MAX_SIZE) }
|
||||
it { expect(champ_pj.type_de_champ.skip_pj_validation).to be_falsy }
|
||||
end
|
||||
|
||||
context "when validation is disabled" do
|
||||
before { champ_pj.type_de_champ.update(skip_pj_validation: true) }
|
||||
|
||||
it { is_expected.not_to validate_size_of(:piece_justificative_file).less_than(Champs::PieceJustificativeChamp::MAX_SIZE) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#for_export" do
|
||||
|
|
|
@ -4,16 +4,8 @@ describe ChampSerializer do
|
|||
let(:serializable_object) { champ }
|
||||
|
||||
context 'when type champ is piece justificative' do
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
let(:champ) { create(:champ_piece_justificative) }
|
||||
|
||||
before do
|
||||
champ.piece_justificative_file.attach({ filename: __FILE__, io: File.open(__FILE__) })
|
||||
champ.piece_justificative_file.blob.send(:enqueue_virus_scan)
|
||||
end
|
||||
after { champ.piece_justificative_file.purge }
|
||||
|
||||
it { expect(subject[:value]).to match('/rails/active_storage/disk/') }
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue