Skip to content

Commit 0fe7e45

Browse files
committed
test creation of attachment collections
1 parent 4722f90 commit 0fe7e45

2 files changed

Lines changed: 206 additions & 0 deletions

File tree

decidim-assemblies/spec/serializers/decidim/assemblies/assembly_importer_spec.rb

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,109 @@ module Decidim::Assemblies
410410
.not_to change(Decidim::Attachment, :count)
411411
end
412412
end
413+
414+
context "when attachment collection is not defined" do
415+
let(:attachments_data) do
416+
{
417+
"files" => [
418+
{
419+
"title" => { "en" => "Test File" },
420+
"description" => { "en" => "Test Description" },
421+
"weight" => 1,
422+
"remote_file_url" => remote_file_url
423+
}
424+
]
425+
}
426+
end
427+
428+
before do
429+
stub_request(:head, remote_file_url)
430+
.to_return(status: 200, headers: { "Content-Type" => "application/pdf" })
431+
stub_request(:get, remote_file_url)
432+
.to_return(status: 200, body: File.read(Decidim::Dev.asset("Exampledocument.pdf")))
433+
end
434+
435+
it "does not create any attachments collections" do
436+
expect { importer.import_folders_and_attachments(attachments_data) }
437+
.not_to change(Decidim::AttachmentCollection, :count)
438+
end
439+
end
440+
441+
context "when attachment collection is nil" do
442+
let(:attachments_data) do
443+
{
444+
"files" => [
445+
{
446+
"title" => { "en" => "Test File" },
447+
"description" => { "en" => "Test Description" },
448+
"weight" => 1,
449+
"remote_file_url" => remote_file_url
450+
}
451+
],
452+
"attachment_collections" => nil
453+
}
454+
end
455+
456+
before do
457+
stub_request(:head, remote_file_url)
458+
.to_return(status: 200, headers: { "Content-Type" => "application/pdf" })
459+
stub_request(:get, remote_file_url)
460+
.to_return(status: 200, body: File.read(Decidim::Dev.asset("Exampledocument.pdf")))
461+
end
462+
463+
it "does not create any attachments collections" do
464+
expect { importer.import_folders_and_attachments(attachments_data) }
465+
.not_to change(Decidim::AttachmentCollection, :count)
466+
end
467+
end
468+
469+
context "when attachment collection is defined" do
470+
let(:attachment_data) do
471+
{
472+
"files" => [
473+
{
474+
"title" => { "en" => "Test File" },
475+
"description" => { "en" => "Test Description" },
476+
"weight" => 1,
477+
"remote_file_url" => remote_file_url,
478+
"attachment_collections" => {
479+
"name" => {
480+
"en" => "Collection name"
481+
},
482+
"weight" => 0,
483+
"description" => {
484+
"en" => "Collection description"
485+
}
486+
}
487+
}
488+
],
489+
"attachment_collections" => [
490+
{
491+
"name" => {
492+
"en" => "Collection name"
493+
},
494+
"weight" => 0,
495+
"description" => {
496+
"en" => "Collection description"
497+
}
498+
}
499+
]
500+
}
501+
end
502+
503+
before do
504+
stub_request(:head, remote_file_url)
505+
.to_return(status: 200, headers: { "Content-Type" => "application/pdf" })
506+
stub_request(:get, remote_file_url)
507+
.to_return(status: 200, body: File.read(Decidim::Dev.asset("Exampledocument.pdf")))
508+
end
509+
510+
it "creates the attachment and the collection" do
511+
expect { importer.import_folders_and_attachments(attachment_data) }
512+
.to change(Decidim::Attachment, :count).by(1)
513+
.and change(Decidim::AttachmentCollection, :count).by(1)
514+
end
515+
end
413516
end
414517
end
415518
end

decidim-participatory_processes/spec/serializers/decidim/participatory_processes/participatory_process_importer_spec.rb

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,109 @@ module Decidim::ParticipatoryProcesses
530530
.not_to change(Decidim::Attachment, :count)
531531
end
532532
end
533+
534+
context "when the attachment collection is not defined" do
535+
let(:attachments_data) do
536+
{
537+
"files" => [
538+
{
539+
"title" => { "en" => "Test File" },
540+
"description" => { "en" => "Test Description" },
541+
"weight" => 1,
542+
"remote_file_url" => remote_file_url
543+
}
544+
]
545+
}
546+
end
547+
548+
before do
549+
stub_request(:head, remote_file_url)
550+
.to_return(status: 200, headers: { "Content-Type" => "application/pdf" })
551+
stub_request(:get, remote_file_url)
552+
.to_return(status: 200, body: File.read(Decidim::Dev.asset("Exampledocument.pdf")))
553+
end
554+
555+
it "does not create any attachments collections" do
556+
expect { importer.import_folders_and_attachments(attachments_data) }
557+
.not_to change(Decidim::AttachmentCollection, :count)
558+
end
559+
end
560+
561+
context "when the attachment collection is nil" do
562+
let(:attachments_data) do
563+
{
564+
"files" => [
565+
{
566+
"title" => { "en" => "Test File" },
567+
"description" => { "en" => "Test Description" },
568+
"weight" => 1,
569+
"remote_file_url" => remote_file_url
570+
}
571+
],
572+
"attachment_collections" => nil
573+
}
574+
end
575+
576+
before do
577+
stub_request(:head, remote_file_url)
578+
.to_return(status: 200, headers: { "Content-Type" => "application/pdf" })
579+
stub_request(:get, remote_file_url)
580+
.to_return(status: 200, body: File.read(Decidim::Dev.asset("Exampledocument.pdf")))
581+
end
582+
583+
it "does not create any attachments collections" do
584+
expect { importer.import_folders_and_attachments(attachments_data) }
585+
.not_to change(Decidim::AttachmentCollection, :count)
586+
end
587+
end
588+
589+
context "when attachment collection is defined" do
590+
let(:attachment_data) do
591+
{
592+
"files" => [
593+
{
594+
"title" => { "en" => "Test File" },
595+
"description" => { "en" => "Test Description" },
596+
"weight" => 1,
597+
"remote_file_url" => remote_file_url,
598+
"attachment_collections" => {
599+
"name" => {
600+
"en" => "Collection name"
601+
},
602+
"weight" => 0,
603+
"description" => {
604+
"en" => "Collection description"
605+
}
606+
}
607+
}
608+
],
609+
"attachment_collections" => [
610+
{
611+
"name" => {
612+
"en" => "Collection name"
613+
},
614+
"weight" => 0,
615+
"description" => {
616+
"en" => "Collection description"
617+
}
618+
}
619+
]
620+
}
621+
end
622+
623+
before do
624+
stub_request(:head, remote_file_url)
625+
.to_return(status: 200, headers: { "Content-Type" => "application/pdf" })
626+
stub_request(:get, remote_file_url)
627+
.to_return(status: 200, body: File.read(Decidim::Dev.asset("Exampledocument.pdf")))
628+
end
629+
630+
it "creates the attachment and the collection" do
631+
expect { importer.import_folders_and_attachments(attachment_data) }
632+
.to change(Decidim::Attachment, :count).by(1)
633+
.and change(Decidim::AttachmentCollection, :count).by(1)
634+
end
635+
end
533636
end
534637
end
535638
end

0 commit comments

Comments
 (0)