Commit 5c7fdd99f4da66e0dc574431d2b9b7de244fec81

Authored by Evandro Junior
1 parent a2cd3edb
Exists in staging

Creating visible users

Showing 2 changed files with 75 additions and 2 deletions   Show diff stats
1 GEM 1 GEM
2 specs: 2 specs:
3 awesome_print (1.6.1) 3 awesome_print (1.6.1)
4 - insensitive_hash (0.3.3)  
5 4
6 PLATFORMS 5 PLATFORMS
7 ruby 6 ruby
8 7
9 DEPENDENCIES 8 DEPENDENCIES
10 awesome_print 9 awesome_print
11 - insensitive_hash  
12 10
13 BUNDLED WITH 11 BUNDLED WITH
14 1.11.2 12 1.11.2
scripts/sample_users.rb 0 → 100755
@@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
  1 +#!/usr/bin/env ruby
  2 +# encoding: utf-8
  3 +require File.dirname(__FILE__) + '/../../../config/environment'
  4 +include Noosfero::SampleDataHelper
  5 +
  6 +categories = $environment.categories
  7 +
  8 +places = [
  9 + { :country=>'BR', :state=>'Bahia', :city=>'Salvador',
  10 + :lat=>-12.94032, :lng=>-38.58398 },
  11 + { :country=>'BR', :state=>'Bahia', :city=>'Feira de Santana',
  12 + :lat=>-12.25547, :lng=>-38.95430 },
  13 + { :country=>'BR', :state=>'São Paulo', :city=>'São Paulo',
  14 + :lat=>-23.54894, :lng=>-46.63881 },
  15 + { :country=>'BR', :state=>'Rio de Janeiro', :city=>'Petrópolis',
  16 + :lat=>-22.50462, :lng=>-43.18232 },
  17 + { :country=>'AR', :state=>'A.C.', :city=>'Buenos Aires',
  18 + :lat=>-34.61088, :lng=>-58.39782 },
  19 + { :country=>'AR', :state=>'Buenos Aires', :city=>'Mar del Plata',
  20 + :lat=>-37.98317, :lng=>-57.59513 },
  21 + { :country=>'MX', :state=>'Guerrero', :city=>'Acapulco',
  22 + :lat=>16.86369, :lng=>-99.88151 },
  23 + { :country=>'US', :state=>'California', :city=>'Los Angeles',
  24 + :lat=>34.02307, :lng=>-118.24310 },
  25 + { :country=>'US', :state=>'Florida', :city=>'Jacksonville',
  26 + :lat=>30.33217, :lng=>-81.65566 },
  27 + { :country=>'IT', :city=>'Roma',
  28 + :lat=>41.89512, :lng=>12.48184 },
  29 + { :country=>'IN', :city=>'Mumbai',
  30 + :lat=>19.01798, :lng=>72.85583 },
  31 + { :country=>'CN', :city=>'Shanghai',
  32 + :lat=>31.23041, :lng=>121.47308 },
  33 + { :country=>'JP', :city=>'Tokyo',
  34 + :lat=>35.68964, :lng=>139.69116 },
  35 + { :country=>'FR', :city=>'Paris',
  36 + :lat=>48.85658, :lng=>2.351074 },
  37 + { :country=>'BW', :city=>'Sowa',
  38 + :lat=>-20.56891, :lng=>26.22367 }
  39 +]
  40 +
  41 +people = []
  42 +NAMES = %w[ José João Antonio Paulo Maria Joana Paula Angela ]
  43 +SURNAMES = %w[ Silva Santos Abreu Oliveira Machado Bonfim ]
  44 +print "Creating users: "
  45 +for name in NAMES
  46 + for surname in SURNAMES
  47 + full_name = [name, surname].join(' ')
  48 + user = User.new({
  49 + :login => full_name.to_slug,
  50 + :email => full_name.to_slug + '@localhost.localdomain',
  51 + :password => 'test',
  52 + :password_confirmation => 'test',
  53 + :environment => $environment,
  54 + })
  55 + save user do
  56 + user.person.name = full_name
  57 + place = places[rand(places.length)]
  58 + user.person.data[:country] = place[:country]
  59 + user.person.state = place[:state]
  60 + user.person.city = place[:city]
  61 + user.person.lat = place[:lat] + (rand/100)-0.005
  62 + user.person.lng = place[:lng] + (rand/100)-0.005
  63 + user.person.visible = true
  64 + user.person.save!
  65 + if categories.present?
  66 + 2.times do
  67 + category = categories.sample
  68 + user.person.add_category category unless category.people.include?(user.person)
  69 + end
  70 + end
  71 + end
  72 + end
  73 +end
  74 +
  75 +done