Skip to content

Instantly share code, notes, and snippets.

@ruralocity
Last active December 17, 2015 13:10
Show Gist options
  • Save ruralocity/5615322 to your computer and use it in GitHub Desktop.
Save ruralocity/5615322 to your computer and use it in GitHub Desktop.
Simple rake task for obfuscating data, to use in screenshots, demos, etc. See http://everydayrails.com/2013/05/20/obfuscated-data-screenshots.html for context.
if Rails.env.development?
require 'faker'
namespace :obfuscate do
desc "Obfuscate user data"
task :users => :environment do
raise "Not to be run in production!" if Rails.env.production?
User.all.each do |user|
unless user.admin?
user.update_attributes(
firstname: Faker::Name.first_name,
lastname: Faker::Name.last_name,
email: Faker::Internet.email)
end
end
end
desc "Obfuscate group data"
task :groups => :environment do
raise "Not to be run in production!" if Rails.env.production?
schools = ['High School', 'Middle School', 'Elementary School']
Group.all.each do |group|
group.update_attributes(
name: "#{Faker::Address.city} #{schools.shuffle[0]}",
description: '')
end
end
desc "Obfuscate project data"
task :projects => :environment do
raise "Not to be run in production!" if Rails.env.production?
Project.all.each do |project|
project.update_attributes(name: "#{Faker::Address.state} Project")
end
end
desc "Obfuscate user, group and project data"
task :all => [:users, :groups, :projects]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment