Commit b0c41ba16c5b53c67c862fc5e107ee631e7e034a
1 parent
2c109fdf
Exists in
master
and in
22 other branches
rails3: fix sample data scripts
Showing
12 changed files
with
34 additions
and
32 deletions
Show diff stats
app/models/certifier.rb
app/models/organization.rb
1 | # Represents any organization of the system | 1 | # Represents any organization of the system |
2 | class Organization < Profile | 2 | class Organization < Profile |
3 | 3 | ||
4 | - attr_accessible :moderated_articles | 4 | + attr_accessible :moderated_articles, :foundation_year |
5 | 5 | ||
6 | SEARCH_FILTERS += %w[ | 6 | SEARCH_FILTERS += %w[ |
7 | more_popular | 7 | more_popular |
app/models/product.rb
@@ -11,7 +11,7 @@ class Product < ActiveRecord::Base | @@ -11,7 +11,7 @@ class Product < ActiveRecord::Base | ||
11 | 11 | ||
12 | SEARCH_DISPLAYS = %w[map full] | 12 | SEARCH_DISPLAYS = %w[map full] |
13 | 13 | ||
14 | - attr_accessible :name, :product_category, :highlighted, :price | 14 | + attr_accessible :name, :product_category, :highlighted, :price, :enterprise |
15 | 15 | ||
16 | def self.default_search_display | 16 | def self.default_search_display |
17 | 'full' | 17 | 'full' |
app/models/product_category.rb
@@ -3,7 +3,7 @@ class ProductCategory < Category | @@ -3,7 +3,7 @@ class ProductCategory < Category | ||
3 | has_many :products | 3 | has_many :products |
4 | has_many :inputs | 4 | has_many :inputs |
5 | 5 | ||
6 | - attr_accessible :name, :parent | 6 | + attr_accessible :name, :parent, :environment |
7 | 7 | ||
8 | def all_products | 8 | def all_products |
9 | Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) }) | 9 | Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) }) |
app/models/profile.rb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | # which by default is the one returned by Environment:default. | 3 | # which by default is the one returned by Environment:default. |
4 | class Profile < ActiveRecord::Base | 4 | class Profile < ActiveRecord::Base |
5 | 5 | ||
6 | - attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id | 6 | + attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng |
7 | 7 | ||
8 | # use for internationalizable human type names in search facets | 8 | # use for internationalizable human type names in search facets |
9 | # reimplement on subclasses | 9 | # reimplement on subclasses |
app/models/qualifier.rb
app/models/unit.rb
1 | class Unit < ActiveRecord::Base | 1 | class Unit < ActiveRecord::Base |
2 | 2 | ||
3 | - attr_accessible :name, :singular, :plural | 3 | + attr_accessible :name, :singular, :plural, :environment |
4 | 4 | ||
5 | validates_presence_of :singular | 5 | validates_presence_of :singular |
6 | validates_presence_of :plural | 6 | validates_presence_of :plural |
script/sample-articles
@@ -12,15 +12,15 @@ THEMES = ['Sustainability', 'Free Software', 'Climate Change', 'Environment', 'A | @@ -12,15 +12,15 @@ THEMES = ['Sustainability', 'Free Software', 'Climate Change', 'Environment', 'A | ||
12 | print "Creating some TinyMce articles: " | 12 | print "Creating some TinyMce articles: " |
13 | for subject in SUBJECTS | 13 | for subject in SUBJECTS |
14 | rand(20).times do |i| | 14 | rand(20).times do |i| |
15 | - profile = profiles.rand | 15 | + profile = profiles.sample |
16 | article = TinyMceArticle.new( | 16 | article = TinyMceArticle.new( |
17 | :name => "%s #{subject}" % profile.name, | 17 | :name => "%s #{subject}" % profile.name, |
18 | :body => "%s #{subject}" % profile.name, | 18 | :body => "%s #{subject}" % profile.name, |
19 | - :tag_list => [TAGS.rand, TAGS.rand], | 19 | + :tag_list => [TAGS.sample, TAGS.sample], |
20 | :profile => profile | 20 | :profile => profile |
21 | ) | 21 | ) |
22 | save article do | 22 | save article do |
23 | - categories.rand.articles << article | 23 | + categories.sample.articles << article |
24 | end | 24 | end |
25 | end | 25 | end |
26 | end | 26 | end |
@@ -29,11 +29,11 @@ done | @@ -29,11 +29,11 @@ done | ||
29 | print "Creating some galleries: " | 29 | print "Creating some galleries: " |
30 | for subject in SUBJECTS | 30 | for subject in SUBJECTS |
31 | rand(20).times do |i| | 31 | rand(20).times do |i| |
32 | - profile = profiles.rand | 32 | + profile = profiles.sample |
33 | save Gallery.new( | 33 | save Gallery.new( |
34 | :name => "Gallery %s #{subject}" % profile.name, | 34 | :name => "Gallery %s #{subject}" % profile.name, |
35 | :body => "Gallery %s #{subject}" % profile.name, | 35 | :body => "Gallery %s #{subject}" % profile.name, |
36 | - :tag_list => [TAGS.rand, TAGS.rand], | 36 | + :tag_list => [TAGS.sample, TAGS.sample], |
37 | :profile => profile | 37 | :profile => profile |
38 | ) | 38 | ) |
39 | end | 39 | end |
@@ -45,14 +45,14 @@ for subject in EVENT_SUBJECTS | @@ -45,14 +45,14 @@ for subject in EVENT_SUBJECTS | ||
45 | for theme in THEMES | 45 | for theme in THEMES |
46 | event = Event.new( | 46 | event = Event.new( |
47 | :name => subject % theme, | 47 | :name => subject % theme, |
48 | - :profile => profiles.rand, | 48 | + :profile => profiles.sample, |
49 | :start_date => Date.today + (-30 + rand(60)).days, | 49 | :start_date => Date.today + (-30 + rand(60)).days, |
50 | - :tag_list => [TAGS.rand, TAGS.rand] | 50 | + :tag_list => [TAGS.sample, TAGS.sample] |
51 | ) | 51 | ) |
52 | save event do | 52 | save event do |
53 | - categories.rand.events << event | ||
54 | - categories.rand.events << event | ||
55 | - categories.rand.events << event | 53 | + categories.sample.events << event |
54 | + categories.sample.events << event | ||
55 | + categories.sample.events << event | ||
56 | end | 56 | end |
57 | end | 57 | end |
58 | end | 58 | end |
script/sample-categories
1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
2 | +# encoding: utf-8 | ||
2 | require File.dirname(__FILE__) + '/../config/environment' | 3 | require File.dirname(__FILE__) + '/../config/environment' |
3 | include Noosfero::SampleDataHelper | 4 | include Noosfero::SampleDataHelper |
4 | 5 | ||
@@ -11,7 +12,7 @@ def new_region(parent, name, color = nil) | @@ -11,7 +12,7 @@ def new_region(parent, name, color = nil) | ||
11 | end | 12 | end |
12 | 13 | ||
13 | def new_state(parent, name) | 14 | def new_state(parent, name) |
14 | - save State.new(:name => name, :parent => parent, :environment => $environment) | 15 | + save State.new(:name => name, :parent_id => parent ? parent.id : nil, :environment => $environment) |
15 | end | 16 | end |
16 | 17 | ||
17 | def new_productcategory(parent, name) | 18 | def new_productcategory(parent, name) |
script/sample-enterprises
1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
2 | +# encoding: utf-8 | ||
2 | require File.dirname(__FILE__) + '/../config/environment' | 3 | require File.dirname(__FILE__) + '/../config/environment' |
3 | include Noosfero::SampleDataHelper | 4 | include Noosfero::SampleDataHelper |
4 | 5 | ||
@@ -27,14 +28,13 @@ groups.each do |group| | @@ -27,14 +28,13 @@ groups.each do |group| | ||
27 | enterprise = Enterprise.new( | 28 | enterprise = Enterprise.new( |
28 | :name => name, | 29 | :name => name, |
29 | :identifier => name.to_slug, | 30 | :identifier => name.to_slug, |
30 | - :enabled => false, | ||
31 | :foundation_year => (1990..2008).to_a[rand(18)], | 31 | :foundation_year => (1990..2008).to_a[rand(18)], |
32 | :lat => rand_position(:lat), | 32 | :lat => rand_position(:lat), |
33 | :lng => rand_position(:lng) | 33 | :lng => rand_position(:lng) |
34 | ) | 34 | ) |
35 | save enterprise do | 35 | save enterprise do |
36 | - categories.rand.enterprises << enterprise | ||
37 | - categories.rand.enterprises << enterprise | 36 | + categories.sample.enterprises << enterprise |
37 | + categories.sample.enterprises << enterprise | ||
38 | end | 38 | end |
39 | end | 39 | end |
40 | end | 40 | end |
@@ -48,6 +48,6 @@ end | @@ -48,6 +48,6 @@ end | ||
48 | 48 | ||
49 | ze = Person['ze'] | 49 | ze = Person['ze'] |
50 | # give admin rights for 'ze' in some enterprises | 50 | # give admin rights for 'ze' in some enterprises |
51 | -$environment.enterprises.rand.add_admin(ze) | ||
52 | -$environment.enterprises.rand.add_admin(ze) | ||
53 | -$environment.enterprises.rand.add_admin(ze) | 51 | +$environment.enterprises.sample.add_admin(ze) |
52 | +$environment.enterprises.sample.add_admin(ze) | ||
53 | +$environment.enterprises.sample.add_admin(ze) |
script/sample-products
@@ -14,8 +14,8 @@ for thing in THINGS | @@ -14,8 +14,8 @@ for thing in THINGS | ||
14 | rand(10).times do |i| | 14 | rand(10).times do |i| |
15 | save Product.new( | 15 | save Product.new( |
16 | :name => name, | 16 | :name => name, |
17 | - :enterprise_id => enterprises.rand.id, :price => (i * 13.7), | ||
18 | - :product_category_id => categories.rand.id | 17 | + :enterprise => enterprises.sample, :price => (i * 13.7), |
18 | + :product_category => categories.sample | ||
19 | ) | 19 | ) |
20 | end | 20 | end |
21 | end | 21 | end |
script/sample-profiles
1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
2 | +# encoding: utf-8 | ||
2 | require File.dirname(__FILE__) + '/../config/environment' | 3 | require File.dirname(__FILE__) + '/../config/environment' |
3 | include Noosfero::SampleDataHelper | 4 | include Noosfero::SampleDataHelper |
4 | 5 | ||
@@ -62,7 +63,7 @@ for name in NAMES | @@ -62,7 +63,7 @@ for name in NAMES | ||
62 | user.person.save! | 63 | user.person.save! |
63 | if categories.present? | 64 | if categories.present? |
64 | 2.times do | 65 | 2.times do |
65 | - category = categories.rand | 66 | + category = categories.sample |
66 | category.people << user.person unless category.people.include?(user.person) | 67 | category.people << user.person unless category.people.include?(user.person) |
67 | end | 68 | end |
68 | end | 69 | end |
@@ -112,8 +113,8 @@ done | @@ -112,8 +113,8 @@ done | ||
112 | people = $environment.people | 113 | people = $environment.people |
113 | print "Creating some friendships: " | 114 | print "Creating some friendships: " |
114 | rand(people.size * 3).times do | 115 | rand(people.size * 3).times do |
115 | - from = people.rand | ||
116 | - to = people.rand | 116 | + from = people.sample |
117 | + to = people.sample | ||
117 | if from != to && !from.friends.include?(to) | 118 | if from != to && !from.friends.include?(to) |
118 | task = AddFriend.new(:requestor => to, :target => from) | 119 | task = AddFriend.new(:requestor => to, :target => from) |
119 | save task do | 120 | save task do |
@@ -142,12 +143,12 @@ for verb in VERBS | @@ -142,12 +143,12 @@ for verb in VERBS | ||
142 | save community do | 143 | save community do |
143 | communities << community | 144 | communities << community |
144 | rand(10).times do | 145 | rand(10).times do |
145 | - person = people.rand | 146 | + person = people.sample |
146 | community.add_member(person) unless community.members.include?(person) | 147 | community.add_member(person) unless community.members.include?(person) |
147 | end | 148 | end |
148 | if categories.present? | 149 | if categories.present? |
149 | 2.times do | 150 | 2.times do |
150 | - category = categories.rand | 151 | + category = categories.sample |
151 | category.communities << community unless category.communities.include?(community) | 152 | category.communities << community unless category.communities.include?(community) |
152 | end | 153 | end |
153 | end | 154 | end |
@@ -156,7 +157,7 @@ for verb in VERBS | @@ -156,7 +157,7 @@ for verb in VERBS | ||
156 | end | 157 | end |
157 | 158 | ||
158 | 5.times do | 159 | 5.times do |
159 | - community = communities.rand | 160 | + community = communities.sample |
160 | community.add_member(guest.person) unless community.members.include?(guest.person) | 161 | community.add_member(guest.person) unless community.members.include?(guest.person) |
161 | community.add_admin(guest.person) unless community.admins.include?(guest.person) | 162 | community.add_admin(guest.person) unless community.admins.include?(guest.person) |
162 | end | 163 | end |