Sha256: e9d553a2992852d5149bc4c2513ee0723437b47923ea6edec6df7ff9012cbd85

Contents?: true

Size: 1.58 KB

Versions: 43

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

module Spree
  module ReturnItem::ExchangeVariantEligibility
    RSpec.describe SameProduct, type: :model do
      describe ".eligible_variants" do
        context "product has no variants" do
          it "returns the master variant for the same product" do
            product = create(:product)
            product.master.stock_items.first.update_column(:count_on_hand, 10)

            expect(SameProduct.eligible_variants(product.master)).to eq [product.master]
          end
        end

        context "product has variants" do
          it "returns all variants for the same product" do
            product = create(:product, variants: Array.new(3) { create(:variant) })
            product.variants.map { |v| v.stock_items.first.update_column(:count_on_hand, 10) }

            expect(SameProduct.eligible_variants(product.variants.first).sort).to eq product.variants.sort
          end
        end

        it "does not return variants for another product" do
          variant = create(:variant)
          other_product_variant = create(:variant)
          expect(SameProduct.eligible_variants(variant)).not_to include other_product_variant
        end

        it "only returns variants that are on hand" do
          product = create(:product, variants: Array.new(2) { create(:variant) })
          in_stock_variant = product.variants.first

          in_stock_variant.stock_items.first.update_column(:count_on_hand, 10)
          expect(SameProduct.eligible_variants(in_stock_variant)).to eq [in_stock_variant]
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
solidus_core-2.9.6 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.8.6 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.9.5 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.9.4 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.6.6 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.7.4 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.8.5 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.9.3 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.9.2 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.10.0.beta1 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.7.3 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.6.5 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.9.1 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.9.0 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.9.0.rc.1 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.8.4 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.8.3 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.7.2 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.6.4 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.8.2 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb