Sha256: 687dbb53ab92384d279f94ebb0f5bd6f11278b9cb5fd774217b3b5639af8fe87

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

FactoryBot.define do
  factory :subscription, class: 'SolidusSubscriptions::Subscription' do
    store
    interval_length { 1 }
    interval_units { :month }
    currency { 'USD' }

    user do
      new_user = create(:user, :subscription_user)
      card = create(:credit_card, gateway_customer_profile_id: 'BGS-123', user: new_user)
      wallet_payment_source = new_user.wallet.add(card)
      new_user.wallet.default_wallet_payment_source = wallet_payment_source
      new_user
    end

    trait :with_line_item do
      transient do
        line_item_traits { [] }
      end

      line_items { [association(:subscription_line_item, *line_item_traits)] }
    end

    trait :with_shipping_address do
      association :shipping_address, factory: :address
    end

    trait :with_billing_address do
      association :billing_address, factory: :address
    end

    trait :actionable do
      with_line_item
      actionable_date { Time.zone.now.yesterday.beginning_of_minute }
    end

    trait :not_actionable do
      with_line_item
      actionable_date { Time.zone.now.tomorrow.beginning_of_minute }
    end

    trait(:pending_cancellation) do
      actionable
      state { 'pending_cancellation' }
    end

    trait(:canceled) {
      state { 'canceled' }
    }
    trait(:inactive) {
      state { 'inactive' }
    }
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_subscriptions-2.0.2 lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb
solidus_subscriptions-2.0.1 lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb
solidus_subscriptions-2.0.0 lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb
solidus_subscriptions-1.1.0 lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb
solidus_subscriptions-1.0.1 lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb
solidus_subscriptions-1.0.0 lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb
solidus_subscriptions-1.0.0.rc1 lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb