<commit_before>require 'test_helper'

class SharedAttachmentTest < Zena::Unit::TestCase
  self.use_transactional_fixtures = false

  Attachment = Class.new(Zena::Use::SharedAttachment::Attachment) do
    def filepath
      File.join(RAILS_ROOT, 'tmp', 'attachments', super)
    end
  end

  # Mock a document class with many versions
  class Document < ActiveRecord::Base
    include Zena::Use::MultiVersion

    set_table_name :nodes
    before_save :set_dummy_defaults

    def title=(title)
      version.title = title
    end

    def file=(file)
      version.file = file
    end

    def version
      @version ||= new_record? ? versions.build : versions.first(:order => 'id DESC')
    end
    private
      def set_dummy_defaults
        self[:user_id] ||= 0
      end
  end

  # Mock a version class with shared attachments (between versions of the same document)
  class Version < ActiveRecord::Base
    include Zena::Use::MultiVersion::Version
    include Zena::Use::AutoVersion
    include Zena::Use::SharedAttachment
    set_attachment_class 'SharedAttachmentTest::Attachment'
    set_table_name :versions

    def should_clone?
      true
    end

    private
      def setup_version_on_create
        # Dummy values when testing Version without a Document
        self[:node_id] ||= 0
        self[:user_id] ||= 0
        self[:status]  ||= 0
      end
  end

  def setup<commit_msg>Get rid off should_clone? in SharedAttachment Test.<commit_after>require 'test_helper'

class SharedAttachmentTest < Zena::Unit::TestCase
  self.use_transactional_fixtures = false

  Attachment = Class.new(Zena::Use::SharedAttachment::Attachment) do
    def filepath
      File.join(RAILS_ROOT, 'tmp', 'attachments', super)
    end
  end

  # Mock a document class with many versions
  class Document < ActiveRecord::Base
    include Zena::Use::MultiVersion

    set_table_name :nodes
    before_save :set_dummy_defaults

    def title=(title)
      version.title = title
    end

    def file=(file)
      version.file = file
    end

    def version
      @version ||= new_record? ? versions.build : versions.first(:order => 'id DESC')
    end
    private
      def set_dummy_defaults
        self[:user_id] ||= 0
      end
  end

  # Mock a version class with shared attachments (between versions of the same document)
  class Version < ActiveRecord::Base
    include Zena::Use::MultiVersion::Version
    include Zena::Use::AutoVersion
    include Zena::Use::SharedAttachment
    set_attachment_class 'SharedAttachmentTest::Attachment'
    set_table_name :versions

    private
      def setup_version_on_create
        # Dummy values when testing Version without a Document
        self[:node_id] ||= 0
        self[:user_id] ||= 0
        self[:status]  ||= 0
      end
  end

  def setup
{'fraction_non_alphanumeric': 0.08566308243727598, 'fraction_numerical': 0.002867383512544803, 'mean_word_length': 3.15946348733234, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '6097875', 'n_tokens_mistral': 826, 'n_tokens_neox': 806, 'n_words': 223}