<commit_before>require "metadata/ingest/translators/form_to_attributes"

describe Metadata::Ingest::Translators::FormToAttributes do
  before(:each) do
    # This has WAY too much setup - figure out something better!

    # Set up a translator map
    Metadata::Ingest::Translators::FormToAttributes.map = {
      title: {
        main: :title,
        alt: :alt_title,
      },

      creator: {
        creator: :creator,
        photographer: :photographer,
      },

      subject: {
        keyword: :subject,
        lcsh: :lcsh_subject,
      }
    }

    # Use the translator to set up form groups
    Metadata::Ingest::Form.internal_groups = Metadata::Ingest::Translators::FormToAttributes.form_groups

    # Set up a pre-populated form
    @filled_form = Metadata::Ingest::Form.new(
      "titles_attributes" => {
        "1" => {"type" => "main", "value" => "This is a main title"},
        "2" => {"type" => "alt", "value" => "alt 1"},
        "3" => {"type" => "alt", "value" => "alt 2"},
      },
      "creators_attributes" => {
        "1" => {"type" => "photographer", "value" => "Photographer Name"}
      },
      "subjects_attributes" => {
        "14325432" => {"type" => "keyword", "value" => "subject keyword"}
      }
    )
  end

  it "delegates a form's data to object attributes" do
    object = double("object")
    expect(object).to receive(:title=).with("This is a main title")
    expect(object).to receive(:alt_title=).with(["alt 1", "alt 2"])
    expect(object).to receive(:photographer=).with("Photographer Name")
    expect(object).to receive(:subject=).with("subject keyword")
    p @filled_form.associations
    Metadata::Ingest::Translators::FormToAttributes.from(@filled_form).to(object)
  end
end<commit_msg>Remove debug output<commit_after>require "metadata/ingest/translators/form_to_attributes"

describe Metadata::Ingest::Translators::FormToAttributes do
  before(:each) do
    # This has WAY too much setup - figure out something better!

    # Set up a translator map
    Metadata::Ingest::Translators::FormToAttributes.map = {
      title: {
        main: :title,
        alt: :alt_title,
      },

      creator: {
        creator: :creator,
        photographer: :photographer,
      },

      subject: {
        keyword: :subject,
        lcsh: :lcsh_subject,
      }
    }

    # Use the translator to set up form groups
    Metadata::Ingest::Form.internal_groups = Metadata::Ingest::Translators::FormToAttributes.form_groups

    # Set up a pre-populated form
    @filled_form = Metadata::Ingest::Form.new(
      "titles_attributes" => {
        "1" => {"type" => "main", "value" => "This is a main title"},
        "2" => {"type" => "alt", "value" => "alt 1"},
        "3" => {"type" => "alt", "value" => "alt 2"},
      },
      "creators_attributes" => {
        "1" => {"type" => "photographer", "value" => "Photo<NAME>"}
      },
      "subjects_attributes" => {
        "14325432" => {"type" => "keyword", "value" => "subject keyword"}
      }
    )
  end

  it "delegates a form's data to object attributes" do
    object = double("object")
    expect(object).to receive(:title=).with("This is a main title")
    expect(object).to receive(:alt_title=).with(["alt 1", "alt 2"])
    expect(object).to receive(:photographer=).with("Photographer Name")
    expect(object).to receive(:subject=).with("subject keyword")
    Metadata::Ingest::Translators::FormToAttributes.from(@filled_form).to(object)
  end
end
{'fraction_non_alphanumeric': 0.16108545034642033, 'fraction_numerical': 0.009237875288683603, 'mean_word_length': 3.100591715976331, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 40, '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': '4937841', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1071, 'n_words': 248}