Skip to content

Commit

Permalink
Add more endorsements in seeds (decidim#11996)
Browse files Browse the repository at this point in the history
* Add more endorsements in seeds

* Refactor seed! method
  • Loading branch information
andreslucena authored Nov 14, 2023
1 parent d814fdc commit f4352e7
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions decidim-core/lib/decidim/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("<p>", "</p>") 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("<p>", "</p>") 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|
Expand All @@ -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
Expand Down

0 comments on commit f4352e7

Please sign in to comment.