<commit_before>require_relative 'test_helper'

module MongoidModelMaker
  class YamlLoaderTest < MiniTest::Unit::TestCase
    def test_scaffolds
      @models = MongoidModelMaker::Models.new File.join( __dir__, "fixtures/double_model.yaml" )
      Rails::Generators.expects(:invoke).with("rails:scaffold", %w(person first:string last:string --timestamps))
      Rails::Generators.expects(:invoke).with("rails:scaffold", %w(dog name:string breed:string --timestamps))
      @models.run_scaffolds
    end

    def test_relations
      @models = MongoidModelMaker::Models.new File.join( __dir__, "fixtures/double_model.yaml" )
      Rails::Generators.expects(:invoke)
        .with("mongoid_model_maker:relation", %w(--child=dog --parent=person --relation=embeds_many))
      @models.run_relations
    end

    def test_relations_with_synonyms
      @models = MongoidModelMaker::Models.new File.join( __dir__, "fixtures/double_model_with_synonyms.yaml" )
      Rails::Generators.expects(:invoke)
        .with("mongoid_model_maker:relation", %w(--child=dog --parent=person --relation=embeds_many --child_synonym=doggie))
      @models.run_relations
    end

    def test_relations_with_validations
      @models = MongoidModelMaker::Models.new File.join( __dir__, "fixtures/double_model_with_validations.yaml" )
      Rails::Generators.expects(:invoke)<commit_msg>added a comment documenting the use of semicolons in the relation generator<commit_after>require_relative 'test_helper'

module MongoidModelMaker
  class YamlLoaderTest < MiniTest::Unit::TestCase
    def test_scaffolds
      @models = MongoidModelMaker::Models.new File.join( __dir__, "fixtures/double_model.yaml" )
      Rails::Generators.expects(:invoke).with("rails:scaffold", %w(person first:string last:string --timestamps))
      Rails::Generators.expects(:invoke).with("rails:scaffold", %w(dog name:string breed:string --timestamps))
      @models.run_scaffolds
    end

    def test_relations
      @models = MongoidModelMaker::Models.new File.join( __dir__, "fixtures/double_model.yaml" )
      Rails::Generators.expects(:invoke)
        .with("mongoid_model_maker:relation", %w(--child=dog --parent=person --relation=embeds_many))
      @models.run_relations
    end

    def test_relations_with_synonyms
      @models = MongoidModelMaker::Models.new File.join( __dir__, "fixtures/double_model_with_synonyms.yaml" )
      Rails::Generators.expects(:invoke)
        .with("mongoid_model_maker:relation", %w(--child=dog --parent=person --relation=embeds_many --child_synonym=doggie))
      @models.run_relations
    end

    ### IMPORTANT
    # This test specifies that multiple validations be semicolon delimited.
    # This is because of an unusual bug where the input after the first line
    # was being ignored.
    def test_relations_with_validations
      @models = MongoidModelMaker::Models.new File.join( __dir__, "fixtures/double_model_with_validations.yaml" )
      Rails::Generators.expects(:invoke)
{'fraction_non_alphanumeric': 0.11476510067114094, 'fraction_numerical': 0.0, 'mean_word_length': 4.530612244897959, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7453755', 'n_tokens_mistral': 952, 'n_tokens_neox': 927, 'n_words': 163}