Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 'Fix Empty participatory process group is created when importing a PP …' to v0.26 #10733

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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