Sha256: eefbe1a9492c0a32ca6b6814c8404be2fe255390a486922af514b78bf40d0d1e

Contents?: true

Size: 1.04 KB

Versions: 29

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'spree/testing_support/factory_bot'
Spree::TestingSupport::FactoryBot.when_cherry_picked do
  Spree::TestingSupport::FactoryBot.deprecate_cherry_picking

  require 'spree/testing_support/sequences'
  require 'spree/testing_support/factories/role_factory'
  require 'spree/testing_support/factories/address_factory'
end

FactoryBot.define do
  factory :user, class: Spree::UserClassHandle.new do
    email { generate(:email) }
    password { 'secret' }
    password_confirmation { password }

    trait :with_api_key do
      after(:create) do |user, _|
        user.generate_spree_api_key!
      end
    end

    trait :with_orders do
      after(:create) do |user, _|
        create(:order, user: user)
      end
    end

    factory :admin_user do
      after(:create) do |user, _|
        admin_role = Spree::Role.find_by(name: 'admin') || create(:role, name: 'admin')
        user.spree_roles << admin_role
      end
    end

    factory :user_with_addresses do |_u|
      bill_address
      ship_address
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
solidus_core-3.4.6 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.4.5 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.4.4 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.3.4 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.2.9 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.2.8 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.3.3 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.4.3 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.4.2 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.2.7 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.3.2 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.4.1 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.4.0 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.3.1 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.2.6 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.1.9 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.3.0 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.2.5 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.2.4 lib/spree/testing_support/factories/user_factory.rb
solidus_core-3.2.3 lib/spree/testing_support/factories/user_factory.rb