mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
parent
b1bf725e27
commit
72d0c74b0f
1 changed files with 72 additions and 18 deletions
|
@ -10,8 +10,37 @@ namespace :dev do
|
|||
FactoryGirl.find_definitions
|
||||
|
||||
PaperTrail.enabled = false
|
||||
Domain.paper_trail_on!
|
||||
Contact.paper_trail_on!
|
||||
|
||||
with_random_data = args[:random].present?
|
||||
|
||||
def create_domain(name:, registrar:, registrant:, account:, price:, reg_time:)
|
||||
duration = price.duration.sub('mons', 'months').split("\s")
|
||||
period = duration.first.to_i
|
||||
period_unit = duration.second[0]
|
||||
|
||||
create(:domain,
|
||||
name: name,
|
||||
period: period,
|
||||
period_unit: period_unit,
|
||||
registered_at: reg_time,
|
||||
valid_from: reg_time,
|
||||
expire_time: reg_time + period.send(duration.second.to_sym),
|
||||
created_at: reg_time,
|
||||
updated_at: reg_time,
|
||||
registrar: registrar,
|
||||
registrant: registrant)
|
||||
|
||||
create(:account_activity,
|
||||
account: account,
|
||||
sum: -price.price.amount,
|
||||
activity_type: AccountActivity::CREATE,
|
||||
created_at: reg_time,
|
||||
updated_at: reg_time,
|
||||
price: price)
|
||||
end
|
||||
|
||||
def generate_default_data
|
||||
create(:admin_user, username: 'test', password: 'testtest', password_confirmation: 'testtest')
|
||||
|
||||
|
@ -19,29 +48,54 @@ namespace :dev do
|
|||
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)
|
||||
account = create(:account, registrar: registrar, balance: 1_000_000)
|
||||
api_user = create(:api_user, username: 'test', password: 'testtest', registrar: registrar)
|
||||
|
||||
epp_session = build(:epp_session, registrar: registrar)
|
||||
epp_session[:api_user_id] = api_user.id
|
||||
epp_session.registrar_id = registrar.id
|
||||
epp_session.save!
|
||||
|
||||
domain_counter = 1.step
|
||||
|
||||
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)
|
||||
price = create(:price,
|
||||
price: Money.from_amount(duration.to_i * 10),
|
||||
valid_from: Time.zone.now - rand(1).months,
|
||||
valid_to: Time.zone.now + rand(1).months,
|
||||
duration: duration,
|
||||
operation_category: operation_category,
|
||||
zone: zone)
|
||||
|
||||
next if operation_category == 'renew'
|
||||
|
||||
(rand(3) + 1).times do
|
||||
create_domain(name: "test#{domain_counter.next}.test",
|
||||
registrar: registrar,
|
||||
registrant: registrant,
|
||||
account: account,
|
||||
price: price,
|
||||
reg_time: 1.month.ago)
|
||||
end
|
||||
|
||||
(rand(3) + 1).times do
|
||||
create_domain(name: "test#{domain_counter.next}.test",
|
||||
registrar: registrar,
|
||||
registrant: registrant,
|
||||
account: account,
|
||||
price: price,
|
||||
reg_time: Time.zone.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
create_domain(name: 'test.test',
|
||||
registrar: registrar,
|
||||
registrant: registrant,
|
||||
account: account,
|
||||
price: Billing::Price.first,
|
||||
reg_time: Time.zone.now)
|
||||
end
|
||||
|
||||
def generate_random_data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue