<commit_before>require 'spec_helper'

module Polyamorous
  describe JoinDependency do

    context 'with symbol joins' do
      subject { new_join_dependency Person, :articles => :comments }

      specify { subject.join_root.drop(1).should have(2).associations }
      specify { subject.join_root.drop(1).should be_all { |a| a.join_type == Arel::InnerJoin } }
    end

    context 'with has_many :through association' do
      subject { new_join_dependency Person, :authored_article_comments }

      specify { subject.join_root.drop(1).should have(1).association }
      specify { subject.join_root.drop(1).first.table_name.should eq 'comments' }
    end

    context 'with outer join' do
      subject { new_join_dependency Person, new_join(:articles, :outer) }

      specify { subject.join_root.drop(1).should have(1).association }
      specify { subject.join_root.drop(1).should be_all { |a| a.join_type == Arel::OuterJoin } }
    end

    context 'with nested outer joins' do
      subject { new_join_dependency Person, new_join(:articles, :outer) => new_join(:comments, :outer) }

      specify { subject.join_root.drop(1).should have(2).associations }
      specify { subject.join_root.drop(1).should be_all { |a| a.join_type == Arel::OuterJoin } }
    end

    context 'with polymorphic belongs_to join' do
      subject { new_join_dependency Note, new_join(:notable, :inner, Person) }

      specify { subject.join_root.drop(1).should have(1).association }
      specify { subject.join_root.drop(1).should be_all { |a| a.join_type == Arel::InnerJoin } }
      specify { subject.join_root.drop(1).first.table_name.should eq 'people' }

      it 'finds a join association respecting polymorphism' do
        parent = subject.join_root
        reflection = Note.reflect_on_association(:notable)
        subject.find_join_association_respecting_polymorphism(
          reflection, parent, Person
        ).should eq subject.join_root.drop(1).first
      end
    end

    context 'with polymorphic belongs_to join and nested symbol join' do
      subject { new_join_dependency Note, new_join(:notable, :inner, Person) => :comments }

      specify { subject.join_root.drop(1).should have(2).association }
      specify { subject.join_root.drop(1).should be_all { |a| a.join_type == Arel::InnerJoin } }
      specify { subject.join_root.drop(1).first.table_name.should eq 'people' }
      specify { subject.join_root.drop(1)[1].table_name.should eq 'comments' }
    end
  end
end<commit_msg>Drop join_type examples in join_dependecy_spec<commit_after>require 'spec_helper'

module Polyamorous
  describe JoinDependency do

    context 'with symbol joins' do
      subject { new_join_dependency Person, :articles => :comments }

      specify { subject.join_root.drop(1).should have(2).associations }
    end

    context 'with has_many :through association' do
      subject { new_join_dependency Person, :authored_article_comments }

      specify { subject.join_root.drop(1).should have(1).association }
      specify { subject.join_root.drop(1).first.table_name.should eq 'comments' }
    end

    context 'with outer join' do
      subject { new_join_dependency Person, new_join(:articles, :outer) }

      specify { subject.join_root.drop(1).should have(1).association }
    end

    context 'with nested outer joins' do
      subject { new_join_dependency Person, new_join(:articles, :outer) => new_join(:comments, :outer) }

      specify { subject.join_root.drop(1).should have(2).associations }
    end

    context 'with polymorphic belongs_to join' do
      subject { new_join_dependency Note, new_join(:notable, :inner, Person) }

      specify { subject.join_root.drop(1).should have(1).association }
      specify { subject.join_root.drop(1).first.table_name.should eq 'people' }

      it 'finds a join association respecting polymorphism' do
        parent = subject.join_root
        reflection = Note.reflect_on_association(:notable)
        subject.find_join_association_respecting_polymorphism(
          reflection, parent, Person
        ).should eq subject.join_root.drop(1).first
      end
    end

    context 'with polymorphic belongs_to join and nested symbol join' do
      subject { new_join_dependency Note, new_join(:notable, :inner, Person) => :comments }

      specify { subject.join_root.drop(1).should have(2).association }
      specify { subject.join_root.drop(1).first.table_name.should eq 'people' }
      specify { subject.join_root.drop(1)[1].table_name.should eq 'comments' }
    end
  end
end
{'fraction_non_alphanumeric': 0.10479964773227653, 'fraction_numerical': 0.009026860413914576, 'mean_word_length': 3.5612449799196786, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4810783', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1368, 'n_words': 315}