<commit_before>require 'spec_helper'

module Spree
  describe OrderUpdater do
    let(:order) { stub_model(Spree::Order, :backordered? => false) }
    let(:updater) { Spree::OrderUpdater.new(order) }

    context "order totals" do
      let(:line_items) { 2.times.map { double(amount: 10, adjustment_total: -2) } }

      it "updates payment totals" do
        order.stub_chain(:payments, :completed, :sum).and_return(10)

        updater.update_totals
        order.payment_total.should == 10
      end

      it "update item total" do
        order.stub :line_items => line_items
        updater.update_item_total
        order.item_total.should == 20
      end

      it "update shipment total" do
        order.stub_chain(:shipments, sum: 10)
        updater.update_shipment_total
        order.shipment_total.should == 10
      end

      it "update order adjustments" do
        order.stub_chain(:adjustments, :eligible, :sum).and_return(-10)
        order.stub_chain(:line_items, sum: -4)

        expect(updater).to receive(:recalculate_adjustments)
        updater.update_adjustment_total
        order.adjustment_total.should == -14
      end
    end

    context "updating shipment state" do
      before do
        order.stub_chain(:shipments, :shipped, :count).and_return(0)
        order.stub_chain(:shipments, :ready, :count).and_return(0)
        order.stub_chain(:shipments, :pending, :count).and_return(0)
      end

      it "is backordered" do
        order.stub :backordered? => true
        updater.update_shipment_state

        order.shipment_state.should == 'backorder'
      end

      it "is nil" do
        order.stub_chain(:shipments, :states).and_return([])
        order.stub_chain(:shipments, :count).and_return(0)<commit_msg>Create real shipment rather than stubbing implementaiton in order_updater_spec<commit_after>require 'spec_helper'

module Spree
  describe OrderUpdater do
    let(:order) { stub_model(Spree::Order, :backordered? => false) }
    let(:updater) { Spree::OrderUpdater.new(order) }

    context "order totals" do
      let(:line_items) { 2.times.map { double(amount: 10, adjustment_total: -2) } }

      it "updates payment totals" do
        order.stub_chain(:payments, :completed, :sum).and_return(10)

        updater.update_totals
        order.payment_total.should == 10
      end

      it "update item total" do
        order.stub :line_items => line_items
        updater.update_item_total
        order.item_total.should == 20
      end

      it "update shipment total" do
        create(:shipment, :order => order, :cost => 10)
        updater.update_shipment_total
        order.shipment_total.should == 10
      end

      it "update order adjustments" do
        order.stub_chain(:adjustments, :eligible, :sum).and_return(-10)
        order.stub_chain(:line_items, sum: -4)

        expect(updater).to receive(:recalculate_adjustments)
        updater.update_adjustment_total
        order.adjustment_total.should == -14
      end
    end

    context "updating shipment state" do
      before do
        order.stub_chain(:shipments, :shipped, :count).and_return(0)
        order.stub_chain(:shipments, :ready, :count).and_return(0)
        order.stub_chain(:shipments, :pending, :count).and_return(0)
      end

      it "is backordered" do
        order.stub :backordered? => true
        updater.update_shipment_state

        order.shipment_state.should == 'backorder'
      end

      it "is nil" do
        order.stub_chain(:shipments, :states).and_return([])
        order.stub_chain(:shipments, :count).and_return(0)
{'fraction_non_alphanumeric': 0.10832637148426622, 'fraction_numerical': 0.012809802283486493, 'mean_word_length': 2.8294243070362475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '360145', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1139, 'n_words': 235}