Everyday Rails

Obfuscating data in Rails applications for screenshots and demonstrations

By Aaron Sumner, May 20, 2013.

I recently had a need to demonstrate a data-heavy application to potential customers. Demonstrating the application with bogus numbers is one thing, but everything looks much more realistic when I’m using real data. I can’t reveal any real information, though, so I needed a quick way to obfuscate real names. Faker to the rescue!

In the past I’ve shown how to use Faker in tests, but it’s got other uses as well. In this case, I used it to change the names of the innocent in my application, while keeping the interesting numbers intact. The result: No way to identify anything to a given user or group, but a realistic demonstration of the data all the same.

To pull this off, I copied production data over to my development setup, then built some simple Rake tasks to obfuscate my data in development. Check it out:

Here, I only obfuscate non-admin users (so I can continue to sign in with my usual credentials), and since I’m working with schools I augment Faker’s returned results with some of my own. I also show a couple of ways you could make sure the tasks aren’t errantly run in production, because that would be bad.

And obviously, this won’t apply to every situation–you may not have access to production data, or your data might not be as easily obfuscatable. It would also need some tweaking to make work in any situation besides mine, since I’m working directly with my Rails models in the rake tasks.

But it’s a fast way to get realistic data for demos and screenshots. If you don’t care about using real data, you can also try this approach for populating a database with lots of test data. It’s a few years old but still applicable.

What do you think? Follow along on on Twitter or Facebook to let me know what you think and catch my latest posts. Better yet, subscribe to my newsletter for updates from Everyday Rails, book picks, and other thoughts and ideas that didn't quite fit here.

Test with confidence!

If you liked my series on practical advice for adding reliable tests to your Rails apps, check out the expanded ebook version. Lots of additional, exclusive content and a complete sample Rails application.

Newsletter

Ruby on Rails news and tips, and other ideas and surprises from Aaron at Everyday Rails. Delivered to your inbox on no particular set schedule.