added before_save to PieceJustificativeChamp in order to set skip_pj_validation

This commit is contained in:
clemkeirua 2020-07-09 11:45:20 +02:00 committed by Keirua (Rebase PR Action)
parent c93d17bcaa
commit 299c86141c
2 changed files with 19 additions and 0 deletions

View file

@ -24,6 +24,8 @@ class Champs::PieceJustificativeChamp < Champ
# content_type: ACCEPTED_FORMATS,
# size: { less_than: MAX_SIZE }
before_save :update_skip_pj_validation
def main_value_name
:piece_justificative_file
end
@ -45,4 +47,8 @@ class Champs::PieceJustificativeChamp < Champ
piece_justificative_file.service_url
end
end
def update_skip_pj_validation
type_de_champ.update(options: type_de_champ.options&.merge({ :skip_pj_validation => true }) || { :skip_pj_validation => true })
end
end

View file

@ -3,6 +3,19 @@ require 'active_storage_validations/matchers'
describe Champs::PieceJustificativeChamp do
include ActiveStorageValidations::Matchers
describe "update_skip_validation" do
subject { champ_pj.type_de_champ.skip_pj_validation }
context 'before_save' do
let(:champ_pj) { build (:champ_piece_justificative) }
it { is_expected.to be_falsy }
end
context 'after_save' do
let(:champ_pj) { create (:champ_piece_justificative) }
it { is_expected.to be_truthy }
end
end
# TODO: once we're running on Rails 6, re-enable the PieceJustificativeChamp validator,
# and re-enable this spec.
#