-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added verbose (failure) logging to the seeding process
- Loading branch information
1 parent
b029f49
commit c995266
Showing
7 changed files
with
147 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
require Rails.root.join('db', 'seeds', 'members.rb') | ||
require Rails.root.join('db', 'seeds', 'activities.rb') | ||
|
||
puts '-- member transaction creation' | ||
puts '-- Creating member transactions' | ||
|
||
Member.all.sample(30).each do |member| | ||
|
||
15.times do | ||
transactiontype = Faker::Number.within(range: 0..1) | ||
# either ideal or pin (see app/models/payment.rb) | ||
paymenttype = Faker::Number.within(range: 0.0..1.0) < 0.5 ? 0 : 3 | ||
status = Faker::Number.within(range:0..2) | ||
if transactiontype == 1 && status == 0 | ||
participants = Participant.where(member:member).where.not(activity:[nil,1]).select{|p| p.currency != nil}.sample(Faker::Number.within(range:1..6)) | ||
participants.map {|p|p.update(paid:true)} | ||
transaction_id = participants.map{|p| p.activity.id} | ||
amount = 0 | ||
participants.map{ |p| amount += p.currency} | ||
status = 2 | ||
else | ||
transaction_id = [1] | ||
status = 0 | ||
end | ||
description = transactiontype == 0 ? "Mongoose Opwaardering" : "Activiteiten - #{transaction_id}" | ||
|
||
@payment =Payment.create(member: member, | ||
transaction_type: transactiontype, | ||
payment_type: paymenttype , | ||
transaction_id: transaction_id, | ||
description: description, | ||
amount: Faker::Number.within(range: 1.0..10.0), | ||
status: status, | ||
trxid: Digest::MD5.hexdigest(description + Time.now.to_f.to_s), | ||
created_at: Faker::Date.between(from: 1.weeks.ago, to: Date.today), | ||
message: 'seeding', | ||
redirect_uri: ENV['KOALA_DOMAIN'] | ||
status = Faker::Number.within(range: 0..2) | ||
payment_type = Faker::Number.within(range: 0.0..1.0) < 0.5 ? 0 : 3 | ||
|
||
participants = Participant.where(member: member).where.not(activity: [nil, 1]).select { |p| p.currency != nil }.sample(Faker::Number.within(range: 1..6)) | ||
|
||
participants.map { |p| p.update(paid: true) } | ||
|
||
amount = 0 | ||
participants.map { |p| amount += p.currency } | ||
|
||
transaction_id = participants.map{|p| p.activity.id} | ||
|
||
description = "Activiteiten - #{transaction_id}" | ||
|
||
payment = Payment.create(member: member, | ||
transaction_type: 1, | ||
payment_type: payment_type, | ||
transaction_id: transaction_id, | ||
description: description, | ||
amount: amount, | ||
status: status, | ||
trxid: Digest::MD5.hexdigest(description + Time.now.to_f.to_s), | ||
created_at: Faker::Date.between(from: 1.weeks.ago, to: Date.today), | ||
message: 'seeding', | ||
redirect_uri: ENV['KOALA_DOMAIN'] | ||
) | ||
|
||
puts " [#{ payment.valid? ? ' Ok ' : 'Fail' }] #{['Failed', 'In progress', 'Successful'][status]} transaction by #{ payment.member.first_name } #{ payment.member.last_name } of #{ payment.amount } for #{ payment.transaction_id } using #{ payment_type == 0 ? "ideal" : "pin" }" | ||
payment.errors.objects.each do |error| | ||
puts " > #{error.full_message}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,34 +2,46 @@ | |
|
||
# Creating login accounts | ||
puts '-- Creating users' | ||
Admin.create( | ||
email: '[email protected]', | ||
|
||
dev = Admin.create( | ||
email: '[email protected]', | ||
password: 'sticky123' | ||
) | ||
puts ' -> [email protected] (admin)' | ||
|
||
Admin.create( | ||
email: '[email protected]', | ||
password: 'sticky123', | ||
puts " [#{ dev.valid? ? ' Ok ' : 'Fail' }] [email protected] (admin)" | ||
dev.errors.objects.each do |error| | ||
puts " > #{error.full_message}" | ||
end | ||
|
||
martijn = Admin.create( | ||
email: '[email protected]', | ||
password: 'sticky123', | ||
|
||
first_name: 'Martijn', | ||
last_name: 'Casteel', | ||
signature: 'Martijn' | ||
last_name: 'Casteel', | ||
signature: 'Martijn' | ||
) | ||
puts ' -> [email protected] (admin)' | ||
|
||
puts " [#{ martijn.valid? ? ' Ok ' : 'Fail' }] [email protected] (admin)" | ||
martijn.errors.objects.each do |error| | ||
puts " > #{error.full_message}" | ||
end | ||
|
||
# create actual members, but give the first member [email protected] | ||
member = Member.joins(:educations).where(educations: { status: 0 }).first | ||
member.update(email: '[email protected]') | ||
|
||
user = User.new( | ||
email: member.email, | ||
password: 'sticky123', | ||
email: member.email, | ||
password: 'sticky123', | ||
credentials: member, | ||
language: Faker::Number.within(range: 0..1) | ||
language: Faker::Number.within(range: 0..1) | ||
) | ||
|
||
user.skip_confirmation! | ||
user.save! | ||
|
||
puts " -> #{ user.email } (member)" | ||
puts " [#{ user.valid? ? ' Ok ' : 'Fail' }] #{ user.email } (member)" | ||
user.errors.objects.each do |error| | ||
puts " > #{error.full_message}" | ||
end |