Merge pull request #7243 from betagouv/link_tdc_chidren_by_ProcedureRevisionTypeDeChamp

refactor(spec): lie les champs enfants avec leurs parents avec la nouvelle methode
This commit is contained in:
LeSim 2022-05-06 10:40:25 +02:00 committed by GitHub
commit 588641764d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 8 deletions

View file

@ -385,8 +385,7 @@ class ProcedureRevision < ApplicationRecord
end
def find_type_de_champ_by_id(id)
types_de_champ.find_by(stable_id: id) ||
types_de_champ_in_repetition.find_by!(stable_id: id)
types_de_champ.find_by(stable_id: id)
end
def types_de_champ_in_repetition

View file

@ -642,12 +642,15 @@ describe Instructeurs::DossiersController, type: :controller do
describe "#update_annotations" do
let(:procedure) do
create(:procedure, :published, types_de_champ_private: [
procedure = create(:procedure, :published, types_de_champ_private: [
build(:type_de_champ_multiple_drop_down_list, position: 0),
build(:type_de_champ_linked_drop_down_list, position: 1),
build(:type_de_champ_datetime, position: 2),
build(:type_de_champ_repetition, :with_types_de_champ, position: 3)
build(:type_de_champ_datetime, position: 2)
], instructeurs: instructeurs)
create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure, position: 3, private: true)
procedure
end
let(:dossier) { create(:dossier, :en_construction, :with_populated_annotations, procedure: procedure) }
let(:another_instructeur) { create(:instructeur) }

View file

@ -188,8 +188,17 @@ FactoryBot.define do
end
trait :with_types_de_champ do
after(:build) do |type_de_champ, _evaluator|
build(:type_de_champ, libelle: 'sub type de champ', parent: type_de_champ)
after(:build) do |type_de_champ, evaluator|
tdc = build(:type_de_champ, libelle: 'sub type de champ', parent: type_de_champ)
evaluator.procedure.save
ProcedureRevisionTypeDeChamp.create!(
revision_id: evaluator.procedure.active_revision.id,
type_de_champ_id: tdc.id,
parent_id: tdc.parent.revision_type_de_champ.id,
position: 0
)
end
end
end

View file

@ -90,7 +90,8 @@ shared_examples 'type_de_champ_spec' do
end
describe 'changing the type_champ from a repetition' do
let(:tdc) { create(:type_de_champ_repetition, :with_types_de_champ) }
let!(:procedure) { create(:procedure) }
let(:tdc) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure) }
before do
tdc.update_attribute('type_champ', target_type_champ)

View file

@ -2,6 +2,11 @@ describe DownloadableFileService do
let(:procedure) { create(:procedure, :published) }
let(:service) { ProcedureArchiveService.new(procedure) }
before do
FileUtils.mkdir_p('/tmp/test_archive_creation')
stub_const("DownloadableFileService::ARCHIVE_CREATION_DIR", '/tmp/test_archive_creation')
end
describe '#download_and_zip' do
let(:archive) { build(:archive, id: '3') }
let(:filename) { service.send(:zip_root_folder, archive) }