<commit_before>require 'spec_helper'

describe Spree::Promotion::Actions::CreateLineItems do
  let(:order) { create(:order) }
  let(:action) { Spree::Promotion::Actions::CreateLineItems.create }

  context "#perform" do
    before do
      @v1 = create(:variant)
      @v2 = create(:variant)
      action.promotion_action_line_items.create!(
        :variant => @v1,
        :quantity => 1
      )
      action.promotion_action_line_items.create!(
        :variant => @v2,
        :quantity => 2
      )
    end

    context "order is eligible" do
      let(:mug) { create(:variant) }
      let(:shirt) { create(:variant) }

      before do
        action.stub(eligible?: true)

        action.promotion_action_line_items.create!({
          :variant => mug,
          :quantity => 1}, :without_protection => true
        )
        action.promotion_action_line_items.create!({
          :variant => shirt,
          :quantity => 2}, :without_protection => true
        )
      end

      it "adds line items to order with correct variant and quantity" do
        action.perform(:order => order)
        order.line_items.count.should == 2
        line_item = order.line_items.find_by_variant_id(mug.id)
        line_item.should_not be_nil
        line_item.quantity.should == 1
      end

      it "only adds the delta of quantity to an order" do
        order.contents.add(shirt, 1)
        action.perform(:order => order)<commit_msg>Fix setup in promotion/actions/create_line_items_spec<commit_after>require 'spec_helper'

describe Spree::Promotion::Actions::CreateLineItems do
  let(:order) { create(:order) }
  let(:action) { Spree::Promotion::Actions::CreateLineItems.create }
  let(:promotion) { stub_model(Spree::Promotion) }
  let(:shirt) { create(:variant) }
  let(:mug) { create(:variant) }

  context "#perform" do
    before do
      action.stub :promotion => promotion
      action.promotion_action_line_items.create!(
        :variant => mug,
        :quantity => 1
      )
      action.promotion_action_line_items.create!(
        :variant => shirt,
        :quantity => 2
      )
    end

    context "order is eligible" do
      before do
        promotion.stub :eligible => true
      end

      it "adds line items to order with correct variant and quantity" do
        action.perform(:order => order)
        order.line_items.count.should == 2
        line_item = order.line_items.find_by_variant_id(mug.id)
        line_item.should_not be_nil
        line_item.quantity.should == 1
      end

      it "only adds the delta of quantity to an order" do
        order.contents.add(shirt, 1)
        action.perform(:order => order)
{'fraction_non_alphanumeric': 0.11258027956176804, 'fraction_numerical': 0.006044578768417076, 'mean_word_length': 2.612551159618008, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '7589968', 'n_tokens_mistral': 816, 'n_tokens_neox': 780, 'n_words': 180}