Sha256: b822ee795cc852706974af82670c78f72ea46f43e5e79cd18addfd4d82cd223c

Contents?: true

Size: 1003 Bytes

Versions: 4

Compression:

Stored size: 1003 Bytes

Contents

FactoryBot.define do
  sequence :user_authentication_token do |n|
    "xxxx#{Time.current.to_i}#{rand(1000)}#{n}xxxxxxxxxxxxx"
  end

  factory :user, class: Spree.user_class do
    email                 { generate(:random_email) }
    login                 { email }
    password              { 'secret' }
    password_confirmation { password }
    authentication_token  { generate(:user_authentication_token) } if Spree.user_class.attribute_method? :authentication_token
    public_metadata { {} }
    private_metadata { {} }

    factory :admin_user do
      spree_roles { [Spree::Role.find_by(name: 'admin') || create(:role, name: 'admin')] }
    end

    factory :user_with_addresses, aliases: [:user_with_addreses] do
      after(:create) do |user|
        user.ship_address = create(:address, user: user)
        user.bill_address = create(:address, user: user)
        user.addresses << user.ship_address
        user.addresses << user.bill_address
        user.save
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree_core-4.4.1 lib/spree/testing_support/factories/user_factory.rb
spree_core-4.4.0 lib/spree/testing_support/factories/user_factory.rb
spree_core-4.4.0.rc2 lib/spree/testing_support/factories/user_factory.rb
spree_core-4.4.0.rc1 lib/spree/testing_support/factories/user_factory.rb