mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Merge remote-tracking branch 'origin/registry-515' into registry-475
This commit is contained in:
commit
e14bac337e
4 changed files with 141 additions and 34 deletions
|
@ -45,6 +45,7 @@ Manual demo install and database setup:
|
||||||
cp config/application-example.yml config/application.yml # and edit it
|
cp config/application-example.yml config/application.yml # and edit it
|
||||||
cp config/database-example.yml config/database.yml # and edit it
|
cp config/database-example.yml config/database.yml # and edit it
|
||||||
bundle exec rake db:setup:all # for production, please follow deployment howto
|
bundle exec rake db:setup:all # for production, please follow deployment howto
|
||||||
|
bundle exec rake:bootstrap
|
||||||
bundle exec rake assets:precompile
|
bundle exec rake assets:precompile
|
||||||
|
|
||||||
### Apache with patched mod_epp (Debian 7/Ubuntu 14.04 LTS)
|
### Apache with patched mod_epp (Debian 7/Ubuntu 14.04 LTS)
|
||||||
|
|
34
db/seeds.rb
34
db/seeds.rb
|
@ -1,36 +1,2 @@
|
||||||
# This file should contain all the record creation needed to seed the database with its default values.
|
# 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 rake db:seed (or created alongside the db with db:setup).
|
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
|
||||||
registrar = Registrar.create!(
|
|
||||||
name: 'Test',
|
|
||||||
reg_no: '1234',
|
|
||||||
street: 'test',
|
|
||||||
city: 'test',
|
|
||||||
state: 'test',
|
|
||||||
zip: '1234',
|
|
||||||
email: 'test@domain.tld',
|
|
||||||
country_code: 'US',
|
|
||||||
code: 'US1'
|
|
||||||
)
|
|
||||||
|
|
||||||
registrar.accounts.create!(account_type: Account::CASH, currency: 'EUR')
|
|
||||||
|
|
||||||
ApiUser.create!(
|
|
||||||
username: 'test',
|
|
||||||
password: 'testtest',
|
|
||||||
identity_code: '51001091072',
|
|
||||||
active: true,
|
|
||||||
registrar: registrar,
|
|
||||||
roles: ['super']
|
|
||||||
)
|
|
||||||
|
|
||||||
AdminUser.create!(
|
|
||||||
username: 'test',
|
|
||||||
email: 'test@domain.tld',
|
|
||||||
password: 'testtest',
|
|
||||||
password_confirmation: 'testtest',
|
|
||||||
country_code: 'US',
|
|
||||||
roles: ['admin']
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
11
lib/tasks/bootstrap.rake
Normal file
11
lib/tasks/bootstrap.rake
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
desc 'Bootstraps production-like environment'
|
||||||
|
task :bootstrap do
|
||||||
|
AdminUser.create!(
|
||||||
|
username: 'admin',
|
||||||
|
email: 'admin@domain.tld',
|
||||||
|
password: 'adminadmin',
|
||||||
|
password_confirmation: 'adminadmin',
|
||||||
|
country_code: 'US',
|
||||||
|
roles: ['admin']
|
||||||
|
)
|
||||||
|
end
|
129
lib/tasks/dev.rake
Normal file
129
lib/tasks/dev.rake
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
namespace :dev do
|
||||||
|
desc 'Generates dummy data in development environment' \
|
||||||
|
' (options: [random] for random data generation - slowest)'
|
||||||
|
|
||||||
|
task :prime, [:random] => :environment do |t, args|
|
||||||
|
abort 'Production environment is not supported' if Rails.env.production?
|
||||||
|
|
||||||
|
require 'factory_girl'
|
||||||
|
include FactoryGirl::Syntax::Methods
|
||||||
|
FactoryGirl.find_definitions
|
||||||
|
|
||||||
|
PaperTrail.enabled = false
|
||||||
|
with_random_data = args[:random].present?
|
||||||
|
|
||||||
|
def generate_default_data
|
||||||
|
create(:admin_user, username: 'test', password: 'testtest', password_confirmation: 'testtest')
|
||||||
|
|
||||||
|
zone = create(:zone, origin: 'test')
|
||||||
|
registrar = create(:registrar, name: 'test')
|
||||||
|
registrant = create(:registrant, name: 'test', registrar: registrar)
|
||||||
|
|
||||||
|
create(:account, registrar: registrar, balance: 1_000_000)
|
||||||
|
create(:api_user, username: 'test', password: 'testtest', registrar: registrar)
|
||||||
|
create(:domain,
|
||||||
|
name: 'test.test',
|
||||||
|
period: 1,
|
||||||
|
period_unit: 'y',
|
||||||
|
registered_at: Time.zone.now,
|
||||||
|
valid_from: Time.zone.now,
|
||||||
|
expire_time: Time.zone.now + 10.years,
|
||||||
|
registrar: registrar,
|
||||||
|
registrant: registrant)
|
||||||
|
|
||||||
|
Billing::Price.durations.each do |duration|
|
||||||
|
Billing::Price.operation_categories.each do |operation_category|
|
||||||
|
create(:price,
|
||||||
|
price: Money.from_amount(1),
|
||||||
|
valid_from: Time.zone.now.beginning_of_day,
|
||||||
|
valid_to: Time.zone.now + 10.years,
|
||||||
|
duration: duration,
|
||||||
|
operation_category: operation_category,
|
||||||
|
zone: zone)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_random_data
|
||||||
|
zone_count = 10
|
||||||
|
admin_user_count = 5
|
||||||
|
registrar_count = 50
|
||||||
|
api_user_count = 10
|
||||||
|
registrant_count = 50
|
||||||
|
domain_count = 50
|
||||||
|
registrars = []
|
||||||
|
registrants = []
|
||||||
|
zones = []
|
||||||
|
registrant_names = [
|
||||||
|
'John Doe',
|
||||||
|
'John Roe',
|
||||||
|
'Jane Doe',
|
||||||
|
'Jane Roe',
|
||||||
|
'John Smith',
|
||||||
|
]
|
||||||
|
|
||||||
|
zone_count.times do
|
||||||
|
origin = SecureRandom.hex[0..(rand(5) + 1)]
|
||||||
|
zones << create(:zone, origin: origin)
|
||||||
|
end
|
||||||
|
|
||||||
|
zone_origins = zones.collect { |zone| zone.origin }
|
||||||
|
|
||||||
|
admin_user_count.times do
|
||||||
|
uid = SecureRandom.hex[0..(rand(5) + 1)]
|
||||||
|
create(:admin_user, username: "test#{uid}", password: 'testtest', password_confirmation: 'testtest')
|
||||||
|
end
|
||||||
|
|
||||||
|
registrar_count.times do
|
||||||
|
uid = SecureRandom.hex[0..(rand(5) + 1)]
|
||||||
|
registrars << create(:registrar, name: "Acme Ltd. #{uid}")
|
||||||
|
end
|
||||||
|
|
||||||
|
registrars.each do |registrar|
|
||||||
|
create(:account, registrar: registrar, balance: rand(99999))
|
||||||
|
|
||||||
|
api_user_count.times do |i|
|
||||||
|
create(:api_user, username: "test#{registrar.id}#{i}", password: 'testtest', registrar: registrar)
|
||||||
|
end
|
||||||
|
|
||||||
|
registrant_count.times do |i|
|
||||||
|
registrants << create(:registrant, name: registrant_names.sample, registrar: registrar)
|
||||||
|
end
|
||||||
|
|
||||||
|
domain_count.times do |i|
|
||||||
|
name = "test#{registrar.id}#{i}#{rand(99999)}.#{zone_origins.sample}"
|
||||||
|
period = rand(3) + 1
|
||||||
|
|
||||||
|
create(:domain,
|
||||||
|
name: name,
|
||||||
|
period: period,
|
||||||
|
period_unit: 'y',
|
||||||
|
registered_at: Time.zone.now,
|
||||||
|
valid_from: Time.zone.now,
|
||||||
|
expire_time: Time.zone.now + period.years,
|
||||||
|
registrar: registrar,
|
||||||
|
registrant: registrants.sample)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
zones.each do |zone|
|
||||||
|
Billing::Price.durations.each do |duration|
|
||||||
|
Billing::Price.operation_categories.each do |operation_category|
|
||||||
|
create(:price,
|
||||||
|
price: Money.from_amount(rand(10) + 1),
|
||||||
|
valid_from: Time.zone.now.beginning_of_day,
|
||||||
|
valid_to: Time.zone.now + (rand(10) + 1).years,
|
||||||
|
duration: duration,
|
||||||
|
operation_category: operation_category,
|
||||||
|
zone: zone)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
generate_default_data
|
||||||
|
generate_random_data if with_random_data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue