<commit_before>require 'spec_helper'

describe Spree::Variant do
  let!(:variant) { create(:variant, :count_on_hand => 95) }

  before(:each) do
    reset_spree_preferences
  end

  context "validations" do
    it "should validate price is greater than 0" do
      variant.price = -1
      variant.should be_invalid
    end

    it "should validate price is 0" do
      variant.price = 0
      variant.should be_valid
    end
  end

  # Regression test for #1778
  it "recalculates product's count_on_hand when saved" do
    variant.stub :is_master => true
    variant.product.should_receive(:on_hand).and_return(3)
    variant.product.should_receive(:update_column).with(:count_on_hand, 3)
    variant.decrement!(:count_on_hand)
  end

  context "on_hand=" do
    before { variant.stub(:inventory_units => mock('inventory-units')) }

    context "when :track_inventory_levels is true" do
      before { Spree::Config.set :track_inventory_levels => true }

      context "and count is increased" do
        before { variant.inventory_units.stub(:with_state).and_return([]) }
        let(:inventory_unit) { mock_model(Spree::InventoryUnit, :state => "backordered") }

        it "should change count_on_hand to given value" do
          variant.on_hand = 100
          variant.count_on_hand.should == 100
        end

        it "should check for backordered units" do
          variant.save!
          variant.inventory_units.should_receive(:with_state).with("backordered")
          variant.on_hand = 100
          variant.save!
        end
<commit_msg>Correct is_master? stub in variant_spec<commit_after>require 'spec_helper'

describe Spree::Variant do
  let!(:variant) { create(:variant, :count_on_hand => 95) }

  before(:each) do
    reset_spree_preferences
  end

  context "validations" do
    it "should validate price is greater than 0" do
      variant.price = -1
      variant.should be_invalid
    end

    it "should validate price is 0" do
      variant.price = 0
      variant.should be_valid
    end
  end

  # Regression test for #1778
  it "recalculates product's count_on_hand when saved" do
    variant.stub :is_master? => true
    variant.product.should_receive(:on_hand).and_return(3)
    variant.product.should_receive(:update_column).with(:count_on_hand, 3)
    variant.decrement!(:count_on_hand)
  end

  context "on_hand=" do
    before { variant.stub(:inventory_units => mock('inventory-units')) }

    context "when :track_inventory_levels is true" do
      before { Spree::Config.set :track_inventory_levels => true }

      context "and count is increased" do
        before { variant.inventory_units.stub(:with_state).and_return([]) }
        let(:inventory_unit) { mock_model(Spree::InventoryUnit, :state => "backordered") }

        it "should change count_on_hand to given value" do
          variant.on_hand = 100
          variant.count_on_hand.should == 100
        end

        it "should check for backordered units" do
          variant.save!
          variant.inventory_units.should_receive(:with_state).with("backordered")
          variant.on_hand = 100
          variant.save!
        end

{'fraction_non_alphanumeric': 0.0963317384370016, 'fraction_numerical': 0.013397129186602871, 'mean_word_length': 3.088657105606258, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4603878', 'n_tokens_mistral': 1006, 'n_tokens_neox': 944, 'n_words': 236}