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
app/models/product.rb
| ... | ... | @@ -11,7 +11,7 @@ class Product < ActiveRecord::Base |
| 11 | 11 | |
| 12 | 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 | 16 | def self.default_search_display |
| 17 | 17 | 'full' | ... | ... |
app/models/product_category.rb
| ... | ... | @@ -3,7 +3,7 @@ class ProductCategory < Category |
| 3 | 3 | has_many :products |
| 4 | 4 | has_many :inputs |
| 5 | 5 | |
| 6 | - attr_accessible :name, :parent | |
| 6 | + attr_accessible :name, :parent, :environment | |
| 7 | 7 | |
| 8 | 8 | def all_products |
| 9 | 9 | Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) }) | ... | ... |
app/models/profile.rb
| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | # which by default is the one returned by Environment:default. |
| 4 | 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 | 8 | # use for internationalizable human type names in search facets |
| 9 | 9 | # reimplement on subclasses | ... | ... |
app/models/qualifier.rb
app/models/unit.rb
script/sample-articles
| ... | ... | @@ -12,15 +12,15 @@ THEMES = ['Sustainability', 'Free Software', 'Climate Change', 'Environment', 'A |
| 12 | 12 | print "Creating some TinyMce articles: " |
| 13 | 13 | for subject in SUBJECTS |
| 14 | 14 | rand(20).times do |i| |
| 15 | - profile = profiles.rand | |
| 15 | + profile = profiles.sample | |
| 16 | 16 | article = TinyMceArticle.new( |
| 17 | 17 | :name => "%s #{subject}" % profile.name, |
| 18 | 18 | :body => "%s #{subject}" % profile.name, |
| 19 | - :tag_list => [TAGS.rand, TAGS.rand], | |
| 19 | + :tag_list => [TAGS.sample, TAGS.sample], | |
| 20 | 20 | :profile => profile |
| 21 | 21 | ) |
| 22 | 22 | save article do |
| 23 | - categories.rand.articles << article | |
| 23 | + categories.sample.articles << article | |
| 24 | 24 | end |
| 25 | 25 | end |
| 26 | 26 | end |
| ... | ... | @@ -29,11 +29,11 @@ done |
| 29 | 29 | print "Creating some galleries: " |
| 30 | 30 | for subject in SUBJECTS |
| 31 | 31 | rand(20).times do |i| |
| 32 | - profile = profiles.rand | |
| 32 | + profile = profiles.sample | |
| 33 | 33 | save Gallery.new( |
| 34 | 34 | :name => "Gallery %s #{subject}" % profile.name, |
| 35 | 35 | :body => "Gallery %s #{subject}" % profile.name, |
| 36 | - :tag_list => [TAGS.rand, TAGS.rand], | |
| 36 | + :tag_list => [TAGS.sample, TAGS.sample], | |
| 37 | 37 | :profile => profile |
| 38 | 38 | ) |
| 39 | 39 | end |
| ... | ... | @@ -45,14 +45,14 @@ for subject in EVENT_SUBJECTS |
| 45 | 45 | for theme in THEMES |
| 46 | 46 | event = Event.new( |
| 47 | 47 | :name => subject % theme, |
| 48 | - :profile => profiles.rand, | |
| 48 | + :profile => profiles.sample, | |
| 49 | 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 | 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 | 56 | end |
| 57 | 57 | end |
| 58 | 58 | end | ... | ... |
script/sample-categories
| 1 | 1 | #!/usr/bin/env ruby |
| 2 | +# encoding: utf-8 | |
| 2 | 3 | require File.dirname(__FILE__) + '/../config/environment' |
| 3 | 4 | include Noosfero::SampleDataHelper |
| 4 | 5 | |
| ... | ... | @@ -11,7 +12,7 @@ def new_region(parent, name, color = nil) |
| 11 | 12 | end |
| 12 | 13 | |
| 13 | 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 | 16 | end |
| 16 | 17 | |
| 17 | 18 | def new_productcategory(parent, name) | ... | ... |
script/sample-enterprises
| 1 | 1 | #!/usr/bin/env ruby |
| 2 | +# encoding: utf-8 | |
| 2 | 3 | require File.dirname(__FILE__) + '/../config/environment' |
| 3 | 4 | include Noosfero::SampleDataHelper |
| 4 | 5 | |
| ... | ... | @@ -27,14 +28,13 @@ groups.each do |group| |
| 27 | 28 | enterprise = Enterprise.new( |
| 28 | 29 | :name => name, |
| 29 | 30 | :identifier => name.to_slug, |
| 30 | - :enabled => false, | |
| 31 | 31 | :foundation_year => (1990..2008).to_a[rand(18)], |
| 32 | 32 | :lat => rand_position(:lat), |
| 33 | 33 | :lng => rand_position(:lng) |
| 34 | 34 | ) |
| 35 | 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 | 38 | end |
| 39 | 39 | end |
| 40 | 40 | end |
| ... | ... | @@ -48,6 +48,6 @@ end |
| 48 | 48 | |
| 49 | 49 | ze = Person['ze'] |
| 50 | 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 | 14 | rand(10).times do |i| |
| 15 | 15 | save Product.new( |
| 16 | 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 | 20 | end |
| 21 | 21 | end | ... | ... |
script/sample-profiles
| 1 | 1 | #!/usr/bin/env ruby |
| 2 | +# encoding: utf-8 | |
| 2 | 3 | require File.dirname(__FILE__) + '/../config/environment' |
| 3 | 4 | include Noosfero::SampleDataHelper |
| 4 | 5 | |
| ... | ... | @@ -62,7 +63,7 @@ for name in NAMES |
| 62 | 63 | user.person.save! |
| 63 | 64 | if categories.present? |
| 64 | 65 | 2.times do |
| 65 | - category = categories.rand | |
| 66 | + category = categories.sample | |
| 66 | 67 | category.people << user.person unless category.people.include?(user.person) |
| 67 | 68 | end |
| 68 | 69 | end |
| ... | ... | @@ -112,8 +113,8 @@ done |
| 112 | 113 | people = $environment.people |
| 113 | 114 | print "Creating some friendships: " |
| 114 | 115 | rand(people.size * 3).times do |
| 115 | - from = people.rand | |
| 116 | - to = people.rand | |
| 116 | + from = people.sample | |
| 117 | + to = people.sample | |
| 117 | 118 | if from != to && !from.friends.include?(to) |
| 118 | 119 | task = AddFriend.new(:requestor => to, :target => from) |
| 119 | 120 | save task do |
| ... | ... | @@ -142,12 +143,12 @@ for verb in VERBS |
| 142 | 143 | save community do |
| 143 | 144 | communities << community |
| 144 | 145 | rand(10).times do |
| 145 | - person = people.rand | |
| 146 | + person = people.sample | |
| 146 | 147 | community.add_member(person) unless community.members.include?(person) |
| 147 | 148 | end |
| 148 | 149 | if categories.present? |
| 149 | 150 | 2.times do |
| 150 | - category = categories.rand | |
| 151 | + category = categories.sample | |
| 151 | 152 | category.communities << community unless category.communities.include?(community) |
| 152 | 153 | end |
| 153 | 154 | end |
| ... | ... | @@ -156,7 +157,7 @@ for verb in VERBS |
| 156 | 157 | end |
| 157 | 158 | |
| 158 | 159 | 5.times do |
| 159 | - community = communities.rand | |
| 160 | + community = communities.sample | |
| 160 | 161 | community.add_member(guest.person) unless community.members.include?(guest.person) |
| 161 | 162 | community.add_admin(guest.person) unless community.admins.include?(guest.person) |
| 162 | 163 | end | ... | ... |