Skip to content
sheerun edited this page Aug 1, 2012 · 2 revisions

boolean

Returns either true or false, randomly.

Forgery(:basic).boolean
# => true

Forgery(:basic).boolean
# => false

color

Randomly generates the name of a color, with the first character uppercase, as a string.

Forgery(:basic).color
# => "Violet"

Derives the list of colors from dictionaries[:colors].

encrypt

Creates a SHA1 hexdigest, with the current time as a salt. It takes two arguments:

  1. A string (default: "password")
  2. Any object, should be something that has a meaningful return to .to_s, (default: Time.now.to_s)
Forgery(:basic).encrypt
# => "b2fbd3955a36068e93e0b9db45bcb178f08336f5"

Forgery(:basic).encrypt 'random-string'
# => "00932bafce4a9391f888ca77f81f98b8e89d3aa6"

Forgery(:basic).encrypt 'random-string', Time.utc(2009) 
# => "4b157c2fbf430b962842d21926eaa887c3a12f81"

frequency

Returns random element from following array: ["Never", "Once", "Seldom", "Often", "Daily", "Weekly", "Monthly", "Yearly"]

Forgery(:basic).frequency
# => "Never"

number

Generates random number within given range.

Forgery(:basic).number(:at_least => 1, :at_most => 14)
# => 9

password

Generates password.

Currently basically alias for text method with different defaults.

  :at_least      => 6,    # minimum number of characters
  :at_most       => 12,    # maximum number of characters
  :allow_lower   => true,  # abcdefghijklmnopqrstuvwxyz
  :allow_upper   => true,  # ABCDEFGHIJKLMNOPQRSTUVWXYZ
  :allow_numeric => true,  # 0123456789
  :allow_special => false, # !'@\#$%^&*()_+-=[]{};:\",./?
  :exactly       => nil    # exact number of characters
Forgery(:basic).password
# => "vLaETMv"

text

Allowed options along defaults:

  :at_least      => 10,    # minimum number of characters
  :at_most       => 15,    # maximum number of characters
  :allow_lower   => true,  # abcdefghijklmnopqrstuvwxyz
  :allow_upper   => true,  # ABCDEFGHIJKLMNOPQRSTUVWXYZ
  :allow_numeric => true,  # 0123456789
  :allow_special => false, # !'@\#$%^&*()_+-=[]{};:\",./?
  :exactly       => nil    # exact number of characters
Forgery(:basic).text
# => "GSoxkFJMjEJ9Cqm"

hex_color

Forgery(:basic).hex_color
# => "#1bc23c"

short_hex_color

Forgery(:basic).short_hex_color
# => "#8e7"
Clone this wiki locally