Created
June 19, 2017 21:26
-
-
Save wellavelino/34e040dbca69f03b2c9904a1b05446b3 to your computer and use it in GitHub Desktop.
Simple module to generate a lot of test mock
This file contains 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
module Helpers | |
def generate_cep | |
cep = rand(01000000...99990000) | |
generate_cep if cep.size < 8 | |
cep | |
end | |
def generate_password | |
(0...8).map { ([65, 97].sample + rand(26)).chr }.push(rand(99)).join | |
end | |
def generate_email | |
email = (0...9).map {[*'a'..'z'].sample}.join | |
provider = ['@gmail.com', '@hotmail.com', '@outlook.com', '@yahoo.com'].sample | |
email + provider | |
end | |
def generate_name | |
['Testador', 'Bug', 'Testa', 'HelloWord', 'Ruby', 'Calabash', 'Barril'].sample | |
end | |
def generate_cell_number | |
ddd = '11' | |
ddd + (1..9).map{'23456789'.chars.sample}.join | |
end | |
#retirado de https://gist.github.com/breim/21f9eb4656c55b9b28e5 | |
def generate_cpf | |
digits = [] | |
9.times { digits << rand(9) } | |
2.times { digits << verification_digit_for(digits) } | |
digits.join | |
end | |
private | |
def verification_digit_for(known_digits) | |
i = 1 | |
sums = known_digits.reverse.collect do |digit| | |
i += 1 | |
digit * i | |
end | |
verification_digit = 11 - sums.inject(0) { |sum, item| sum + item } % 11 | |
verification_digit < 10 ? verification_digit : 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment