<commit_before>require 'paperclip'
require 'paperclip/railtie'
# require 'filemagic'
require 'paperclip-optimizer'

require 'rspec'
require 'rspec/autorun'

require "active_record"

# taken from https://github.com/tienle/docsplit-paperclip-processor/blob/master/spec/spec_helper.rb

ActiveRecord::Base.establish_connection(
  "adapter" => "sqlite3",
  "database" => ":memory:"
)

ActiveRecord::Base.logger = Logger.new(nil)
load(File.join(File.dirname(__FILE__), 'schema.rb'))

Paperclip::Railtie.insert

class Upload < ActiveRecord::Base
  self.table_name = "uploads"

  has_attached_file :image,
      :storage    => :filesystem,
      :path       => "./spec/tmp/:id.:extension",
      :url        => "/spec/tmp/:id.:extension",
      :styles     => lambda { |attachment| attachment.instance.style_settings },
      :processors => lambda { |instance| instance.processor_settings }

  do_not_validate_attachment_file_type :image

  def style_settings
    { 
      medium: { geometry: "500x500>" }
    }
  end

  def processor_settings
    [:thumbnail]
  end
end

def get_fixture(file_type = :jpg, valid = "valid")
  file_name     = "#{valid}.#{file_type.to_s}"
  fixtures_dir  = File.join(File.dirname(__FILE__), "../fixtures")
  fixture_path  = File.join(fixtures_dir, file_name)
<commit_msg>Guard against older versions of Paperclip<commit_after>require 'paperclip'
require 'paperclip/railtie'
# require 'filemagic'
require 'paperclip-optimizer'

require 'rspec'
require 'rspec/autorun'

require "active_record"

# taken from https://github.com/tienle/docsplit-paperclip-processor/blob/master/spec/spec_helper.rb

ActiveRecord::Base.establish_connection(
  "adapter" => "sqlite3",
  "database" => ":memory:"
)

ActiveRecord::Base.logger = Logger.new(nil)
load(File.join(File.dirname(__FILE__), 'schema.rb'))

Paperclip::Railtie.insert

class Upload < ActiveRecord::Base
  self.table_name = "uploads"

  has_attached_file :image,
      :storage    => :filesystem,
      :path       => "./spec/tmp/:id.:extension",
      :url        => "/spec/tmp/:id.:extension",
      :styles     => lambda { |attachment| attachment.instance.style_settings },
      :processors => lambda { |instance| instance.processor_settings }

  if self.respond_to?(:do_not_validate_attachment_file_type)
    do_not_validate_attachment_file_type :image
  end

  def style_settings
    { 
      medium: { geometry: "500x500>" }
    }
  end

  def processor_settings
    [:thumbnail]
  end
end

def get_fixture(file_type = :jpg, valid = "valid")
  file_name     = "#{valid}.#{file_type.to_s}"
  fixtures_dir  = File.join(File.dirname(__FILE__), "../fixtures")
  fixture_path  = File.join(fixtures_dir, file_name)

{'fraction_non_alphanumeric': 0.13891992551210428, 'fraction_numerical': 0.0052141527001862194, 'mean_word_length': 4.125954198473282, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '5406246', 'n_tokens_mistral': 914, 'n_tokens_neox': 891, 'n_words': 156}