Skip to content

Instantly share code, notes, and snippets.

@jiggneshhgohel
Created December 15, 2015 11:35
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 jiggneshhgohel/dad4233bdd332aebbd14 to your computer and use it in GitHub Desktop.
Save jiggneshhgohel/dad4233bdd332aebbd14 to your computer and use it in GitHub Desktop.
FactoryGirl - Generate a Random Cell Number

Can be useful in generating random cell numbers while writing specs for a class which has a Cell Number attribute.

FactoryGirl.define do
  sequence :cell_number do |n|
    # ----------------------------------------         ----------------------
    #|           SUFFIX PART                 |         |   PREFIX PART      |
    9.times.map { (0..9).to_a.sample }.join("").prepend([7, 8, 9].sample.to_s)
  end
end

Sample Output

7119156645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment