prefer exception-raising methods in database seeds

This commit is contained in:
JuliusR 2020-10-10 19:40:37 +02:00 committed by Patrick Gansterer
parent 9a01cd67a6
commit a1bf2a36ad
2 changed files with 9 additions and 10 deletions

View file

@ -1,7 +1,7 @@
# Create nessecary data to start with a fresh installation
# Create working group with full rights
administrators = Workgroup.create(
administrators = Workgroup.create!(
:name => "Administrators",
:description => "System administrators.",
:role_admin => true,
@ -13,7 +13,7 @@ administrators = Workgroup.create(
)
# Create admin user
User.create(
User.create!(
:nick => "admin",
:first_name => "Anton",
:last_name => "Administrator",
@ -23,9 +23,9 @@ User.create(
)
# First entry for financial transaction types
financial_transaction_class = FinancialTransactionClass.create(:name => "Other")
FinancialTransactionType.create(:name => "Foodcoop", :financial_transaction_class_id => financial_transaction_class.id)
financial_transaction_class = FinancialTransactionClass.create!(:name => "Other")
FinancialTransactionType.create!(:name => "Foodcoop", :financial_transaction_class_id => financial_transaction_class.id)
# First entry for article categories
SupplierCategory.create(:name => "Other", :financial_transaction_class_id => financial_transaction_class.id)
ArticleCategory.create(:name => "Other", :description => "other, misc, unknown")
SupplierCategory.create!(:name => "Other", :financial_transaction_class_id => financial_transaction_class.id)
ArticleCategory.create!(:name => "Other", :description => "other, misc, unknown")

View file

@ -7,9 +7,9 @@ def seed_group_orders
# 20% of the order-ordergroup combinations don't order
next if rand(10) < 2
# order 3..12 times a random article
go = og.group_orders.create(order: order)
go = og.group_orders.create!(order: order)
(3+rand(10)).times do
goa = go.group_order_articles.find_or_create_by(order_article: order.order_articles.offset(rand(noas)).first)
goa = go.group_order_articles.find_or_create_by!(order_article: order.order_articles.offset(rand(noas)).first)
unit_quantity = goa.order_article.price.unit_quantity
goa.update_quantities rand([4, 2*unit_quantity+2].max), rand(unit_quantity)
end
@ -23,6 +23,5 @@ end
def seed_order(options={})
options[:article_ids] ||= (options[:supplier]||Supplier.find(options[:supplier_id])).articles.map(&:id)
options[:created_by_user_id] ||= 1
Order.create options
Order.create! options
end