Commit 5cacb9831f5580692d361431b50cfa9d905f2b04
Committed by
Rodrigo Souto
1 parent
ac139797
Exists in
master
and in
22 other branches
script-sample-data: fixed script sample-data errors on some records
AI3091
Showing
5 changed files
with
35 additions
and
23 deletions
Show diff stats
lib/noosfero/sample_data_helper.rb
| ... | ... | @@ -11,13 +11,13 @@ module Noosfero::SampleDataHelper |
| 11 | 11 | |
| 12 | 12 | def save(obj, &block) |
| 13 | 13 | begin |
| 14 | - if obj.save | |
| 15 | - print '.' | |
| 16 | - instance_eval &block if block | |
| 17 | - return obj | |
| 18 | - else | |
| 19 | - print 'F' | |
| 20 | - end | |
| 14 | + if obj.save | |
| 15 | + print '.' | |
| 16 | + instance_eval &block if block | |
| 17 | + return obj | |
| 18 | + else | |
| 19 | + print 'F' | |
| 20 | + end | |
| 21 | 21 | rescue |
| 22 | 22 | print 'E' |
| 23 | 23 | end | ... | ... |
script/sample-articles
| ... | ... | @@ -13,14 +13,16 @@ print "Creating some TinyMce articles: " |
| 13 | 13 | for subject in SUBJECTS |
| 14 | 14 | rand(20).times do |i| |
| 15 | 15 | profile = profiles.rand |
| 16 | + name = "%s #{subject}" % profile.name | |
| 17 | + next if profile.articles.where(:slug => name.to_slug).first | |
| 16 | 18 | article = TinyMceArticle.new( |
| 17 | - :name => "%s #{subject}" % profile.name, | |
| 18 | - :body => "%s #{subject}" % profile.name, | |
| 19 | + :name => name, | |
| 20 | + :body => name, | |
| 19 | 21 | :tag_list => [TAGS.rand, TAGS.rand], |
| 20 | 22 | :profile => profile |
| 21 | 23 | ) |
| 22 | 24 | save article do |
| 23 | - categories.rand.articles << article | |
| 25 | + article.add_category categories.rand | |
| 24 | 26 | end |
| 25 | 27 | end |
| 26 | 28 | end |
| ... | ... | @@ -30,9 +32,11 @@ print "Creating some galleries: " |
| 30 | 32 | for subject in SUBJECTS |
| 31 | 33 | rand(20).times do |i| |
| 32 | 34 | profile = profiles.rand |
| 35 | + name = "Gallery %s #{subject}" % profile.name | |
| 36 | + next if profile.articles.where(:slug => name.to_slug).first | |
| 33 | 37 | save Gallery.new( |
| 34 | - :name => "Gallery %s #{subject}" % profile.name, | |
| 35 | - :body => "Gallery %s #{subject}" % profile.name, | |
| 38 | + :name => name, | |
| 39 | + :body => name, | |
| 36 | 40 | :tag_list => [TAGS.rand, TAGS.rand], |
| 37 | 41 | :profile => profile |
| 38 | 42 | ) |
| ... | ... | @@ -43,16 +47,20 @@ done |
| 43 | 47 | print "Creating some events: " |
| 44 | 48 | for subject in EVENT_SUBJECTS |
| 45 | 49 | for theme in THEMES |
| 50 | + profile = profiles.rand | |
| 51 | + name = subject % theme | |
| 52 | + next if profile.articles.where(:slug => name.to_slug).first | |
| 46 | 53 | event = Event.new( |
| 47 | - :name => subject % theme, | |
| 48 | - :profile => profiles.rand, | |
| 54 | + :name => name, | |
| 55 | + :profile => profile, | |
| 49 | 56 | :start_date => Date.today + (-30 + rand(60)).days, |
| 50 | 57 | :tag_list => [TAGS.rand, TAGS.rand] |
| 51 | 58 | ) |
| 52 | 59 | save event do |
| 53 | - categories.rand.events << event | |
| 54 | - categories.rand.events << event | |
| 55 | - categories.rand.events << event | |
| 60 | + 3.times do | |
| 61 | + category = categories.rand | |
| 62 | + event.add_category category | |
| 63 | + end | |
| 56 | 64 | end |
| 57 | 65 | end |
| 58 | 66 | end | ... | ... |
script/sample-enterprises
| ... | ... | @@ -32,9 +32,12 @@ groups.each do |group| |
| 32 | 32 | :lat => rand_position(:lat), |
| 33 | 33 | :lng => rand_position(:lng) |
| 34 | 34 | ) |
| 35 | + next if Profile[enterprise.identifier] | |
| 35 | 36 | save enterprise do |
| 36 | - categories.rand.enterprises << enterprise | |
| 37 | - categories.rand.enterprises << enterprise | |
| 37 | + 2.times do | |
| 38 | + category = categories.rand | |
| 39 | + enterprise.add_category category | |
| 40 | + end | |
| 38 | 41 | end |
| 39 | 42 | end |
| 40 | 43 | end |
| ... | ... | @@ -43,7 +46,6 @@ done |
| 43 | 46 | |
| 44 | 47 | EnterpriseActivation.find(:all, :conditions => ['created_at > ?', start_time]).each do |activation| |
| 45 | 48 | enterprise = activation.enterprise |
| 46 | - puts [activation.code, enterprise.name, enterprise.foundation_year].join(';') | |
| 47 | 49 | end |
| 48 | 50 | |
| 49 | 51 | ze = Person['ze'] | ... | ... |
script/sample-products
| ... | ... | @@ -12,9 +12,11 @@ for thing in THINGS |
| 12 | 12 | for color in COLORS |
| 13 | 13 | name = [color, thing].join(' ') |
| 14 | 14 | rand(10).times do |i| |
| 15 | + profile = enterprises.rand | |
| 16 | + next if profile.products.where(:name => name).first | |
| 15 | 17 | save Product.new( |
| 16 | 18 | :name => name, |
| 17 | - :profile_id => enterprises.rand.id, :price => (i * 13.7), | |
| 19 | + :profile_id => profile.id, :price => (i * 13.7), | |
| 18 | 20 | :product_category_id => categories.rand.id |
| 19 | 21 | ) |
| 20 | 22 | end | ... | ... |
script/sample-profiles
| ... | ... | @@ -63,7 +63,7 @@ for name in NAMES |
| 63 | 63 | if categories.present? |
| 64 | 64 | 2.times do |
| 65 | 65 | category = categories.rand |
| 66 | - category.people << user.person unless category.people.include?(user.person) | |
| 66 | + user.person.add_category category unless category.people.include?(user.person) | |
| 67 | 67 | end |
| 68 | 68 | end |
| 69 | 69 | end |
| ... | ... | @@ -148,7 +148,7 @@ for verb in VERBS |
| 148 | 148 | if categories.present? |
| 149 | 149 | 2.times do |
| 150 | 150 | category = categories.rand |
| 151 | - category.communities << community unless category.communities.include?(community) | |
| 151 | + community.add_category category unless category.communities.include?(community) | |
| 152 | 152 | end |
| 153 | 153 | end |
| 154 | 154 | end | ... | ... |