<commit_before>require 'spec_helper'

describe Spree::Promotion::Actions::FreeShipping do
  let(:order) { create(:completed_order_with_totals) }
  let(:promotion) { create(:promotion) }
  let(:action) { Spree::Promotion::Actions::FreeShipping.create }

  # From promotion spec:
  context "#perform" do
    before do
      order.shipments << create(:shipment)
      promotion.promotion_actions << action
    end

    it "should create a discount with correct negative amount" do
      order.shipments.count.should == 2
      order.shipments.first.cost.should == 100
      order.shipments.last.cost.should == 100
      action.perform(:order => order).should be_true
      promotion.credits_count.should == 2
      order.shipment_adjustments.count.should == 2
      order.shipment_adjustments.first.amount.to_i.should == -100
      order.shipment_adjustments.last.amount.to_i.should == -100
    end

    it "should not create a discount when order already has one from this promotion" do
      action.perform(:order => order).should be_true
      action.perform(:order => order).should be_false
      promotion.credits_count.should == 1
      order.shipment_adjustments.count.should == 1
    end
  end
end<commit_msg>Free Shipping test actually works with 2 shipments; thus 2 adjustments<commit_after>require 'spec_helper'

describe Spree::Promotion::Actions::FreeShipping do
  let(:order) { create(:completed_order_with_totals) }
  let(:promotion) { create(:promotion) }
  let(:action) { Spree::Promotion::Actions::FreeShipping.create }

  # From promotion spec:
  context "#perform" do
    before do
      order.shipments << create(:shipment)
      promotion.promotion_actions << action
    end

    it "should create a discount with correct negative amount" do
      order.shipments.count.should == 2
      order.shipments.first.cost.should == 100
      order.shipments.last.cost.should == 100
      action.perform(:order => order).should be_true
      promotion.credits_count.should == 2
      order.shipment_adjustments.count.should == 2
      order.shipment_adjustments.first.amount.to_i.should == -100
      order.shipment_adjustments.last.amount.to_i.should == -100
    end

    it "should not create a discount when order already has one from this promotion" do
      action.perform(:order => order).should be_true
      action.perform(:order => order).should be_false
      promotion.credits_count.should == 2
      order.shipment_adjustments.count.should == 2
    end
  end
end
{'fraction_non_alphanumeric': 0.10422535211267606, 'fraction_numerical': 0.01448692152917505, 'mean_word_length': 3.578268876611418, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '136911', 'n_tokens_mistral': 757, 'n_tokens_neox': 717, 'n_words': 169}