Created
November 28, 2013 22:07
-
-
Save fsaravia/7698729 to your computer and use it in GitHub Desktop.
Fake unique property with Faker (https://github.com/stympy/faker)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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