Sha256: cdcc6e92e485d74fbbb1f325f06213c3a7f8c7a03ce15cd9a5b04a5b16c48fe3

Contents?: true

Size: 1.22 KB

Versions: 17

Compression:

Stored size: 1.22 KB

Contents

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

FactoryGirl.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 'Doe'
    company 'Company'
    address1 '10 Lovely Street'
    address2 'Northwest'
    city 'Herndon'
    zipcode { TwitterCldr::Shared::PostalCodes.for_territory(country_iso_code).sample.first }
    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

17 entries across 17 versions & 1 rubygems

Version Path
solidus_core-2.0.3 lib/spree/testing_support/factories/address_factory.rb
solidus_core-1.4.2 lib/spree/testing_support/factories/address_factory.rb
solidus_core-1.3.2 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.0.2 lib/spree/testing_support/factories/address_factory.rb
solidus_core-1.4.1 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.0.1 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.0.0 lib/spree/testing_support/factories/address_factory.rb
solidus_core-1.4.0 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.0.0.rc1 lib/spree/testing_support/factories/address_factory.rb
solidus_core-1.4.0.rc1 lib/spree/testing_support/factories/address_factory.rb
solidus_core-2.0.0.beta1 lib/spree/testing_support/factories/address_factory.rb
solidus_core-1.4.0.beta1 lib/spree/testing_support/factories/address_factory.rb
solidus_core-1.3.1 lib/spree/testing_support/factories/address_factory.rb
solidus_core-1.3.0 lib/spree/testing_support/factories/address_factory.rb
solidus_core-1.3.0.rc2 lib/spree/testing_support/factories/address_factory.rb
solidus_core-1.3.0.rc1 lib/spree/testing_support/factories/address_factory.rb
solidus_core-1.3.0.beta1 lib/spree/testing_support/factories/address_factory.rb