Class: Seeder

Inherits:
Object
  • Object
show all
Defined in:
lib/seeder.rb

Constant Summary collapse

@@engines =
[]
@@system_receipt_templates_path =
"#{seeds_root}/receipt_templates/system/*.txt"
@@providers_receipt_template_path =
"#{seeds_root}/receipt_templates/payment.txt"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSeeder

Returns a new instance of Seeder.



20
21
22
23
24
25
26
# File 'lib/seeder.rb', line 20

def initialize
  seed_roles

  @user      = User.make! :root => true, :email => '[email protected]', :password => 'password'
  @agent     = Agent.make!
  @terminals = []
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



14
15
16
# File 'lib/seeder.rb', line 14

def agent
  @agent
end

#dummyObject

Returns the value of attribute dummy.



14
15
16
# File 'lib/seeder.rb', line 14

def dummy
  @dummy
end

#terminalsObject

Returns the value of attribute terminals.



14
15
16
# File 'lib/seeder.rb', line 14

def terminals
  @terminals
end

#userObject

Returns the value of attribute user.



14
15
16
# File 'lib/seeder.rb', line 14

def user
  @user
end

Instance Method Details

#seed_enginesObject



33
34
35
36
37
# File 'lib/seeder.rb', line 33

def seed_engines
  self.class.engines.each do |e|
    e.const_get('Engine').load_seed
  end
end

#seed_gatewaysObject



45
46
47
# File 'lib/seeder.rb', line 45

def seed_gateways
  @dummy = Gateway.create! :title => 'Заглушка', :keyword => 'dummy', :payzilla => 'dummy'
end

#seed_receipt_templatesObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/seeder.rb', line 92

def seed_receipt_templates
  Dir[self.class.system_receipt_templates_path].each do |rt|
    SystemReceiptTemplate.create! :keyword => File.basename(rt).gsub('.txt', ''), :template => File.read(rt)
  end

  ProviderReceiptTemplate.create!(
    :system   => true,
    :template => File.read(providers_receipt_template_path)
  )
end

#seed_rolesObject



39
40
41
42
43
# File 'lib/seeder.rb', line 39

def seed_roles
  Role.entries.each do |x|
    Role.create! :keyword => x
  end
end

#seed_terminal(keyword) ⇒ Object



49
50
51
# File 'lib/seeder.rb', line 49

def seed_terminal(keyword)
  Terminal.make!(:keyword => keyword, :agent => @agent).ping! TerminalPing.make
end

#seed_terminal_profilesObject



59
60
61
# File 'lib/seeder.rb', line 59

def seed_terminal_profiles
  TerminalProfile.create! :keyword => 'default', :title => 'Основные'
end

#seed_test_paymentsObject



86
87
88
89
90
# File 'lib/seeder.rb', line 86

def seed_test_payments
  100.times do |i|
    Payment.make! :agent => @agent, :terminal => @terminals.sample, :provider_gateway => @dummy.provider_gateways.sample, :gateway_error => [nil, -1].sample
  end
end

#seed_test_providersObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/seeder.rb', line 63

def seed_test_providers
  Provider.make! :keyword => 'first'
  Provider.make! :keyword => 'second'
  Provider.make! :keyword => 'third'
  Provider.make! :keyword => 'fourth'

  Provider.all.each do |p|
    ProviderGateway.create! :provider => p, :gateway => @dummy, :priority => 1

    ([1,5].sample).times do
      ProviderField.make! :provider => p
    end
  end
end

#seed_test_terminal_profile_promotionsObject



78
79
80
81
82
83
84
# File 'lib/seeder.rb', line 78

def seed_test_terminal_profile_promotions
  profile = TerminalProfile.first

  Provider.all.each_with_index do |p, i|
    TerminalProfilePromotion.create! :terminal_profile => profile, :provider => p
  end
end

#seed_test_terminalsObject



53
54
55
56
57
# File 'lib/seeder.rb', line 53

def seed_test_terminals
  3000.times do |i|
    @terminals << Terminal.make!(:agent => @agent)
  end
end

#truncate_databaseObject



28
29
30
31
# File 'lib/seeder.rb', line 28

def truncate_database
  DatabaseCleaner.strategy = :truncation
  DatabaseCleaner.clean
end