Class: Decidim::Assemblies::Seeds

Inherits:
Seeds
  • Object
show all
Defined in:
lib/decidim/assemblies/seeds.rb

Instance Method Summary collapse

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/decidim/assemblies/seeds.rb', line 8

def call
  create_content_block!

  2.times do |_n|
    assembly = create_assembly!

    create_assembly_user_roles!(assembly:)

    child = create_assembly!(parent: assembly)

    [assembly, child].each do |current_assembly|
      current_assembly.add_to_index_as_search_resource

      create_attachments!(attached_to: current_assembly)

      2.times do
        create_category!(participatory_space: current_assembly)
      end

      create_assembly_members!(assembly: current_assembly)

      seed_components_manifests!(participatory_space: current_assembly)

      Decidim::ContentBlocksCreator.new(current_assembly).create_default!
    end
  end
end

#create_assembly!(parent: nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/decidim/assemblies/seeds.rb', line 46

def create_assembly!(parent: nil)
  n = rand(2)
  params = {
    title: Decidim::Faker::Localized.sentence(word_count: 5),
    slug: Decidim::Faker::Internet.unique.slug(words: nil, glue: "-"),
    subtitle: Decidim::Faker::Localized.sentence(word_count: 2),
    hashtag: "##{::Faker::Lorem.word}",
    short_description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
      Decidim::Faker::Localized.sentence(word_count: 3)
    end,
    description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
      Decidim::Faker::Localized.paragraph(sentence_count: 3)
    end,
    organization:,
    hero_image: ::Faker::Boolean.boolean(true_ratio: 0.5) ? hero_image : nil, # Keep after organization
    banner_image: ::Faker::Boolean.boolean(true_ratio: 0.5) ? banner_image : nil, # Keep after organization
    promoted: true,
    published_at: 2.weeks.ago,
    meta_scope: Decidim::Faker::Localized.word,
    developer_group: Decidim::Faker::Localized.sentence(word_count: 1),
    local_area: Decidim::Faker::Localized.sentence(word_count: 2),
    target: Decidim::Faker::Localized.sentence(word_count: 3),
    participatory_scope: Decidim::Faker::Localized.sentence(word_count: 1),
    participatory_structure: Decidim::Faker::Localized.sentence(word_count: 2),
    scope: n.positive? ? Decidim::Scope.all.sample : nil,
    purpose_of_action: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
      Decidim::Faker::Localized.paragraph(sentence_count: 3)
    end,
    composition: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
      Decidim::Faker::Localized.paragraph(sentence_count: 3)
    end,
    assembly_type: Decidim::AssembliesType.create!(organization:, title: Decidim::Faker::Localized.word),
    creation_date: 1.day.from_now,
    created_by: "others",
    created_by_other: Decidim::Faker::Localized.word,
    duration: 2.days.from_now,
    included_at: 5.days.from_now,
    closing_date: 5.days.from_now,
    closing_date_reason: Decidim::Faker::Localized.sentence(word_count: 3),
    internal_organisation: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
      Decidim::Faker::Localized.paragraph(sentence_count: 3)
    end,
    is_transparent: true,
    special_features: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
      Decidim::Faker::Localized.paragraph(sentence_count: 3)
    end,
    twitter_handler: ::Faker::Lorem.word,
    facebook_handler: ::Faker::Lorem.word,
    instagram_handler: ::Faker::Lorem.word,
    youtube_handler: ::Faker::Lorem.word,
    github_handler: ::Faker::Lorem.word,
    parent:
  }

  Decidim.traceability.perform_action!(
    "publish",
    Decidim::Assembly,
    organization.users.first,
    visibility: "all"
  ) do
    Decidim::Assembly.create!(params)
  end
end

#create_assembly_members!(assembly:) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/decidim/assemblies/seeds.rb', line 124

def create_assembly_members!(assembly:)
  Decidim::AssemblyMember::POSITIONS.each do |position|
    Decidim::AssemblyMember.create!(
      full_name: ::Faker::Name.name,
      gender: ::Faker::Lorem.word,
      birthday: ::Faker::Date.birthday(min_age: 18, max_age: 65),
      birthplace: ::Faker::Demographic.demonym,
      designation_date: ::Faker::Date.between(from: 1.year.ago, to: 1.month.ago),
      position:,
      position_other: position == "other" ? ::Faker::Job.position : nil,
      assembly:
    )
  end

  Decidim::AssemblyMember.create!(
    user: assembly.organization.users.first,
    gender: ::Faker::Lorem.word,
    birthday: ::Faker::Date.birthday(min_age: 18, max_age: 65),
    birthplace: ::Faker::Demographic.demonym,
    designation_date: ::Faker::Date.between(from: 1.year.ago, to: 1.month.ago),
    position: "other",
    position_other: ::Faker::Job.position,
    assembly:
  )
end

#create_assembly_user_roles!(assembly:) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/decidim/assemblies/seeds.rb', line 110

def create_assembly_user_roles!(assembly:)
  # Create users with specific roles
  Decidim::AssemblyUserRole::ROLES.each do |role|
    email = "assembly_#{assembly.id}_#{role}@example.org"
    user = find_or_initialize_user_by(email:)

    Decidim::AssemblyUserRole.find_or_create_by!(
      user:,
      assembly:,
      role:
    )
  end
end

#create_content_block!Object



36
37
38
39
40
41
42
43
44
# File 'lib/decidim/assemblies/seeds.rb', line 36

def create_content_block!
  Decidim::ContentBlock.create(
    organization:,
    weight: 32,
    scope_name: :homepage,
    manifest_name: :highlighted_assemblies,
    published_at: Time.current
  )
end