<commit_before>require 'test_helper'

module Dagnabit
  module Link
    class TestAssociations < ActiveRecord::TestCase
      class Node < ActiveRecord::Base
        set_table_name 'nodes'
      end

      class Link < ActiveRecord::Base
        set_table_name 'edges'
        acts_as_dag_link
      end

      class CustomLink < ActiveRecord::Base
        set_table_name 'other_name_edges'
        acts_as_dag_link :ancestor_id_column => 'the_ancestor_id',
                         :descendant_id_column => 'the_descendant_id',
                         :transitive_closure_table_name => 'my_transitive_closure'
      end

      def setup
        @node = Node.new
        @link = Link.new
        @custom_link = CustomLink.new
      end

      should 'add an ancestor association proxy' do
        @link.ancestor = @node
        @link.save
        assert_equal @node, @link.reload.ancestor
      end

      should 'add a descendant association proxy' do
        @link.descendant = @node
        @link.save
        assert_equal @node, @link.reload.descendant
      end

      should 'permit customization of the ancestor association foreign key' do
        @custom_link.ancestor = @node
        @custom_link.save<commit_msg>Test Dagnabit::Link::Associations in isolation.<commit_after>require 'test_helper'

module Dagnabit
  module Link
    class TestAssociations < ActiveRecord::TestCase
      class Node < ActiveRecord::Base
        set_table_name 'nodes'
      end

      class Link < ActiveRecord::Base
        set_table_name 'edges'
        extend Dagnabit::Link::Configuration
        configure_acts_as_dag_link({})
        extend Dagnabit::Link::Associations
      end

      class CustomLink < ActiveRecord::Base
        set_table_name 'other_name_edges'

        extend Dagnabit::Link::Configuration
        configure_acts_as_dag_link(:ancestor_id_column => 'the_ancestor_id',
                                   :descendant_id_column => 'the_descendant_id',
                                   :transitive_closure_table_name => 'my_transitive_closure')

        extend Dagnabit::Link::Associations
      end

      def setup
        @node = Node.new
        @link = Link.new
        @custom_link = CustomLink.new
      end

      should 'add an ancestor association proxy' do
        @link.ancestor = @node
        @link.save
        assert_equal @node, @link.reload.ancestor
      end

      should 'add a descendant association proxy' do
        @link.descendant = @node
        @link.save
        assert_equal @node, @link.reload.descendant
      end

      should 'permit customization of the ancestor association foreign key' do
        @custom_link.ancestor = @node
        @custom_link.save
{'fraction_non_alphanumeric': 0.07134935304990758, 'fraction_numerical': 0.0, 'mean_word_length': 2.283980582524272, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7645988', 'n_tokens_mistral': 778, 'n_tokens_neox': 748, 'n_words': 179}