Sha256: 57ae770d84ce410fba8b67e0f4f662bfb397b48e38309c1032d19c95c0d5ee3e

Contents?: true

Size: 1.7 KB

Versions: 2

Compression:

Stored size: 1.7 KB

Contents

module FactoryGirl

  def self.register_default_sequences
    # basic types
    register_sequence(Sequence.new(:integer) { |n| n })
    register_sequence(Sequence.new(:string) { |n| "string-#{n}" })
    register_sequence(Sequence.new(:date) { Date.today })
    register_sequence(Sequence.new(:datetime) { Time.current })
    register_sequence(Sequence.new(:boolean) { |n| [false, true][n%2] })

    # personal
    register_sequence(Sequence.new(:name, :aliases => [:login, :first_name, :last_name]) { |n| "name-#{n}" })
    register_sequence(Sequence.new(:password) { |n| "password-#{n}" })
    register_sequence(Sequence.new(:email) { |n| "person#{n}@example.com" })

    # network
    register_sequence(Sequence.new(:ip_address) { |n| "192.168.0.#{n%256}" })
    register_sequence(Sequence.new(:ip_subnet) { |n| "192.168.#{n%256}.0" })
    register_sequence(Sequence.new(:mac_address) { |n| "01:23:45:67:89:" + ("%02x" % "#{n%256}") })

    # post (or article)
    register_sequence(Sequence.new(:title) { |n| "Title #{n}" })
    register_sequence(Sequence.new(:body, :aliases => [:description]) { |n| "body-#{n}" })
    register_sequence(Sequence.new(:slug) { |n| "slug-#{n}" })

    # other
    register_sequence(Sequence.new(:domain) { |n| "example#{n}.com" })
    register_sequence(Sequence.new(:subdomain) { |n| "blog#{n}" })
    register_sequence(Sequence.new(:color) { |n| "%06d" % n })
    register_sequence(Sequence.new(:checksum) { |n| n })
  end

  # FIXME [AK] Monkey-patching here. There should be another way around.
  def self.reload
    reset_configuration
    register_default_strategies
    register_default_callbacks
    register_default_sequences
    find_definitions
  end
end

FactoryGirl.register_default_sequences

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
factory_girl_sequences-0.0.4 lib/factory_girl_sequences/sequences.rb
factory_girl_sequences-0.0.3 lib/factory_girl_sequences/sequences.rb