2024-01-26 13:43:10 +01:00
|
|
|
describe ProcedureRevisionPreloader do
|
|
|
|
let(:procedure) do
|
|
|
|
create(:procedure, :published,
|
|
|
|
types_de_champ_public: [
|
|
|
|
{ type: :integer_number },
|
|
|
|
{ type: :decimal_number }
|
|
|
|
],
|
|
|
|
types_de_champ_private: [
|
|
|
|
{ type: :text },
|
|
|
|
{ type: :textarea }
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.load_one' do
|
|
|
|
let(:revision) { procedure.draft_revision }
|
|
|
|
subject { ProcedureRevisionPreloader.load_one(revision) }
|
|
|
|
|
|
|
|
it 'assigns stuffs correctly' do
|
2024-01-26 14:45:37 +01:00
|
|
|
# check it changes loaded from false to true
|
|
|
|
expect { subject }.to change { procedure.draft_revision.association(:revision_types_de_champ).loaded? }.from(false).to(true)
|
|
|
|
|
|
|
|
# check loaded relationships
|
2024-01-26 13:43:10 +01:00
|
|
|
expect(procedure.draft_revision.association(:revision_types_de_champ_public).loaded?).to be_truthy
|
|
|
|
expect(procedure.draft_revision.association(:revision_types_de_champ_private).loaded?).to be_truthy
|
|
|
|
expect(procedure.draft_revision.association(:types_de_champ).loaded?).to be_truthy
|
|
|
|
expect(procedure.draft_revision.association(:types_de_champ_public).loaded?).to be_truthy
|
|
|
|
expect(procedure.draft_revision.association(:types_de_champ_private).loaded?).to be_truthy
|
|
|
|
|
2024-01-26 14:45:37 +01:00
|
|
|
# check nested relationship
|
2024-01-26 13:43:10 +01:00
|
|
|
expect(revision.revision_types_de_champ.first.association(:revision).loaded?).to eq(true)
|
|
|
|
expect(revision.revision_types_de_champ.first.association(:procedure).loaded?).to eq(true)
|
2024-01-26 14:45:37 +01:00
|
|
|
|
|
|
|
# check order
|
|
|
|
original = Procedure.find(procedure.id)
|
|
|
|
expect_relation_is_preloaded_sorted(original, procedure, :revision_types_de_champ)
|
|
|
|
expect_relation_is_preloaded_sorted(original, procedure, :revision_types_de_champ_public)
|
|
|
|
expect_relation_is_preloaded_sorted(original, procedure, :revision_types_de_champ_private)
|
|
|
|
expect_relation_is_preloaded_sorted(original, procedure, :types_de_champ)
|
|
|
|
expect_relation_is_preloaded_sorted(original, procedure, :types_de_champ_public)
|
|
|
|
expect_relation_is_preloaded_sorted(original, procedure, :types_de_champ_private)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_relation_is_preloaded_sorted(original, preloaded, association)
|
|
|
|
expect(original.draft_revision.send(association).map(&:id)).to eq(preloaded.draft_revision.send(association).map(&:id))
|
2024-01-26 13:43:10 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|