From b0c41ba16c5b53c67c862fc5e107ee631e7e034a Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 28 Jan 2014 13:44:45 -0300 Subject: [PATCH] rails3: fix sample data scripts --- app/models/certifier.rb | 2 +- app/models/organization.rb | 2 +- app/models/product.rb | 2 +- app/models/product_category.rb | 2 +- app/models/profile.rb | 2 +- app/models/qualifier.rb | 2 +- app/models/unit.rb | 2 +- script/sample-articles | 20 ++++++++++---------- script/sample-categories | 3 ++- script/sample-enterprises | 12 ++++++------ script/sample-products | 4 ++-- script/sample-profiles | 13 +++++++------ 12 files changed, 34 insertions(+), 32 deletions(-) diff --git a/app/models/certifier.rb b/app/models/certifier.rb index ba9b712..bb08b59 100644 --- a/app/models/certifier.rb +++ b/app/models/certifier.rb @@ -1,6 +1,6 @@ class Certifier < ActiveRecord::Base - attr_accessible :name + attr_accessible :name, :environment SEARCHABLE_FIELDS = { :name => 10, diff --git a/app/models/organization.rb b/app/models/organization.rb index 6547d01..a212c6a 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,7 +1,7 @@ # Represents any organization of the system class Organization < Profile - attr_accessible :moderated_articles + attr_accessible :moderated_articles, :foundation_year SEARCH_FILTERS += %w[ more_popular diff --git a/app/models/product.rb b/app/models/product.rb index 0373b31..337943d 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -11,7 +11,7 @@ class Product < ActiveRecord::Base SEARCH_DISPLAYS = %w[map full] - attr_accessible :name, :product_category, :highlighted, :price + attr_accessible :name, :product_category, :highlighted, :price, :enterprise def self.default_search_display 'full' diff --git a/app/models/product_category.rb b/app/models/product_category.rb index 2118ce7..058226a 100644 --- a/app/models/product_category.rb +++ b/app/models/product_category.rb @@ -3,7 +3,7 @@ class ProductCategory < Category has_many :products has_many :inputs - attr_accessible :name, :parent + attr_accessible :name, :parent, :environment def all_products Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) }) diff --git a/app/models/profile.rb b/app/models/profile.rb index 5d2f03a..6d37750 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -3,7 +3,7 @@ # which by default is the one returned by Environment:default. class Profile < ActiveRecord::Base - attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id + 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 # use for internationalizable human type names in search facets # reimplement on subclasses diff --git a/app/models/qualifier.rb b/app/models/qualifier.rb index da3c2ce..2f62cfb 100644 --- a/app/models/qualifier.rb +++ b/app/models/qualifier.rb @@ -1,6 +1,6 @@ class Qualifier < ActiveRecord::Base - attr_accessible :name + attr_accessible :name, :environment SEARCHABLE_FIELDS = { :name => 1, diff --git a/app/models/unit.rb b/app/models/unit.rb index bb8fbf5..31ecd1b 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -1,6 +1,6 @@ class Unit < ActiveRecord::Base - attr_accessible :name, :singular, :plural + attr_accessible :name, :singular, :plural, :environment validates_presence_of :singular validates_presence_of :plural diff --git a/script/sample-articles b/script/sample-articles index c36d828..29add31 100755 --- a/script/sample-articles +++ b/script/sample-articles @@ -12,15 +12,15 @@ THEMES = ['Sustainability', 'Free Software', 'Climate Change', 'Environment', 'A print "Creating some TinyMce articles: " for subject in SUBJECTS rand(20).times do |i| - profile = profiles.rand + profile = profiles.sample article = TinyMceArticle.new( :name => "%s #{subject}" % profile.name, :body => "%s #{subject}" % profile.name, - :tag_list => [TAGS.rand, TAGS.rand], + :tag_list => [TAGS.sample, TAGS.sample], :profile => profile ) save article do - categories.rand.articles << article + categories.sample.articles << article end end end @@ -29,11 +29,11 @@ done print "Creating some galleries: " for subject in SUBJECTS rand(20).times do |i| - profile = profiles.rand + profile = profiles.sample save Gallery.new( :name => "Gallery %s #{subject}" % profile.name, :body => "Gallery %s #{subject}" % profile.name, - :tag_list => [TAGS.rand, TAGS.rand], + :tag_list => [TAGS.sample, TAGS.sample], :profile => profile ) end @@ -45,14 +45,14 @@ for subject in EVENT_SUBJECTS for theme in THEMES event = Event.new( :name => subject % theme, - :profile => profiles.rand, + :profile => profiles.sample, :start_date => Date.today + (-30 + rand(60)).days, - :tag_list => [TAGS.rand, TAGS.rand] + :tag_list => [TAGS.sample, TAGS.sample] ) save event do - categories.rand.events << event - categories.rand.events << event - categories.rand.events << event + categories.sample.events << event + categories.sample.events << event + categories.sample.events << event end end end diff --git a/script/sample-categories b/script/sample-categories index c7704f9..14a4113 100755 --- a/script/sample-categories +++ b/script/sample-categories @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# encoding: utf-8 require File.dirname(__FILE__) + '/../config/environment' include Noosfero::SampleDataHelper @@ -11,7 +12,7 @@ def new_region(parent, name, color = nil) end def new_state(parent, name) - save State.new(:name => name, :parent => parent, :environment => $environment) + save State.new(:name => name, :parent_id => parent ? parent.id : nil, :environment => $environment) end def new_productcategory(parent, name) diff --git a/script/sample-enterprises b/script/sample-enterprises index 4015ab3..60caeb1 100755 --- a/script/sample-enterprises +++ b/script/sample-enterprises @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# encoding: utf-8 require File.dirname(__FILE__) + '/../config/environment' include Noosfero::SampleDataHelper @@ -27,14 +28,13 @@ groups.each do |group| enterprise = Enterprise.new( :name => name, :identifier => name.to_slug, - :enabled => false, :foundation_year => (1990..2008).to_a[rand(18)], :lat => rand_position(:lat), :lng => rand_position(:lng) ) save enterprise do - categories.rand.enterprises << enterprise - categories.rand.enterprises << enterprise + categories.sample.enterprises << enterprise + categories.sample.enterprises << enterprise end end end @@ -48,6 +48,6 @@ end ze = Person['ze'] # give admin rights for 'ze' in some enterprises -$environment.enterprises.rand.add_admin(ze) -$environment.enterprises.rand.add_admin(ze) -$environment.enterprises.rand.add_admin(ze) +$environment.enterprises.sample.add_admin(ze) +$environment.enterprises.sample.add_admin(ze) +$environment.enterprises.sample.add_admin(ze) diff --git a/script/sample-products b/script/sample-products index c4fecbc..a555ade 100755 --- a/script/sample-products +++ b/script/sample-products @@ -14,8 +14,8 @@ for thing in THINGS rand(10).times do |i| save Product.new( :name => name, - :enterprise_id => enterprises.rand.id, :price => (i * 13.7), - :product_category_id => categories.rand.id + :enterprise => enterprises.sample, :price => (i * 13.7), + :product_category => categories.sample ) end end diff --git a/script/sample-profiles b/script/sample-profiles index 372ba81..8d417e4 100755 --- a/script/sample-profiles +++ b/script/sample-profiles @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# encoding: utf-8 require File.dirname(__FILE__) + '/../config/environment' include Noosfero::SampleDataHelper @@ -62,7 +63,7 @@ for name in NAMES user.person.save! if categories.present? 2.times do - category = categories.rand + category = categories.sample category.people << user.person unless category.people.include?(user.person) end end @@ -112,8 +113,8 @@ done people = $environment.people print "Creating some friendships: " rand(people.size * 3).times do - from = people.rand - to = people.rand + from = people.sample + to = people.sample if from != to && !from.friends.include?(to) task = AddFriend.new(:requestor => to, :target => from) save task do @@ -142,12 +143,12 @@ for verb in VERBS save community do communities << community rand(10).times do - person = people.rand + person = people.sample community.add_member(person) unless community.members.include?(person) end if categories.present? 2.times do - category = categories.rand + category = categories.sample category.communities << community unless category.communities.include?(community) end end @@ -156,7 +157,7 @@ for verb in VERBS end 5.times do - community = communities.rand + community = communities.sample community.add_member(guest.person) unless community.members.include?(guest.person) community.add_admin(guest.person) unless community.admins.include?(guest.person) end -- libgit2 0.21.2