diff --git a/lib/noosfero/sample_data_helper.rb b/lib/noosfero/sample_data_helper.rb index a191a27..6b93e6d 100644 --- a/lib/noosfero/sample_data_helper.rb +++ b/lib/noosfero/sample_data_helper.rb @@ -11,13 +11,13 @@ module Noosfero::SampleDataHelper def save(obj, &block) begin - if obj.save - print '.' - instance_eval &block if block - return obj - else - print 'F' - end + if obj.save + print '.' + instance_eval &block if block + return obj + else + print 'F' + end rescue print 'E' end diff --git a/script/sample-articles b/script/sample-articles index c36d828..e1212d1 100755 --- a/script/sample-articles +++ b/script/sample-articles @@ -13,14 +13,16 @@ print "Creating some TinyMce articles: " for subject in SUBJECTS rand(20).times do |i| profile = profiles.rand + name = "%s #{subject}" % profile.name + next if profile.articles.where(:slug => name.to_slug).first article = TinyMceArticle.new( - :name => "%s #{subject}" % profile.name, - :body => "%s #{subject}" % profile.name, + :name => name, + :body => name, :tag_list => [TAGS.rand, TAGS.rand], :profile => profile ) save article do - categories.rand.articles << article + article.add_category categories.rand end end end @@ -30,9 +32,11 @@ print "Creating some galleries: " for subject in SUBJECTS rand(20).times do |i| profile = profiles.rand + name = "Gallery %s #{subject}" % profile.name + next if profile.articles.where(:slug => name.to_slug).first save Gallery.new( - :name => "Gallery %s #{subject}" % profile.name, - :body => "Gallery %s #{subject}" % profile.name, + :name => name, + :body => name, :tag_list => [TAGS.rand, TAGS.rand], :profile => profile ) @@ -43,16 +47,20 @@ done print "Creating some events: " for subject in EVENT_SUBJECTS for theme in THEMES + profile = profiles.rand + name = subject % theme + next if profile.articles.where(:slug => name.to_slug).first event = Event.new( - :name => subject % theme, - :profile => profiles.rand, + :name => name, + :profile => profile, :start_date => Date.today + (-30 + rand(60)).days, :tag_list => [TAGS.rand, TAGS.rand] ) save event do - categories.rand.events << event - categories.rand.events << event - categories.rand.events << event + 3.times do + category = categories.rand + event.add_category category + end end end end diff --git a/script/sample-enterprises b/script/sample-enterprises index 4015ab3..a589a2d 100755 --- a/script/sample-enterprises +++ b/script/sample-enterprises @@ -32,9 +32,12 @@ groups.each do |group| :lat => rand_position(:lat), :lng => rand_position(:lng) ) + next if Profile[enterprise.identifier] save enterprise do - categories.rand.enterprises << enterprise - categories.rand.enterprises << enterprise + 2.times do + category = categories.rand + enterprise.add_category category + end end end end @@ -43,7 +46,6 @@ done EnterpriseActivation.find(:all, :conditions => ['created_at > ?', start_time]).each do |activation| enterprise = activation.enterprise - puts [activation.code, enterprise.name, enterprise.foundation_year].join(';') end ze = Person['ze'] diff --git a/script/sample-products b/script/sample-products index daccd9d..35f6142 100755 --- a/script/sample-products +++ b/script/sample-products @@ -12,9 +12,11 @@ for thing in THINGS for color in COLORS name = [color, thing].join(' ') rand(10).times do |i| + profile = enterprises.rand + next if profile.products.where(:name => name).first save Product.new( :name => name, - :profile_id => enterprises.rand.id, :price => (i * 13.7), + :profile_id => profile.id, :price => (i * 13.7), :product_category_id => categories.rand.id ) end diff --git a/script/sample-profiles b/script/sample-profiles index 372ba81..f0444d8 100755 --- a/script/sample-profiles +++ b/script/sample-profiles @@ -63,7 +63,7 @@ for name in NAMES if categories.present? 2.times do category = categories.rand - category.people << user.person unless category.people.include?(user.person) + user.person.add_category category unless category.people.include?(user.person) end end end @@ -148,7 +148,7 @@ for verb in VERBS if categories.present? 2.times do category = categories.rand - category.communities << community unless category.communities.include?(community) + community.add_category category unless category.communities.include?(community) end end end -- libgit2 0.21.2