Skip to content

Commit

Permalink
Backport 'Fix Empty participatory process group is created when impor…
Browse files Browse the repository at this point in the history
…ting a PP …' to v0.26 (#10733)
  • Loading branch information
alecslupu committed Apr 25, 2023
1 parent 7537b44 commit 873c5ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Expand Up @@ -53,6 +53,11 @@ def import(attributes, _user, opts)
end

def import_process_group(attributes)
title = compact_translation(attributes["title"] || attributes["name"])
description = compact_translation(attributes["description"])

return if title.blank? && description.blank?

Decidim.traceability.perform_action!("create", ParticipatoryProcessGroup, @user) do
group = ParticipatoryProcessGroup.find_or_initialize_by(
title: attributes["title"] || attributes["name"],
Expand Down Expand Up @@ -152,6 +157,11 @@ def import_components(components)

private

def compact_translation(translation)
translation["machine_translations"] = translation["machine_translations"].reject { |_k, v| v.blank? } if translation["machine_translations"].present?
translation.reject { |_k, v| v.blank? }
end

def create_attachment_collection(attributes)
return unless attributes.compact.any?

Expand Down
Expand Up @@ -94,6 +94,19 @@ module Decidim::ParticipatoryProcesses
expect(group.title).to eq(group_data["name"])
end
end

context "when the process group is empty" do
let(:group_data) do
{
"title" => Decidim::Faker::Localized.localized { "" },
"description" => Decidim::Faker::Localized.localized { "" }
}
end

it "does not create a process group" do
expect { subject }.not_to change(Decidim::ParticipatoryProcessGroup, :count)
end
end
end
end
end

0 comments on commit 873c5ff

Please sign in to comment.