Commit 27ab82a73f970d2ca21bc2ed4a56d3be5e626c23
1 parent
3f54dc4f
Exists in
staging
and in
42 other branches
Refactoring sample-data scripts
- creating helpers in Noosfero::SampleDataHelper to save some 'typing' - adding articles and profiles to categories in sample-data scripts - moving Events creation to sample-articles script - echoing 'F' or 'E' in output in case of fail or error on creating
Showing
8 changed files
with
156 additions
and
139 deletions
Show diff stats
| @@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
| 1 | +module Noosfero::SampleDataHelper | ||
| 2 | + # tourn on autoflush | ||
| 3 | + STDOUT.sync = true | ||
| 4 | + | ||
| 5 | + environment_id = ARGV.first | ||
| 6 | + $environment = unless environment_id.blank? | ||
| 7 | + Environment.find(environment_id) | ||
| 8 | + else | ||
| 9 | + Environment.default || Environment.create!(:name => 'Noosfero', :is_default => true) | ||
| 10 | + end | ||
| 11 | + | ||
| 12 | + def save(obj, &block) | ||
| 13 | + begin | ||
| 14 | + if obj.save | ||
| 15 | + print '.' | ||
| 16 | + instance_eval &block if block | ||
| 17 | + return obj | ||
| 18 | + else | ||
| 19 | + print 'F' | ||
| 20 | + end | ||
| 21 | + rescue | ||
| 22 | + print 'E' | ||
| 23 | + end | ||
| 24 | + return nil | ||
| 25 | + end | ||
| 26 | + | ||
| 27 | + def done | ||
| 28 | + puts ' done!' | ||
| 29 | + end | ||
| 30 | +end |
script/sample-articles
| 1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
| 2 | require File.dirname(__FILE__) + '/../config/environment' | 2 | require File.dirname(__FILE__) + '/../config/environment' |
| 3 | +include Noosfero::SampleDataHelper | ||
| 3 | 4 | ||
| 4 | -# tourn on autoflush | ||
| 5 | -STDOUT.sync = true | ||
| 6 | - | ||
| 7 | -profiles = Profile.all | 5 | +profiles = $environment.profiles |
| 6 | +categories = $environment.categories | ||
| 8 | SUBJECTS = ['got a new car', 'release a new version of project X', "doesn't like wales no more", "doesn't use free-software no more"] | 7 | SUBJECTS = ['got a new car', 'release a new version of project X', "doesn't like wales no more", "doesn't use free-software no more"] |
| 9 | TAGS = ['free-software', 'noosfero', 'development', 'rails', 'ruby'] | 8 | TAGS = ['free-software', 'noosfero', 'development', 'rails', 'ruby'] |
| 9 | +EVENT_SUBJECTS = ['International Conference on %s', '%s day', '%s World Congress', '%s World Forum', '%s Summit', '%s Week'] | ||
| 10 | +THEMES = ['Sustainability', 'Free Software', 'Climate Change', 'Environment', 'Agile Development', 'Solidarity Economy', 'Debian', 'Perl'] | ||
| 10 | 11 | ||
| 11 | print "Creating some TinyMce articles: " | 12 | print "Creating some TinyMce articles: " |
| 12 | for subject in SUBJECTS | 13 | for subject in SUBJECTS |
| 13 | rand(20).times do |i| | 14 | rand(20).times do |i| |
| 14 | profile = profiles.rand | 15 | profile = profiles.rand |
| 15 | - profile.articles << TinyMceArticle.new( | 16 | + article = TinyMceArticle.new( |
| 16 | :name => "%s #{subject}" % profile.name, | 17 | :name => "%s #{subject}" % profile.name, |
| 17 | :body => "%s #{subject}" % profile.name, | 18 | :body => "%s #{subject}" % profile.name, |
| 18 | - :tag_list => [TAGS.rand, TAGS.rand] | 19 | + :tag_list => [TAGS.rand, TAGS.rand], |
| 20 | + :profile => profile | ||
| 19 | ) | 21 | ) |
| 20 | - print '.' | 22 | + save article do |
| 23 | + categories.rand.articles << article | ||
| 24 | + end | ||
| 21 | end | 25 | end |
| 22 | end | 26 | end |
| 23 | -puts ' done!' | 27 | +done |
| 24 | 28 | ||
| 25 | print "Creating some galleries: " | 29 | print "Creating some galleries: " |
| 26 | for subject in SUBJECTS | 30 | for subject in SUBJECTS |
| 27 | rand(20).times do |i| | 31 | rand(20).times do |i| |
| 28 | profile = profiles.rand | 32 | profile = profiles.rand |
| 29 | - profile.articles << Gallery.new( | 33 | + save Gallery.new( |
| 30 | :name => "Gallery %s #{subject}" % profile.name, | 34 | :name => "Gallery %s #{subject}" % profile.name, |
| 31 | :body => "Gallery %s #{subject}" % profile.name, | 35 | :body => "Gallery %s #{subject}" % profile.name, |
| 36 | + :tag_list => [TAGS.rand, TAGS.rand], | ||
| 37 | + :profile => profile | ||
| 38 | + ) | ||
| 39 | + end | ||
| 40 | +end | ||
| 41 | +done | ||
| 42 | + | ||
| 43 | +print "Creating some events: " | ||
| 44 | +for subject in EVENT_SUBJECTS | ||
| 45 | + for theme in THEMES | ||
| 46 | + event = Event.new( | ||
| 47 | + :name => subject % theme, | ||
| 48 | + :profile => profiles.rand, | ||
| 49 | + :start_date => Date.today + (-30 + rand(60)).days, | ||
| 32 | :tag_list => [TAGS.rand, TAGS.rand] | 50 | :tag_list => [TAGS.rand, TAGS.rand] |
| 33 | ) | 51 | ) |
| 34 | - print '.' | 52 | + save event do |
| 53 | + categories.rand.events << event | ||
| 54 | + categories.rand.events << event | ||
| 55 | + categories.rand.events << event | ||
| 56 | + end | ||
| 35 | end | 57 | end |
| 36 | end | 58 | end |
| 37 | -puts ' done!' | 59 | +done |
script/sample-categories
| 1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
| 2 | require File.dirname(__FILE__) + '/../config/environment' | 2 | require File.dirname(__FILE__) + '/../config/environment' |
| 3 | - | ||
| 4 | -# turn on autoflush | ||
| 5 | -STDOUT.sync = true | ||
| 6 | - | ||
| 7 | -$environment_default = Environment.default | 3 | +include Noosfero::SampleDataHelper |
| 8 | 4 | ||
| 9 | def new_category(parent, name, color = nil) | 5 | def new_category(parent, name, color = nil) |
| 10 | - print '.' | ||
| 11 | - $environment_default.categories.create(:name => name, :display_color => color, :parent_id => (parent ? parent.id: nil), :display_in_menu => true) | 6 | + save $environment.categories.build(:name => name, :display_color => color, :parent_id => (parent ? parent.id: nil), :display_in_menu => true) |
| 12 | end | 7 | end |
| 13 | 8 | ||
| 14 | def new_region(parent, name, color = nil) | 9 | def new_region(parent, name, color = nil) |
| 15 | - print '.' | ||
| 16 | - $environment_default.regions.create(:name => name, :display_color => color, :parent_id => (parent ? parent.id: nil), :display_in_menu => true) | 10 | + save $environment.regions.build(:name => name, :display_color => color, :parent_id => (parent ? parent.id: nil), :display_in_menu => true) |
| 17 | end | 11 | end |
| 18 | 12 | ||
| 19 | def new_state(parent, name) | 13 | def new_state(parent, name) |
| 20 | - print '.' | ||
| 21 | - State.create(:name => name, :parent => parent, :environment => $environment_default) | 14 | + save State.new(:name => name, :parent => parent, :environment => $environment) |
| 22 | end | 15 | end |
| 23 | 16 | ||
| 24 | def new_productcategory(parent, name) | 17 | def new_productcategory(parent, name) |
| 25 | - print '.' | ||
| 26 | - ProductCategory.create(:name => name, :environment => $environment_default, :parent => parent) | ||
| 27 | -end | ||
| 28 | - | ||
| 29 | -def done | ||
| 30 | - puts ' done!' | 18 | + save ProductCategory.new(:name => name, :environment => $environment, :parent => parent) |
| 31 | end | 19 | end |
| 32 | 20 | ||
| 33 | print "Creating categories: " | 21 | print "Creating categories: " |
script/sample-data
| 1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
| 2 | require File.dirname(__FILE__) + '/../config/environment' | 2 | require File.dirname(__FILE__) + '/../config/environment' |
| 3 | +include Noosfero::SampleDataHelper | ||
| 3 | 4 | ||
| 4 | -# turn on autoflush | ||
| 5 | -STDOUT.sync = true | ||
| 6 | - | ||
| 7 | -environment_id = ARGV.first | ||
| 8 | -environment = nil | ||
| 9 | -if environment_id | ||
| 10 | - environment = Environment.find(environment_id) | ||
| 11 | -else | ||
| 12 | - environment = Environment.default || Environment.create!(:name => 'Noosfero', :is_default => true) | ||
| 13 | -end | ||
| 14 | - | ||
| 15 | -system('./script/sample-profiles') | ||
| 16 | -system('./script/sample-categories') | ||
| 17 | -system('./script/sample-enterprises') | ||
| 18 | -system('./script/sample-products') | ||
| 19 | -system('./script/sample-articles') | 5 | +id = ARGV.first || '' |
| 6 | +system('./script/sample-categories', id) | ||
| 7 | +system('./script/sample-profiles', id) | ||
| 8 | +system('./script/sample-enterprises', id) | ||
| 9 | +system('./script/sample-products', id) | ||
| 10 | +system('./script/sample-articles', id) |
script/sample-enterprises
| 1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
| 2 | require File.dirname(__FILE__) + '/../config/environment' | 2 | require File.dirname(__FILE__) + '/../config/environment' |
| 3 | +include Noosfero::SampleDataHelper | ||
| 3 | 4 | ||
| 4 | -# turn on autoflush | ||
| 5 | -STDOUT.sync = true | 5 | +categories = $environment.categories |
| 6 | 6 | ||
| 7 | def rand_position(type) | 7 | def rand_position(type) |
| 8 | range = { | 8 | range = { |
| @@ -23,8 +23,8 @@ print "Creating enterprises: " | @@ -23,8 +23,8 @@ print "Creating enterprises: " | ||
| 23 | groups.each do |group| | 23 | groups.each do |group| |
| 24 | what.each do |production| | 24 | what.each do |production| |
| 25 | places.each do |place| | 25 | places.each do |place| |
| 26 | - name = [group, production, place].join(' ') | ||
| 27 | - Enterprise.create!( | 26 | + name = [group, production, place].join(' ') + " - #{$environment.name}" |
| 27 | + enterprise = Enterprise.new( | ||
| 28 | :name => name, | 28 | :name => name, |
| 29 | :identifier => name.to_slug, | 29 | :identifier => name.to_slug, |
| 30 | :enabled => false, | 30 | :enabled => false, |
| @@ -32,11 +32,14 @@ groups.each do |group| | @@ -32,11 +32,14 @@ groups.each do |group| | ||
| 32 | :lat => rand_position(:lat), | 32 | :lat => rand_position(:lat), |
| 33 | :lng => rand_position(:lng) | 33 | :lng => rand_position(:lng) |
| 34 | ) | 34 | ) |
| 35 | - print "." | 35 | + save enterprise do |
| 36 | + categories.rand.enterprises << enterprise | ||
| 37 | + categories.rand.enterprises << enterprise | ||
| 38 | + end | ||
| 36 | end | 39 | end |
| 37 | end | 40 | end |
| 38 | end | 41 | end |
| 39 | -puts " done!" | 42 | +done |
| 40 | 43 | ||
| 41 | EnterpriseActivation.find(:all, :conditions => ['created_at > ?', start_time]).each do |activation| | 44 | EnterpriseActivation.find(:all, :conditions => ['created_at > ?', start_time]).each do |activation| |
| 42 | enterprise = activation.enterprise | 45 | enterprise = activation.enterprise |
| @@ -45,6 +48,6 @@ end | @@ -45,6 +48,6 @@ end | ||
| 45 | 48 | ||
| 46 | ze = Person['ze'] | 49 | ze = Person['ze'] |
| 47 | # give admin rights for 'ze' in some enterprises | 50 | # give admin rights for 'ze' in some enterprises |
| 48 | -Enterprise.all.rand.add_admin(ze) | ||
| 49 | -Enterprise.all.rand.add_admin(ze) | ||
| 50 | -Enterprise.all.rand.add_admin(ze) | 51 | +$environment.enterprises.rand.add_admin(ze) |
| 52 | +$environment.enterprises.rand.add_admin(ze) | ||
| 53 | +$environment.enterprises.rand.add_admin(ze) |
script/sample-products
| 1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
| 2 | require File.dirname(__FILE__) + '/../config/environment' | 2 | require File.dirname(__FILE__) + '/../config/environment' |
| 3 | +include Noosfero::SampleDataHelper | ||
| 3 | 4 | ||
| 4 | -# tourn on autoflush | ||
| 5 | -STDOUT.sync = true | ||
| 6 | - | ||
| 7 | -enterprises = Enterprise.all | ||
| 8 | -categories = ProductCategory.all | 5 | +enterprises = $environment.enterprises |
| 6 | +categories = $environment.product_categories | ||
| 9 | 7 | ||
| 10 | print "Creating products: " | 8 | print "Creating products: " |
| 11 | THINGS = %w[ Car House Bicycle Book Pen Computer Webcam ] | 9 | THINGS = %w[ Car House Bicycle Book Pen Computer Webcam ] |
| @@ -14,35 +12,29 @@ for thing in THINGS | @@ -14,35 +12,29 @@ for thing in THINGS | ||
| 14 | for color in COLORS | 12 | for color in COLORS |
| 15 | name = [color, thing].join(' ') | 13 | name = [color, thing].join(' ') |
| 16 | rand(10).times do |i| | 14 | rand(10).times do |i| |
| 17 | - Product.create( | 15 | + save Product.new( |
| 18 | :name => name, | 16 | :name => name, |
| 19 | :enterprise_id => enterprises.rand.id, :price => (i * 13.7), | 17 | :enterprise_id => enterprises.rand.id, :price => (i * 13.7), |
| 20 | :product_category_id => categories.rand.id | 18 | :product_category_id => categories.rand.id |
| 21 | ) | 19 | ) |
| 22 | - print '.' | ||
| 23 | end | 20 | end |
| 24 | end | 21 | end |
| 25 | end | 22 | end |
| 26 | -puts ' done!' | ||
| 27 | - | ||
| 28 | -environment = Environment.default | 23 | +done |
| 29 | 24 | ||
| 30 | print "Creating qualifiers and certifier: " | 25 | print "Creating qualifiers and certifier: " |
| 31 | QUALIFIERS = ['Organic', 'Free as in Freedom', 'Regional'] | 26 | QUALIFIERS = ['Organic', 'Free as in Freedom', 'Regional'] |
| 32 | CERTIFIERS = ['FBES', 'Colivre', 'Institute Paulo Freire', 'Fora do Eixo'] | 27 | CERTIFIERS = ['FBES', 'Colivre', 'Institute Paulo Freire', 'Fora do Eixo'] |
| 33 | for qualifier in QUALIFIERS | 28 | for qualifier in QUALIFIERS |
| 34 | - environment.qualifiers << Qualifier.new(:name => qualifier) | ||
| 35 | - print '.' | 29 | + save Qualifier.new(:name => qualifier, :environment => $environment) |
| 36 | end | 30 | end |
| 37 | for certifier in CERTIFIERS | 31 | for certifier in CERTIFIERS |
| 38 | - environment.certifiers << Certifier.new(:name => certifier) | ||
| 39 | - print '.' | 32 | + save Certifier.new(:name => certifier, :environment => $environment) |
| 40 | end | 33 | end |
| 41 | -puts ' done!' | 34 | +done |
| 42 | 35 | ||
| 43 | print "Creating units: " | 36 | print "Creating units: " |
| 44 | [['Litre', 'Litres'], ['Kilo', 'Kilos'], ['Meter', 'Meters']].each do |unit| | 37 | [['Litre', 'Litres'], ['Kilo', 'Kilos'], ['Meter', 'Meters']].each do |unit| |
| 45 | - Unit.create!(:singular => unit[0], :plural => unit[1], :environment => environment) | ||
| 46 | - print '.' | 38 | + save Unit.new(:singular => unit[0], :plural => unit[1], :environment => $environment) |
| 47 | end | 39 | end |
| 48 | -puts ' done!' | 40 | +done |
script/sample-profiles
| 1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
| 2 | require File.dirname(__FILE__) + '/../config/environment' | 2 | require File.dirname(__FILE__) + '/../config/environment' |
| 3 | +include Noosfero::SampleDataHelper | ||
| 3 | 4 | ||
| 4 | -# turn on autoflush | ||
| 5 | -STDOUT.sync = true | ||
| 6 | - | ||
| 7 | -environment = Environment.default | 5 | +categories = $environment.categories |
| 8 | 6 | ||
| 9 | places = [ | 7 | places = [ |
| 10 | { :country=>'BR', :city=>'Salvador', | 8 | { :country=>'BR', :city=>'Salvador', |
| @@ -42,37 +40,63 @@ print "Creating users: " | @@ -42,37 +40,63 @@ print "Creating users: " | ||
| 42 | for name in NAMES | 40 | for name in NAMES |
| 43 | for surname in SURNAMES | 41 | for surname in SURNAMES |
| 44 | full_name = [name, surname].join(' ') | 42 | full_name = [name, surname].join(' ') |
| 45 | - user = User.create!({ | 43 | + user = User.new({ |
| 46 | :login => full_name.to_slug, | 44 | :login => full_name.to_slug, |
| 47 | :email => full_name.to_slug + '@localhost.localdomain', | 45 | :email => full_name.to_slug + '@localhost.localdomain', |
| 48 | :password => 'test', | 46 | :password => 'test', |
| 49 | :password_confirmation => 'test', | 47 | :password_confirmation => 'test', |
| 50 | - :environment => environment, | 48 | + :environment => $environment, |
| 51 | }) | 49 | }) |
| 52 | - user.person.name = full_name | ||
| 53 | - place = places[rand(places.length)] | ||
| 54 | - user.person.data[:country] = place[:country] | ||
| 55 | - user.person.city = place[:city] | ||
| 56 | - user.person.lat = place[:lat] + (rand/100)-0.005 | ||
| 57 | - user.person.lng = place[:lng] + (rand/100)-0.005 | ||
| 58 | - user.person.save! | ||
| 59 | - people << user.person | ||
| 60 | - | ||
| 61 | - print '.' | 50 | + save user do |
| 51 | + user.person.name = full_name | ||
| 52 | + place = places[rand(places.length)] | ||
| 53 | + user.person.data[:country] = place[:country] | ||
| 54 | + user.person.city = place[:city] | ||
| 55 | + user.person.lat = place[:lat] + (rand/100)-0.005 | ||
| 56 | + user.person.lng = place[:lng] + (rand/100)-0.005 | ||
| 57 | + user.person.save! | ||
| 58 | + categories.rand.people << user.person | ||
| 59 | + categories.rand.people << user.person | ||
| 60 | + end | ||
| 62 | end | 61 | end |
| 63 | end | 62 | end |
| 64 | -puts ' done!' | 63 | +ze = User.new({ |
| 64 | + :login => "ze", | ||
| 65 | + :email => 'root@localhost.localdomain', | ||
| 66 | + :password => 'test', | ||
| 67 | + :password_confirmation => 'test', | ||
| 68 | + :environment => $environment, | ||
| 69 | +}) | ||
| 70 | +save ze do | ||
| 71 | + $environment.add_admin(ze.person) | ||
| 72 | +end | ||
| 73 | + | ||
| 74 | +admin = User.new({ | ||
| 75 | + :login => "adminuser", | ||
| 76 | + :email => 'adminuser@localhost.localdomain', | ||
| 77 | + :password => 'admin', | ||
| 78 | + :password_confirmation => 'admin', | ||
| 79 | + :environment => $environment, | ||
| 80 | +}) | ||
| 81 | +save admin do | ||
| 82 | + $environment.add_admin(admin.person) | ||
| 83 | +end | ||
| 84 | +done | ||
| 65 | 85 | ||
| 86 | +people = $environment.people | ||
| 66 | print "Creating some friendships: " | 87 | print "Creating some friendships: " |
| 67 | rand(people.size * 3).times do | 88 | rand(people.size * 3).times do |
| 68 | from = people.rand | 89 | from = people.rand |
| 69 | to = people.rand | 90 | to = people.rand |
| 70 | if from != to && !from.friends.include?(to) | 91 | if from != to && !from.friends.include?(to) |
| 71 | - AddFriend.create!(:requestor => to, :target => from).finish | 92 | + task = AddFriend.new(:requestor => to, :target => from) |
| 93 | + save task do | ||
| 94 | + task.finish | ||
| 95 | + end | ||
| 72 | end | 96 | end |
| 73 | print '.' | 97 | print '.' |
| 74 | end | 98 | end |
| 75 | -puts ' done!' | 99 | +done |
| 76 | 100 | ||
| 77 | 101 | ||
| 78 | communities = [] | 102 | communities = [] |
| @@ -82,41 +106,15 @@ print "Creating communities: " | @@ -82,41 +106,15 @@ print "Creating communities: " | ||
| 82 | for verb in VERBS | 106 | for verb in VERBS |
| 83 | for stuff in STUFF | 107 | for stuff in STUFF |
| 84 | name = [verb, stuff].join(' ') | 108 | name = [verb, stuff].join(' ') |
| 85 | - community = Community.create!(:name => name, :environment => environment) | ||
| 86 | - communities << community | ||
| 87 | - rand(10).times do | ||
| 88 | - community.add_member(people.rand) | 109 | + community = Community.new(:name => name, :environment => $environment) |
| 110 | + save community do | ||
| 111 | + communities << community | ||
| 112 | + rand(10).times do | ||
| 113 | + community.add_member(people.rand) | ||
| 114 | + end | ||
| 115 | + categories.rand.communities << community | ||
| 116 | + categories.rand.communities << community | ||
| 89 | end | 117 | end |
| 90 | - print '.' | ||
| 91 | - end | ||
| 92 | -end | ||
| 93 | -puts ' done!' | ||
| 94 | - | ||
| 95 | -EVENTS = ['International Conference on %s', '%s day', '%s World Congress', '%s World Forum', '%s Summit', '%s Week'] | ||
| 96 | -THEMES = ['Sustainability', 'Free Software', 'Climate Change', 'Environment', 'Agile Development', 'Solidarity Economy'] | ||
| 97 | -print "Creating some events: " | ||
| 98 | -for event in EVENTS | ||
| 99 | - for theme in THEMES | ||
| 100 | - Event.create!(:name => event % theme, :profile => communities.rand, :start_date => Date.today + (-30 + rand(60)).days) | ||
| 101 | - print '.' | ||
| 102 | end | 118 | end |
| 103 | end | 119 | end |
| 104 | -puts ' done!' | ||
| 105 | - | ||
| 106 | -ze = User.create!({ | ||
| 107 | - :login => "ze", | ||
| 108 | - :email => 'root@localhost.localdomain', | ||
| 109 | - :password => 'test', | ||
| 110 | - :password_confirmation => 'test', | ||
| 111 | - :environment => environment, | ||
| 112 | -}).person | ||
| 113 | -environment.add_admin(ze) | ||
| 114 | - | ||
| 115 | -admin = User.create!({ | ||
| 116 | - :login => "adminuser", | ||
| 117 | - :email => 'adminuser@localhost.localdomain', | ||
| 118 | - :password => 'admin', | ||
| 119 | - :password_confirmation => 'admin', | ||
| 120 | - :environment => environment, | ||
| 121 | -}).person | ||
| 122 | -environment.add_admin(admin) | 120 | +done |
script/sample-qualifiers
| 1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
| 2 | require File.dirname(__FILE__) + '/../config/environment' | 2 | require File.dirname(__FILE__) + '/../config/environment' |
| 3 | - | ||
| 4 | -# turn on autoflush | ||
| 5 | -STDOUT.sync = true | 3 | +include Noosfero::SampleDataHelper |
| 6 | 4 | ||
| 7 | QUALIFIERS = ['Organic', 'Ecological', 'Biodynamic farming', 'Sustainable', 'Agroecological', 'Craft', 'Free as in freedom'] | 5 | QUALIFIERS = ['Organic', 'Ecological', 'Biodynamic farming', 'Sustainable', 'Agroecological', 'Craft', 'Free as in freedom'] |
| 8 | CERTIFIERS = ['FBES', 'Colivre', 'Circuito Fora do Eixo', 'Instituto Paulo Freire', 'Free Software Foundation', 'Linux Foundation', 'GNU', 'Perl Foundation'] | 6 | CERTIFIERS = ['FBES', 'Colivre', 'Circuito Fora do Eixo', 'Instituto Paulo Freire', 'Free Software Foundation', 'Linux Foundation', 'GNU', 'Perl Foundation'] |
| 9 | 7 | ||
| 10 | -environment = Environment.default | ||
| 11 | - | ||
| 12 | printf "Creating qualifiers and certifiers: " | 8 | printf "Creating qualifiers and certifiers: " |
| 13 | CERTIFIERS.each do |certifier_name| | 9 | CERTIFIERS.each do |certifier_name| |
| 14 | - Certifier.create!(:name => certifier_name, :environment => environment) | ||
| 15 | - print '.' | 10 | + save Certifier.new(:name => certifier_name, :environment => $environment) |
| 16 | end | 11 | end |
| 17 | 12 | ||
| 18 | QUALIFIERS.each do |qualifier_name| | 13 | QUALIFIERS.each do |qualifier_name| |
| 19 | - Qualifier.create!(:name => qualifier_name, :environment => environment) | ||
| 20 | - print '.' | 14 | + save Qualifier.new(:name => qualifier_name, :environment => $environment) |
| 21 | end | 15 | end |
| 22 | 16 | ||
| 23 | -Qualifier.all.each do |qualifier| | ||
| 24 | - Certifier.all.sort_by{rand}.slice(0, CERTIFIERS.size / 2).each do |certifier| | ||
| 25 | - QualifierCertifier.create!(:qualifier => qualifier, :certifier => certifier) | ||
| 26 | - print '.' | 17 | +$environment.qualifiers.each do |qualifier| |
| 18 | + $environment.certifiers.sort_by{rand}.slice(0, CERTIFIERS.size / 2).each do |certifier| | ||
| 19 | + save QualifierCertifier.new(:qualifier => qualifier, :certifier => certifier) | ||
| 27 | end | 20 | end |
| 28 | end | 21 | end |
| 29 | -puts " done!" | 22 | +done |