Sha256: 330834b8d68c3b171d4cef735567ebadbfacc4b3727d040254036f4daefa82e4

Contents?: true

Size: 1.23 KB

Versions: 44

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'spree/testing_support/factories/state_factory'
require 'spree/testing_support/factories/country_factory'

FactoryBot.define do
  factory :address, class: 'Spree::Address' do
    transient do
      # There's `Spree::Address#country_iso=`, prohibiting me from using `country_iso` here
      country_iso_code { 'US' }
      state_code { 'AL' }
    end

    firstname { 'John' }
    lastname { nil }
    company { 'Company' }
    address1 { '10 Lovely Street' }
    address2 { 'Northwest' }
    city { 'Herndon' }
    sequence(:zipcode, 10001) { |i| i.to_s }
    phone { '555-555-0199' }
    alternative_phone { '555-555-0199' }

    state do |address|
      Spree::State.joins(:country).where('spree_countries.iso = (?)', country_iso_code).find_by(abbr: state_code) ||
        address.association(:state, country_iso: country_iso_code, state_code: state_code)
    end

    country do |address|
      if address.state
        address.state.country
      else
        address.association(:country, iso: country_iso_code)
      end
    end
  end

  factory :ship_address, parent: :address do
    address1 { 'A Different Road' }
  end

  factory :bill_address, parent: :address do
    address1 { 'PO Box 1337' }
  end
end

Version data entries

44 entries across 44 versions & 2 rubygems

Version Path
solidus_core-2.10.5 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.10.3 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.10.2 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.9.6 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.8.6 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.10.1 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.9.5 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.10.0 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.9.4 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.6.6 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.7.4 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.8.5 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.9.3 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.9.2 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.10.0.beta1 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.7.3 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.6.5 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.9.1 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.9.0 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.9.0.rc.1 lib/spree/testing_support/factories/address_factory.rb