<commit_before>require 'spec_helper'
require 'benchmark'

describe Spree::Shipment do
  let(:order) { mock_model Spree::Order, backordered?: false,
                                         canceled?: false,
                                         can_ship?: true,
                                         currency: 'USD' }
  let(:shipping_method) { create(:shipping_method, name: "UPS") }
  let(:shipment) do
    shipment = Spree::Shipment.new order: order
    shipment.stub(shipping_method: shipping_method)
    shipment.state = 'pending'
    shipment
  end

  let(:charge) { create(:adjustment) }
  let(:variant) { mock_model(Spree::Variant) }

  it 'is backordered if one if its inventory_units is backordered' do
    shipment.stub(inventory_units: [
      mock_model(Spree::InventoryUnit, backordered?: false),
      mock_model(Spree::InventoryUnit, backordered?: true)
    ])
    shipment.should be_backordered
  end

  context "#cost" do
    it "should return the amount of any shipping charges that it originated" do
      shipment.stub_chain :adjustment, amount: 10
      shipment.cost.should == 10
    end

    it "should return 0 if there are no relevant shipping adjustments" do
      shipment.cost.should == 0
    end
  end

  context "display_cost" do
    it "retuns a Spree::Money" do
      shipment.stub(:cost) { 21.22 }
      shipment.display_cost.should == Spree::Money.new(21.22)
    end
  end

  context "display_item_cost" do
    it "retuns a Spree::Money" do
      shipment.stub(:item_cost) { 21.22 }
      shipment.display_item_cost.should == Spree::Money.new(21.22)
    end
  end


  it "#item_cost" do
    shipment = create(:shipment, order: create(:order_with_totals))
    shipment.item_cost.should eql(10.0)
  end

  context "manifest" do
    let(:order) { Spree::Order.create }
    let(:variant) { create(:variant) }
    let!(:line_item) { order.contents.add variant }
    let!(:shipment) { order.create_proposed_shipments.first }

    it "returns variant expected" do
      expect(shipment.manifest.first.variant).to eq variant
    end

    context "variant was removed" do
      before { variant.product.destroy }

      it "still returns variant expected" do
        expect(shipment.manifest.first.variant).to eq variant<commit_msg>Remove Shipment#cost tests, replace with #amount tests<commit_after>require 'spec_helper'
require 'benchmark'

describe Spree::Shipment do
  let(:order) { mock_model Spree::Order, backordered?: false,
                                         canceled?: false,
                                         can_ship?: true,
                                         currency: 'USD' }
  let(:shipping_method) { create(:shipping_method, name: "UPS") }
  let(:shipment) do
    shipment = Spree::Shipment.new order: order
    shipment.stub(shipping_method: shipping_method)
    shipment.state = 'pending'
    shipment
  end

  let(:charge) { create(:adjustment) }
  let(:variant) { mock_model(Spree::Variant) }

  it 'is backordered if one if its inventory_units is backordered' do
    shipment.stub(inventory_units: [
      mock_model(Spree::InventoryUnit, backordered?: false),
      mock_model(Spree::InventoryUnit, backordered?: true)
    ])
    shipment.should be_backordered
  end

  context "display_amount" do
    it "retuns a Spree::Money" do
      shipment.stub(:amount) { 21.22 }
      shipment.display_amount.should == Spree::Money.new(21.22)
    end
  end

  context "display_item_cost" do
    it "retuns a Spree::Money" do
      shipment.stub(:item_cost) { 21.22 }
      shipment.display_item_cost.should == Spree::Money.new(21.22)
    end
  end

  it "#item_cost" do
    shipment = create(:shipment, order: create(:order_with_totals))
    shipment.item_cost.should eql(10.0)
  end

  context "manifest" do
    let(:order) { Spree::Order.create }
    let(:variant) { create(:variant) }
    let!(:line_item) { order.contents.add variant }
    let!(:shipment) { order.create_proposed_shipments.first }

    it "returns variant expected" do
      expect(shipment.manifest.first.variant).to eq variant
    end

    context "variant was removed" do
      before { variant.product.destroy }

      it "still returns variant expected" do
        expect(shipment.manifest.first.variant).to eq variant
{'fraction_non_alphanumeric': 0.10709253170502583, 'fraction_numerical': 0.010333489901362142, 'mean_word_length': 2.8788706739526413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6187548', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1288, 'n_words': 312}