prefer exception-raising methods in database seeds
This commit is contained in:
parent
9a01cd67a6
commit
a1bf2a36ad
2 changed files with 9 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
# Create nessecary data to start with a fresh installation
|
# Create nessecary data to start with a fresh installation
|
||||||
|
|
||||||
# Create working group with full rights
|
# Create working group with full rights
|
||||||
administrators = Workgroup.create(
|
administrators = Workgroup.create!(
|
||||||
:name => "Administrators",
|
:name => "Administrators",
|
||||||
:description => "System administrators.",
|
:description => "System administrators.",
|
||||||
:role_admin => true,
|
:role_admin => true,
|
||||||
|
@ -13,7 +13,7 @@ administrators = Workgroup.create(
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create admin user
|
# Create admin user
|
||||||
User.create(
|
User.create!(
|
||||||
:nick => "admin",
|
:nick => "admin",
|
||||||
:first_name => "Anton",
|
:first_name => "Anton",
|
||||||
:last_name => "Administrator",
|
:last_name => "Administrator",
|
||||||
|
@ -23,9 +23,9 @@ User.create(
|
||||||
)
|
)
|
||||||
|
|
||||||
# First entry for financial transaction types
|
# First entry for financial transaction types
|
||||||
financial_transaction_class = FinancialTransactionClass.create(:name => "Other")
|
financial_transaction_class = FinancialTransactionClass.create!(:name => "Other")
|
||||||
FinancialTransactionType.create(:name => "Foodcoop", :financial_transaction_class_id => financial_transaction_class.id)
|
FinancialTransactionType.create!(:name => "Foodcoop", :financial_transaction_class_id => financial_transaction_class.id)
|
||||||
|
|
||||||
# First entry for article categories
|
# First entry for article categories
|
||||||
SupplierCategory.create(:name => "Other", :financial_transaction_class_id => financial_transaction_class.id)
|
SupplierCategory.create!(:name => "Other", :financial_transaction_class_id => financial_transaction_class.id)
|
||||||
ArticleCategory.create(:name => "Other", :description => "other, misc, unknown")
|
ArticleCategory.create!(:name => "Other", :description => "other, misc, unknown")
|
||||||
|
|
|
@ -7,9 +7,9 @@ def seed_group_orders
|
||||||
# 20% of the order-ordergroup combinations don't order
|
# 20% of the order-ordergroup combinations don't order
|
||||||
next if rand(10) < 2
|
next if rand(10) < 2
|
||||||
# order 3..12 times a random article
|
# 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
|
(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
|
unit_quantity = goa.order_article.price.unit_quantity
|
||||||
goa.update_quantities rand([4, 2*unit_quantity+2].max), rand(unit_quantity)
|
goa.update_quantities rand([4, 2*unit_quantity+2].max), rand(unit_quantity)
|
||||||
end
|
end
|
||||||
|
@ -23,6 +23,5 @@ end
|
||||||
def seed_order(options={})
|
def seed_order(options={})
|
||||||
options[:article_ids] ||= (options[:supplier]||Supplier.find(options[:supplier_id])).articles.map(&:id)
|
options[:article_ids] ||= (options[:supplier]||Supplier.find(options[:supplier_id])).articles.map(&:id)
|
||||||
options[:created_by_user_id] ||= 1
|
options[:created_by_user_id] ||= 1
|
||||||
Order.create options
|
Order.create! options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue