<commit_before>require 'spec_helper'

RSpec.describe Hyrax::Actors::TransactionalRequest do
  let(:bad_actor) do
    Class.new(Hyrax::Actors::AbstractActor) do
      def create(attributes)
        next_actor.create(attributes) && raise('boom')
      end
    end
  end

  let(:actor_stack) do
    Hyrax::Actors::ActorStack.new(work, ::Ability.new(depositor), [described_class,
                                                                   bad_actor,
                                                                   Hyrax::Actors::InitializeWorkflowActor])
  end

  let(:depositor) { create(:user) }
  let(:work) { create(:work) }

  describe "create" do
    subject { actor_stack.create({}) }

    it "rolls back any database changes" do
      expect do
        expect { subject }.to raise_error 'boom'
      end.not_to change { Sipity::Entity.count }
    end
  end<commit_msg>Minimizing unit tests hit of services<commit_after>require 'spec_helper'

RSpec.describe Hyrax::Actors::TransactionalRequest do
  let(:bad_actor) do
    Class.new(Hyrax::Actors::AbstractActor) do
      def create(attributes)
        next_actor.create(attributes) && raise('boom')
      end
    end
  end

  let(:good_actor) do
    Class.new(Hyrax::Actors::AbstractActor) do
      def create(_attributes)
        FactoryGirl.create(:user)
      end
    end
  end

  let(:actor_stack) do
    Hyrax::Actors::ActorStack.new(work, ::Ability.new(depositor), [described_class,
                                                                   bad_actor,
                                                                   good_actor])
  end

  let(:depositor) { instance_double(User, new_record?: true, guest?: true, id: nil) }
  let(:work) { double(:work) }

  describe "create" do
    subject { actor_stack.create({}) }

    it "rolls back any database changes" do
      expect do
        expect { subject }.to raise_error 'boom'
      end.not_to change { User.count } # Note the above good actor creates a user
    end
  end
{'fraction_non_alphanumeric': 0.10284573140289566, 'fraction_numerical': 0.0, 'mean_word_length': 2.111801242236025, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6739454', 'n_tokens_mistral': 584, 'n_tokens_neox': 562, 'n_words': 132}