<commit_before>ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'webmock/test_unit'

require 'fixtures/factories'
require 'fixtures/mock_book_metadata_lookup'

require 'mocha/setup'

DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean

WebMock.disable_net_connect!

include Warden::Test::Helpers

class ActiveSupport::TestCase
  def setup
    DatabaseCleaner.start
    Book.metadata_lookup = MockBookMetadataLookup.new # stub the metadata lookup class in tests
  end

  def teardown
    DatabaseCleaner.clean
  end

  def login_as_stub_user
    @user = FactoryGirl.create(:user, :name => '<NAME>')
    request.env['warden'] = stub(:authenticate! => true, :authenticated? => true, :user => @user)
  end
end<commit_msg>Add test helper method for using paper_trail<commit_after>ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'webmock/test_unit'

require 'fixtures/factories'
require 'fixtures/mock_book_metadata_lookup'

require 'mocha/setup'

DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean

WebMock.disable_net_connect!

include Warden::Test::Helpers

class ActiveSupport::TestCase
  def setup
    DatabaseCleaner.start
    Book.metadata_lookup = MockBookMetadataLookup.new # stub the metadata lookup class in tests
  end

  def teardown
    DatabaseCleaner.clean
  end

  def login_as_stub_user
    @user = FactoryGirl.create(:user, :name => '<NAME>')
    request.env['warden'] = stub(:authenticate! => true, :authenticated? => true, :user => @user)
  end

  # https://github.com/airblade/paper_trail#globally
  def with_versioning
    was_enabled = PaperTrail.enabled?
    PaperTrail.enabled = true
    begin
      yield
    ensure
      PaperTrail.enabled = was_enabled
    end
  end
end
{'fraction_non_alphanumeric': 0.10693175711982805, 'fraction_numerical': 0.0, 'mean_word_length': 4.746913580246914, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 1, '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': '2715663', 'n_tokens_mistral': 601, 'n_tokens_neox': 589, 'n_words': 129}