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.8.1 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.6.3 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.8.0 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.7.1 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.6.2 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.10 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.9 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.8 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.7 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.6 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.5 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.4 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.3 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.1 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.0 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
solidus_core-2.7.0 spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb