Sha256: e0b8dea3a3a41c645d6bc37f5061867ed885cca27622391ed051ba95839668af

Contents?: true

Size: 1.6 KB

Versions: 144

Compression:

Stored size: 1.6 KB

Contents

require 'spec_helper'

describe "sequences" do
  include FactoryGirl::Syntax::Methods

  it "generates several values in the correct format" do
    FactoryGirl.define do
      sequence :email do |n|
        "somebody#{n}@example.com"
      end
    end

    first_value = generate(:email)
    another_value = generate(:email)

    first_value.should =~ /^somebody\d+@example\.com$/
    another_value.should =~ /^somebody\d+@example\.com$/
    first_value.should_not == another_value
  end

  it "generates sequential numbers if no block is given" do
    FactoryGirl.define do
      sequence :order
    end

    first_value = generate(:order)
    another_value = generate(:order)

    first_value.should == 1
    another_value.should == 2
    first_value.should_not == another_value
  end

  it "generates aliases for the sequence that reference the same block" do
    FactoryGirl.define do
      sequence(:size, aliases: [:count, :length]) {|n| "called-#{n}" }
    end

    first_value  = generate(:size)
    second_value = generate(:count)
    third_value  = generate(:length)

    first_value.should  == "called-1"
    second_value.should == "called-2"
    third_value.should  == "called-3"
  end

  it "generates aliases for the sequence that reference the same block and retains value" do
    FactoryGirl.define do
      sequence(:size, "a", aliases: [:count, :length]) {|n| "called-#{n}" }
    end

    first_value  = generate(:size)
    second_value = generate(:count)
    third_value  = generate(:length)

    first_value.should  == "called-a"
    second_value.should == "called-b"
    third_value.should  == "called-c"
  end
end

Version data entries

144 entries across 84 versions & 6 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/sequence_spec.rb
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/sequence_spec.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/sequence_spec.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/sequence_spec.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/sequence_spec.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/sequence_spec.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/sequence_spec.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/sequence_spec.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/sequence_spec.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/sequence_spec.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/sequence_spec.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/sequence_spec.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.1.0/spec/acceptance/sequence_spec.rb
challah-0.9.1.beta.3 vendor/bundle/gems/factory_girl-4.1.0/spec/acceptance/sequence_spec.rb
challah-0.9.1.beta vendor/bundle/gems/factory_girl-4.1.0/spec/acceptance/sequence_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/factory_girl-4.1.0/spec/acceptance/sequence_spec.rb
challah-0.9.0 vendor/bundle/gems/factory_girl-4.1.0/spec/acceptance/sequence_spec.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/sequence_spec.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/sequence_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/factory_girl-3.6.1/spec/acceptance/sequence_spec.rb