Skip to content

Commit baad066

Browse files
authored
Merge pull request #90 from takahashim/add-seed
Add seeds for development
2 parents b1b4278 + 8741e8a commit baad066

File tree

3 files changed

+170
-5
lines changed

3 files changed

+170
-5
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ end
4444

4545
group :development, :test do
4646
# gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
47+
gem 'faker'
4748
gem 'listen'
4849

4950
gem 'letter_opener_web', git: 'https://github.com/fgrehm/letter_opener_web', ref: 'ab50ad09a2af5350bdca9c079bba73523e64f4cd' # https://github.com/fgrehm/letter_opener_web/pull/83

Gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ GEM
129129
factory_bot_rails (6.4.4)
130130
factory_bot (~> 6.5)
131131
railties (>= 5.0.0)
132+
faker (3.5.1)
133+
i18n (>= 1.8.11, < 2)
132134
faraday (1.10.4)
133135
faraday-em_http (~> 1.0)
134136
faraday-em_synchrony (~> 1.0)
@@ -376,6 +378,7 @@ DEPENDENCIES
376378
commonmarker
377379
connection_pool
378380
factory_bot_rails
381+
faker
379382
faraday
380383
faraday_middleware
381384
haml

db/seeds.rb

+166-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,168 @@
11
# This file should contain all the record creation needed to seed the database with its default values.
22
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3-
#
4-
# Examples:
5-
#
6-
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7-
# Character.create(name: 'Luke', movie: movies.first)
3+
4+
require "securerandom"
5+
6+
puts "Creating Conferences..."
7+
8+
ApplicationRecord.transaction do
9+
conferences = [
10+
{
11+
name: "RubyKaigi 4096",
12+
contact_email_address: "[email protected]",
13+
tito_slug: "rubykaigi/rubykaigi4096",
14+
application_opens_at: Time.zone.now - 1.month,
15+
application_closes_at: Time.zone.now + 1.month,
16+
amendment_closes_at: Time.zone.now + 2.months,
17+
ticket_distribution_starts_at: Time.zone.now + 1.week,
18+
github_repo: "ruby-no-kai/rubykaigi.org:data/year_4096/sponsors.yml",
19+
hidden: false
20+
}
21+
]
22+
23+
conferences.each do |conf_params|
24+
conference = Conference.find_or_initialize_by(name: conf_params[:name])
25+
conference.update!(conf_params)
26+
27+
# Plans
28+
puts "Creating plans for #{conference.name}..."
29+
[
30+
{
31+
name: "Ruby",
32+
price_text: "2,000,000 JPY",
33+
words_limit: 200,
34+
booth_size: 2,
35+
capacity: 6,
36+
rank: 0,
37+
auto_acceptance: false,
38+
closes_at: Time.now + 30.days
39+
},
40+
{
41+
name: "Platinum",
42+
price_text: "1,000,000 JPY",
43+
words_limit: 100,
44+
booth_size: 1,
45+
capacity: 30,
46+
rank: 1,
47+
auto_acceptance: false,
48+
closes_at: Time.now + 30.days
49+
},
50+
{
51+
name: "Gold",
52+
price_text: "500,000 JPY",
53+
words_limit: 50,
54+
booth_size: nil,
55+
capacity: 1000,
56+
rank: 2,
57+
},
58+
{
59+
name: "Silver",
60+
price_text: "250,000 JPY",
61+
words_limit: 25,
62+
booth_size: nil,
63+
capacity: 10000,
64+
rank: 3,
65+
}
66+
].each do |plan_params|
67+
conference.plans.find_or_create_by!(plan_params)
68+
end
69+
70+
# FormDescriptions
71+
puts "Creating form_descriptions for #{conference.name}..."
72+
[
73+
{
74+
locale: "en",
75+
head: "Thank you for your interest in sponsoring #{conference.name}. Please fill in the information for the main contact, invoice details, and your company information.",
76+
plan_help: "See the sponsorship prospectus for package details.",
77+
booth_help: "Sponsor booth is only applicable for sponsors in Ruby and Platinum plan as a paid add-on.",
78+
policy_help: "Please read the following policies and all agree to avide by. Note that the policy is required for all participants including attendees and booth staff.",
79+
ticket_help: "Select the tickets you'd like to include."
80+
},
81+
{
82+
locale: "ja",
83+
head: "#{conference.name} への協賛をご検討いただきありがとうございます。<br>スポンサーシップを希望される企業様はスポンサー募集要項をご確認の上、下記のフォームにてお申し込みください。",
84+
plan_help: "各プランの詳細は 募集要項 をご参照ください。",
85+
booth_help: "Ruby, Platinum スポンサーはスポンサーブースを出展することができます。詳細は募集要項をご参照ください。",
86+
policy_help: "RubyKaigi ではスポンサー (ブーススタッフ) を含む全ての参加者に下記ポリシーへの同意を求めています。必要に応じてブース担当者や招待チケット利用者にもご共有ください。",
87+
ticket_help: "含めたいチケットを選択してください。"
88+
}
89+
].each do |form_desc_params|
90+
conference.form_descriptions.find_or_create_by!(form_desc_params)
91+
end
92+
93+
# Organizations
94+
organizations = [
95+
{ name: "ふつうのRubyの株式会社", domain: "ordinary-ruby.example.jp", locale: "ja", plan: "Ruby", request: :customization },
96+
{ name: "Great Ruby Inc.", domain: "great-ruby.example.com", locale: "en", plan: "Platinum", request: :billing, billing_contact: true },
97+
{ name: "合同会社ゆかいなRubyists", domain: "cheerfull-rubyists.example.jp", locale: "ja", plan: "Gold", billing_contact: true },
98+
{ name: "Little Rubyists LLC", domain: "little-rubyists.example.com", locale: "en", plan: "Silver", request: :note },
99+
]
100+
101+
puts "Creating organizations and sponsorships for #{conference.name}..."
102+
organizations.each do |org_params|
103+
organization = Organization.find_or_create_by!(name: org_params[:name]) do |org|
104+
org.domain = org_params[:domain]
105+
end
106+
107+
# Sponsorships
108+
plans = conference.plans
109+
sponsorship_params = {
110+
name: organization.name,
111+
organization: organization,
112+
conference: conference,
113+
url: "https://#{organization.domain}",
114+
profile: "#{organization.name} is a leader in innovation and technology.",
115+
plan: plans.find_by(name: org_params[:plan]),
116+
booth_requested: (org_params[:plan] == "Ruby"),
117+
booth_assigned: false,
118+
locale: org_params[:locale],
119+
number_of_additional_attendees: 2,
120+
}
121+
sponsorship = Sponsorship.new(sponsorship_params)
122+
123+
# Asset Files
124+
asset_file = sponsorship.build_asset_file(
125+
prefix: "sponsorships/",
126+
extension: "zip",
127+
handle: SecureRandom.urlsafe_base64(32)
128+
)
129+
130+
# Contacts (:primary)
131+
sponsorship.build_contact(
132+
organization: sponsorship.name,
133+
name: Faker::Name.name,
134+
email: Faker::Internet.email(domain: organization.domain),
135+
kind: :primary,
136+
address: Faker::Address.full_address,
137+
email_cc: "#{Faker::Internet.email(domain: organization.domain)}, #{Faker::Internet.email(domain: organization.domain)}"
138+
)
139+
140+
# Contacts (:billing)
141+
if org_params[:billing_contact]
142+
sponsorship.contacts.build(
143+
organization: sponsorship.name,
144+
name: Faker::Name.name,
145+
email: Faker::Internet.email(domain: organization.domain),
146+
kind: :billing,
147+
address: Faker::Address.full_address
148+
)
149+
end
150+
151+
# Sponsorship Requests
152+
if org_params[:request]
153+
body = if sponsorship.locale == "ja"
154+
"#{sponsorship.name}のリクエストです。"
155+
else
156+
"Hello from #{sponsorship.name}!"
157+
end
158+
request = SponsorshipRequest.new(kind: org_params[:request], body: )
159+
sponsorship.requests << request
160+
end
161+
162+
sponsorship.accept if sponsorship.plan&.auto_acceptance
163+
sponsorship.save!
164+
end
165+
end
166+
end
167+
168+
puts "Seeding complete!"

0 commit comments

Comments
 (0)