Commit 152a99656ef0039daf9c471b203e925168506a58
Exists in
master
and in
27 other branches
Merge branch 'script-sample-data' of https://gitlab.com/juniorsilva1001/noosfero
Conflicts: script/sample-articles script/sample-enterprises script/sample-products script/sample-profiles
Showing
5 changed files
with
38 additions
and
25 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.sample |
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 | - :tag_list => [TAGS.sample, TAGS.sample], | |
19 | + :name => name, | |
20 | + :body => name, | |
21 | + :tag_list => [TAGS.rand, TAGS.rand], | |
20 | 22 | :profile => profile |
21 | 23 | ) |
22 | 24 | save article do |
23 | - categories.sample.articles << article | |
25 | + article.add_category categories.rand | |
24 | 26 | end |
25 | 27 | end |
26 | 28 | end |
... | ... | @@ -30,10 +32,12 @@ print "Creating some galleries: " |
30 | 32 | for subject in SUBJECTS |
31 | 33 | rand(20).times do |i| |
32 | 34 | profile = profiles.sample |
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, | |
36 | - :tag_list => [TAGS.sample, TAGS.sample], | |
38 | + :name => name, | |
39 | + :body => name, | |
40 | + :tag_list => [TAGS.rand, TAGS.rand], | |
37 | 41 | :profile => profile |
38 | 42 | ) |
39 | 43 | end |
... | ... | @@ -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.sample | |
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.sample, | |
54 | + :name => name, | |
55 | + :profile => profile, | |
49 | 56 | :start_date => Date.today + (-30 + rand(60)).days, |
50 | 57 | :tag_list => [TAGS.sample, TAGS.sample] |
51 | 58 | ) |
52 | 59 | save event do |
53 | - categories.sample.events << event | |
54 | - categories.sample.events << event | |
55 | - categories.sample.events << event | |
60 | + 3.times do | |
61 | + category = categories.sample | |
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.sample.enterprises << enterprise | |
37 | - categories.sample.enterprises << enterprise | |
37 | + 2.times do | |
38 | + category = categories.sample | |
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,12 @@ 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 => enterprises.sample, :price => (i * 13.7), | |
19 | + :profile_id => profile.id, :price => (i * 13.7), | |
20 | + :product_category_id => categories.sample.id | |
18 | 21 | ) |
19 | 22 | end |
20 | 23 | end | ... | ... |
script/sample-profiles
... | ... | @@ -64,7 +64,7 @@ for name in NAMES |
64 | 64 | if categories.present? |
65 | 65 | 2.times do |
66 | 66 | category = categories.sample |
67 | - category.people << user.person unless category.people.include?(user.person) | |
67 | + user.person.add_category category unless category.people.include?(user.person) | |
68 | 68 | end |
69 | 69 | end |
70 | 70 | end |
... | ... | @@ -149,7 +149,7 @@ for verb in VERBS |
149 | 149 | if categories.present? |
150 | 150 | 2.times do |
151 | 151 | category = categories.sample |
152 | - category.communities << community unless category.communities.include?(community) | |
152 | + community.add_category category unless category.communities.include?(community) | |
153 | 153 | end |
154 | 154 | end |
155 | 155 | end | ... | ... |