Bring seeds.rb from ofn-install

This commit is contained in:
Pau Perez
2018-03-07 10:28:34 +01:00
parent 23d36e3898
commit 9849f76c1c

View File

@@ -1,28 +1,29 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
require 'yaml'
require 'csv'
# -- Spree
unless Spree::Country.find_by_name 'Australia'
unless Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE'])
puts "[db:seed] Seeding Spree"
Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
end
# -- States
unless Spree::State.find_by_name 'Victoria'
country = Spree::Country.find_by_name('Australia')
puts "[db:seed] Seeding states"
country = Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE'])
puts "Country is #{country.to_s}"
puts "[db:seed] loading states yaml"
states = YAML::load_file "db/default/spree/states.yml"
puts "States: #{states.to_s}"
[
['ACT', 'ACT'],
['New South Wales', 'NSW'],
['Northern Territory', 'NT'],
['Queensland', 'QLD'],
['South Australia', 'SA'],
['Tasmania', 'Tas'],
['Victoria', 'Vic'],
['Western Australia', 'WA']
].each do |state|
Spree::State.create!({"name"=>state[0], "abbr"=>state[1], :country=>country}, :without_protection => true)
# -- Seeding States
puts "[db:seed] Seeding states for " + country.name
states.each do |state|
puts "State: " + state.to_s
unless Spree::State.find_by_name(state['name'])
Spree::State.create!({"name"=>state['name'], "abbr"=>state['abbr'], :country=>country}, without_protection: true)
end
puts "set id"
end