validation is enableed only for 'new' procedures
This commit is contained in:
parent
0d88674cea
commit
31d48c2879
3 changed files with 35 additions and 12 deletions
|
@ -35,9 +35,8 @@ class Champs::PieceJustificativeChamp < Champ
|
||||||
|
|
||||||
validates :piece_justificative_file,
|
validates :piece_justificative_file,
|
||||||
content_type: ACCEPTED_FORMATS,
|
content_type: ACCEPTED_FORMATS,
|
||||||
size: { less_than: MAX_SIZE }
|
size: { less_than: MAX_SIZE },
|
||||||
|
if: -> { !type_de_champ.skip_pj_validation }
|
||||||
before_save :update_skip_pj_validation
|
|
||||||
|
|
||||||
def main_value_name
|
def main_value_name
|
||||||
:piece_justificative_file
|
:piece_justificative_file
|
||||||
|
@ -60,8 +59,4 @@ class Champs::PieceJustificativeChamp < Champ
|
||||||
piece_justificative_file.service_url
|
piece_justificative_file.service_url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_skip_pj_validation
|
|
||||||
type_de_champ.update(skip_pj_validation: true)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -176,6 +176,13 @@ feature 'The user' do
|
||||||
create(:procedure, :published, :for_individual, types_de_champ: tdcs)
|
create(:procedure, :published, :for_individual, types_de_champ: tdcs)
|
||||||
end
|
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
|
scenario 'add an attachment', js: true do
|
||||||
log_in(user, procedure_with_pjs)
|
log_in(user, procedure_with_pjs)
|
||||||
fill_individual
|
fill_individual
|
||||||
|
@ -216,6 +223,16 @@ feature 'The user' do
|
||||||
expect(page).to have_text('piece_justificative_0.pdf')
|
expect(page).to have_text('piece_justificative_0.pdf')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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_no_text('La pièce justificative n’est pas d’un type accepté')
|
||||||
|
expect(page).to have_text('analyse antivirus en cours', count: 1)
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'retry on transcient upload error', js: true do
|
scenario 'retry on transcient upload error', js: true do
|
||||||
log_in(user, procedure_with_pjs)
|
log_in(user, procedure_with_pjs)
|
||||||
fill_individual
|
fill_individual
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'active_storage_validations/matchers'
|
||||||
describe Champs::PieceJustificativeChamp do
|
describe Champs::PieceJustificativeChamp do
|
||||||
include ActiveStorageValidations::Matchers
|
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 }
|
subject { champ_pj.type_de_champ.skip_pj_validation }
|
||||||
|
|
||||||
context 'before_save' do
|
context 'before_save' do
|
||||||
|
@ -12,15 +12,26 @@ describe Champs::PieceJustificativeChamp do
|
||||||
end
|
end
|
||||||
context 'after_save' do
|
context 'after_save' do
|
||||||
let(:champ_pj) { create (:champ_piece_justificative) }
|
let(:champ_pj) { create (:champ_piece_justificative) }
|
||||||
it { is_expected.to be_truthy }
|
it { is_expected.to be_falsy }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "validations" do
|
describe "validations" do
|
||||||
subject(:champ_pj) { build(:champ_piece_justificative) }
|
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) }
|
context "by default" do
|
||||||
it { is_expected.to validate_content_type_of(:piece_justificative_file).allowing(Champs::PieceJustificativeChamp::ACCEPTED_FORMATS) }
|
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) }
|
||||||
|
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) }
|
||||||
|
it { is_expected.not_to validate_content_type_of(:piece_justificative_file).allowing(Champs::PieceJustificativeChamp::ACCEPTED_FORMATS) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#for_export" do
|
describe "#for_export" do
|
||||||
|
|
Loading…
Reference in a new issue