Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add seeds for development #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ end

group :development, :test do
# gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'faker'
gem 'listen'
end

Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ GEM
diff-lcs (1.5.1)
drb (2.2.1)
erubi (1.13.0)
faker (3.5.1)
i18n (>= 1.8.11, < 2)
faraday (1.10.4)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
Expand Down Expand Up @@ -370,6 +372,7 @@ DEPENDENCIES
barnes
commonmarker
connection_pool
faker
faraday
faraday_middleware
haml
Expand Down
171 changes: 166 additions & 5 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,168 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)

require "securerandom"

puts "Creating Conferences..."

ApplicationRecord.transaction do
conferences = [
{
name: "RubyKaigi 4096",
contact_email_address: "[email protected]",
tito_slug: "rubykaigi/rubykaigi4096",
application_opens_at: Time.zone.now - 1.month,
application_closes_at: Time.zone.now + 1.month,
amendment_closes_at: Time.zone.now + 2.months,
ticket_distribution_starts_at: Time.zone.now + 1.week,
github_repo: "ruby-no-kai/rubykaigi.org:data/year_4096/sponsors.yml",
hidden: false
}
]

conferences.each do |conf_params|
conference = Conference.find_or_initialize_by(name: conf_params[:name])
conference.update!(conf_params)

# Plans
puts "Creating plans for #{conference.name}..."
[
{
name: "Ruby",
price_text: "2,000,000 JPY",
words_limit: 200,
booth_size: 2,
capacity: 6,
rank: 0,
auto_acceptance: false,
closes_at: Time.now + 30.days
},
{
name: "Platinum",
price_text: "1,000,000 JPY",
words_limit: 100,
booth_size: 1,
capacity: 30,
rank: 1,
auto_acceptance: false,
closes_at: Time.now + 30.days
},
{
name: "Gold",
price_text: "500,000 JPY",
words_limit: 50,
booth_size: nil,
capacity: 1000,
rank: 2,
},
{
name: "Silver",
price_text: "250,000 JPY",
words_limit: 25,
booth_size: nil,
capacity: 10000,
rank: 3,
}
].each do |plan_params|
conference.plans.find_or_create_by!(plan_params)
end

# FormDescriptions
puts "Creating form_descriptions for #{conference.name}..."
[
{
locale: "en",
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.",
plan_help: "See the sponsorship prospectus for package details.",
booth_help: "Sponsor booth is only applicable for sponsors in Ruby and Platinum plan as a paid add-on.",
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.",
ticket_help: "Select the tickets you'd like to include."
},
{
locale: "ja",
head: "#{conference.name} への協賛をご検討いただきありがとうございます。<br>スポンサーシップを希望される企業様はスポンサー募集要項をご確認の上、下記のフォームにてお申し込みください。",
plan_help: "各プランの詳細は 募集要項 をご参照ください。",
booth_help: "Ruby, Platinum スポンサーはスポンサーブースを出展することができます。詳細は募集要項をご参照ください。",
policy_help: "RubyKaigi ではスポンサー (ブーススタッフ) を含む全ての参加者に下記ポリシーへの同意を求めています。必要に応じてブース担当者や招待チケット利用者にもご共有ください。",
ticket_help: "含めたいチケットを選択してください。"
}
].each do |form_desc_params|
conference.form_descriptions.find_or_create_by!(form_desc_params)
end

# Organizations
organizations = [
{ name: "ふつうのRubyの株式会社", domain: "ordinary-ruby.example.jp", locale: "ja", plan: "Ruby", request: :customization },
{ name: "Great Ruby Inc.", domain: "great-ruby.example.com", locale: "en", plan: "Platinum", request: :billing, billing_contact: true },
{ name: "合同会社ゆかいなRubyists", domain: "cheerfull-rubyists.example.jp", locale: "ja", plan: "Gold", billing_contact: true },
{ name: "Little Rubyists LLC", domain: "little-rubyists.example.com", locale: "en", plan: "Silver", request: :note },
]

puts "Creating organizations and sponsorships for #{conference.name}..."
organizations.each do |org_params|
organization = Organization.find_or_create_by!(name: org_params[:name]) do |org|
org.domain = org_params[:domain]
end

# Sponsorships
plans = conference.plans
sponsorship_params = {
name: organization.name,
organization: organization,
conference: conference,
url: "https://#{organization.domain}",
profile: "#{organization.name} is a leader in innovation and technology.",
plan: plans.find_by(name: org_params[:plan]),
booth_requested: (org_params[:plan] == "Ruby"),
booth_assigned: false,
locale: org_params[:locale],
number_of_additional_attendees: 2,
}
sponsorship = Sponsorship.new(sponsorship_params)

# Asset Files
asset_file = sponsorship.build_asset_file(
prefix: "sponsorships/",
extension: "zip",
handle: SecureRandom.urlsafe_base64(32)
)

# Contacts (:primary)
sponsorship.build_contact(
organization: sponsorship.name,
name: Faker::Name.name,
email: Faker::Internet.email(domain: organization.domain),
kind: :primary,
address: Faker::Address.full_address,
email_cc: "#{Faker::Internet.email(domain: organization.domain)}, #{Faker::Internet.email(domain: organization.domain)}"
)

# Contacts (:billing)
if org_params[:billing_contact]
sponsorship.contacts.build(
organization: sponsorship.name,
name: Faker::Name.name,
email: Faker::Internet.email(domain: organization.domain),
kind: :billing,
address: Faker::Address.full_address
)
end

# Sponsorship Requests
if org_params[:request]
body = if sponsorship.locale == "ja"
"#{sponsorship.name}のリクエストです。"
else
"Hello from #{sponsorship.name}!"
end
request = SponsorshipRequest.new(kind: org_params[:request], body: )
sponsorship.requests << request
end

sponsorship.accept if sponsorship.plan&.auto_acceptance
sponsorship.save!
end
end
end

puts "Seeding complete!"