diff --git a/decidim-core/lib/decidim/core.rb b/decidim-core/lib/decidim/core.rb index b1a9ee59e7a16..5c53226198fef 100644 --- a/decidim-core/lib/decidim/core.rb +++ b/decidim-core/lib/decidim/core.rb @@ -145,17 +145,29 @@ def self.seed! participatory_space_manifests.each do |manifest| manifest.seed! - Organization.all.each do |organization| - ContextualHelpSection.set_content( - organization, - manifest.name, - Decidim::Faker::Localized.wrapped("
", "
") do - Decidim::Faker::Localized.sentence(word_count: 15) - end - ) - end + seed_contextual_help_sections!(manifest) + end + + seed_gamification_badges! + + seed_endorsements! + + I18n.available_locales = original_locale + end + + def self.seed_contextual_help_sections!(manifest) + Organization.all.each do |organization| + ContextualHelpSection.set_content( + organization, + manifest.name, + Decidim::Faker::Localized.wrapped("", "
") do + Decidim::Faker::Localized.sentence(word_count: 15) + end + ) end + end + def self.seed_gamification_badges! Gamification.badges.each do |badge| puts "Setting random values for the \"#{badge.name}\" badge..." User.all.find_each do |user| @@ -166,8 +178,24 @@ def self.seed! ) end end + end - I18n.available_locales = original_locale + def self.seed_endorsements! + resources_types = Decidim.resource_manifests + .map { |resource| resource.attributes[:model_class_name] } + .select { |resource| resource.constantize.include? Decidim::Endorsable } + + resources_types.each do |resource_type| + resource_type.constantize.find_each do |resource| + # exclude the users that already endorsed + users = resource.endorsements.map(&:author) + rand(50).times do + user = (Decidim::User.all - users).sample + Decidim::Endorsement.create!(resource:, author: user) + users << user + end + end + end end # Finds all currently loaded Decidim ActiveRecord classes and resets their