Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Code from blog post on anonymizing sensitive user data
task :env_checker do
unless Rails.env.development?
puts "Not in development environment, exiting!"
exit 1
end
end
namespace :app_name do
desc 'Anonymize user, company, and location information'
task :anonymize => [:environment, :env_checker] do
User.all.each do |user|
genders = ['male', 'female']
user.update_attributes!(
:born_on => rand(50*365).days.ago
:email => (rand(1000) + 100).to_s + Faker::Internet.email,
:first_name => Faker::Name.first_name,
:gender => genders.rand,
:last_name => Faker::Name.last_name)
end
Company.all.each do |company|
company.update_attributes!(
:description_html => Faker::Company.catch_phrase,
:name => Faker::Company.name,
:twitter_username => Faker::Internet.user_name,
:url => 'http://' + Faker::Internet.domain_name)
end
location_array = Location.all.inject([]) do |result, location|
result << [location.lat, location.lng]
end.shuffle
Location.all.each do |location|
lat, lng = location_array.pop
location.update_attributes(
:city => Faker::Address.city,
:extended_address => Faker::Address.secondary_address,
:lat => lat,
:lng => lng,
:phone => Faker::PhoneNumber.phone_number,
:postal_code => Faker::Address.zip_code,
:state => Faker::Address.state_abbr,
:street_address => Faker::Address.street_address
)
end
end
end
@tinogomes

To generate your own phone format, you can use Faker.numerify("###-###-####")

See more at https://github.com/yyyc514/faker/blob/master/lib/faker/phone_number.rb#L5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.