<commit_before># frozen_string_literal: true

require 'spec_helper'

module Spree
  describe Adjustment do
    let(:order) { build(:order) }
    let(:adjustment) { Spree::Adjustment.create(label: "Adjustment", amount: 5) }

    describe "scopes" do
      let!(:arbitrary_adjustment) { create(:adjustment, label: "Arbitrary") }
      let!(:return_authorization_adjustment) {
        create(:adjustment, originator: create(:return_authorization))
      }

      it "returns return_authorization adjustments" do
        expect(Spree::Adjustment.return_authorization.to_a).to eq [return_authorization_adjustment]
      end
    end

    context "#update_adjustment!" do
      context "when originator present" do
        let(:originator) { instance_double(EnterpriseFee, compute_amount: 10.0) }

        before do
          allow(adjustment).to receive_messages originator: originator, label: 'adjustment',
                                                amount: 0
        end

        it "should do nothing when closed" do
          adjustment.close
          expect(originator).not_to receive(:compute_amount)
          adjustment.update_adjustment!
        end

        it "should do nothing when finalized" do
          adjustment.finalize
          expect(originator).not_to receive(:compute_amount)
          adjustment.update_adjustment!
        end<commit_msg>Update adjustment unit tests<commit_after># frozen_string_literal: true

require 'spec_helper'

module Spree
  describe Adjustment do
    let(:order) { build(:order) }
    let(:adjustment) { Spree::Adjustment.create(label: "Adjustment", amount: 5) }

    describe "scopes" do
      let!(:arbitrary_adjustment) { create(:adjustment, label: "Arbitrary") }
      let!(:return_authorization_adjustment) {
        create(:adjustment, originator: create(:return_authorization))
      }

      it "returns return_authorization adjustments" do
        expect(Spree::Adjustment.return_authorization.to_a).to eq [return_authorization_adjustment]
      end
    end

    context "#update_adjustment!" do
      context "when originator present" do
        let(:originator) { instance_double(EnterpriseFee, compute_amount: 10.0) }
        let(:adjustable) { instance_double(LineItem) }

        before do
          allow(adjustment).to receive_messages originator: originator, label: 'adjustment',
                                                adjustable: adjustable, amount: 0
        end

        it "should do nothing when closed" do
          adjustment.close
          expect(originator).not_to receive(:compute_amount)
          adjustment.update_adjustment!
        end

        it "should do nothing when finalized" do
          adjustment.finalize
          expect(originator).not_to receive(:compute_amount)
          adjustment.update_adjustment!
        end
{'fraction_non_alphanumeric': 0.08687943262411348, 'fraction_numerical': 0.0035460992907801418, 'mean_word_length': 2.80188679245283, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4315662', 'n_tokens_mistral': 779, 'n_tokens_neox': 749, 'n_words': 176}