Class: Decidim::Conferences::Seeds
- Inherits:
-
Seeds
- Object
- Seeds
- Decidim::Conferences::Seeds
- Defined in:
- lib/decidim/conferences/seeds.rb
Instance Method Summary collapse
- #call ⇒ Object
- #create_conference! ⇒ Object
- #create_conference_media_link!(conference:) ⇒ Object
- #create_conference_meeting!(conference:) ⇒ Object
- #create_conference_partner!(conference:, type:) ⇒ Object
- #create_conference_registration_type!(conference:) ⇒ Object
- #create_conference_speaker!(conference:) ⇒ Object
- #create_conference_user_roles!(conference:) ⇒ Object
- #create_content_block! ⇒ Object
Instance Method Details
#call ⇒ Object
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 35 36 37 38 39 40 41 42 |
# File 'lib/decidim/conferences/seeds.rb', line 8 def call create_content_block! number_of_records.times do |_n| conference = create_conference! create_conference_user_roles!(conference:) (attached_to: conference) number_of_records.times do create_conference_speaker!(conference:) end Decidim::Conferences::Partner::TYPES.map do |type| number_of_records.times do create_conference_partner!(conference:, type:) end end number_of_records.times do create_conference_media_link!(conference:) end number_of_records.times do create_conference_registration_type!(conference:) end Decidim.component_manifests.each do |manifest| manifest.seed!(conference.reload) end create_conference_meeting!(conference:) end end |
#create_conference! ⇒ Object
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 |
# File 'lib/decidim/conferences/seeds.rb', line 54 def create_conference! params = { title: Decidim::Faker::Localized.sentence(word_count: 5), slogan: Decidim::Faker::Localized.sentence(word_count: 2), slug: Decidim::Faker::Internet.unique.slug(words: nil, glue: "-"), 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) ? : nil, # Keep after organization promoted: true, published_at: 2.weeks.ago, objectives: Decidim::Faker::Localized.wrapped("<p>", "</p>") do Decidim::Faker::Localized.paragraph(sentence_count: 3) end, start_date: Time.current, end_date: 2.months.from_now.at_midnight, registrations_enabled: [true, false].sample, available_slots: (10..50).step(10).to_a.sample, registration_terms: Decidim::Faker::Localized.wrapped("<p>", "</p>") do Decidim::Faker::Localized.paragraph(sentence_count: 3) end } conference = Decidim.traceability.perform_action!( "publish", Decidim::Conference, organization.users.first, visibility: "all" ) do Decidim::Conference.create!(params) end conference.add_to_index_as_search_resource conference end |
#create_conference_media_link!(conference:) ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/decidim/conferences/seeds.rb', line 136 def create_conference_media_link!(conference:) Decidim::Conferences::MediaLink.create!( title: Decidim::Faker::Localized.sentence(word_count: 2), link: ::Faker::Internet.url, date: Date.current, weight: ::Faker::Number.between(from: 1, to: 10), conference: ) end |
#create_conference_meeting!(conference:) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/decidim/conferences/seeds.rb', line 157 def create_conference_meeting!(conference:) Decidim::ConferenceMeeting.where(component: conference.components).each do |conference_meeting| next unless ::Faker::Boolean.boolean(true_ratio: 0.5) conference.speakers.sample(3).each do |speaker| Decidim::ConferenceSpeakerConferenceMeeting.create!( conference_meeting:, conference_speaker: speaker ) end end end |
#create_conference_partner!(conference:, type:) ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/decidim/conferences/seeds.rb', line 125 def create_conference_partner!(conference:, type:) Decidim::Conferences::Partner.create!( name: ::Faker::Name.name, weight: ::Faker::Number.between(from: 1, to: 10), link: ::Faker::Internet.url, partner_type: type, conference:, logo: create_blob!(seeds_file: "logo.png", filename: "logo.png", content_type: "image/png") ) end |
#create_conference_registration_type!(conference:) ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/decidim/conferences/seeds.rb', line 146 def create_conference_registration_type!(conference:) Decidim::Conferences::RegistrationType.create!( title: Decidim::Faker::Localized.sentence(word_count: 2), description: Decidim::Faker::Localized.sentence(word_count: 5), weight: ::Faker::Number.between(from: 1, to: 10), price: ::Faker::Number.between(from: 1, to: 300), published_at: 2.weeks.ago, conference: ) end |
#create_conference_speaker!(conference:) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/decidim/conferences/seeds.rb', line 109 def create_conference_speaker!(conference:) Decidim::ConferenceSpeaker.create!( user: conference.organization.users.sample, full_name: ::Faker::Name.name, position: Decidim::Faker::Localized.word, affiliation: Decidim::Faker::Localized.sentence(word_count: 3), short_bio: Decidim::Faker::Localized.wrapped("<p>", "</p>") do Decidim::Faker::Localized.paragraph(sentence_count: 3) end, twitter_handle: ::Faker::Twitter.unique.screen_name, personal_url: ::Faker::Internet.url, published_at: Time.current, conference: ) end |
#create_conference_user_roles!(conference:) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/decidim/conferences/seeds.rb', line 95 def create_conference_user_roles!(conference:) # Create users with specific roles Decidim::ConferenceUserRole::ROLES.each do |role| email = "conference_#{conference.id}_#{role}@example.org" user = find_or_initialize_user_by(email:) Decidim::ConferenceUserRole.find_or_create_by!( user:, conference:, role: ) end end |
#create_content_block! ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/decidim/conferences/seeds.rb', line 44 def create_content_block! Decidim::ContentBlock.create( organization:, weight: 33, scope_name: :homepage, manifest_name: :highlighted_conferences, published_at: Time.current ) end |