Skip to content

Instantly share code, notes, and snippets.

@serg-kovalev
Forked from mikegrassotti/gist:2247065
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serg-kovalev/8487870b128b093721e4 to your computer and use it in GitHub Desktop.
Save serg-kovalev/8487870b128b093721e4 to your computer and use it in GitHub Desktop.
FactoryGirl upgrade from version 2.* to 3.*
# FactoryGirl3ForYouAndMe
# The new syntax: http://robots.thoughtbot.com/post/19412394597/factory-girl-hits-3-0
#
# Where to learn sed?
# http://www.grymoire.com/Unix/Sed.html#uh-6
# http://www.markhneedham.com/blog/2011/01/11/sed-across-multiple-files/
#
# What needs to change?
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory.create"
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory.build"
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory.define"
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory.attributes_for"
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory\(\:"
# Lets do it!
find . -type f -name "factor*.rb" -print0 | xargs -0 sed -i '.sed' -e 's/Factory.define/FactoryGirl.define/'
find . -type f -name "*_spec.rb" -print0 | xargs -0 sed -i '.sed' -e 's/Factory.create/FactoryGirl.create/' -e 's/Factory.build/FactoryGirl.build/' -e 's/Factory(:/FactoryGirl.create(:/' -e 's/Factory.define/FactoryGirl.define/' -e 's/Factory.attributes_for/FactoryGirl.attributes_for/'
# Fix FeedEngine Factory
find . -type f -name "*_spec.rb" -print0 | xargs -0 sed -i '.sed' -e 's/FeedEngine::FactoryGirl/FeedEngine::Factory/'
# Use syntax methods
find . -type f -name "*_spec.rb" -print0 | xargs -0 sed -i '.sed' -e 's/FactoryGirl.create/create/' -e 's/FactoryGirl.build/build/' -e 's/FactoryGirl.attributes_for/attributes_for/'
# Goodbye backups
find . -name "*.sed" -print0 | xargs -0 rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment