Skip to content

Instantly share code, notes, and snippets.

@fsaravia
Created November 28, 2013 22:07
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 fsaravia/7698729 to your computer and use it in GitHub Desktop.
Save fsaravia/7698729 to your computer and use it in GitHub Desktop.
Fake unique property with Faker (https://github.com/stympy/faker)
# ActiveRecord edition
# For use with DataMapper replace line 7 with the following line
# if model.first(property.to_sym => result).nil?
def fake_unique(model, property, method_module, method)
result = method_module.send(method.to_sym)
if model.where(property.to_sym => result).first.nil?
result
else
fake_unique(model, property, method_module, method)
end
end
# Usage: fake_unique(User, :email, Faker::Internet, :free_email)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment