<commit_before>require "cases/helper"
require 'models/post'
require 'models/person'
require 'models/reference'
require 'models/job'
require 'models/reader'
require 'models/comment'
require 'models/rating'
require 'models/tag'
require 'models/tagging'
require 'models/author'
require 'models/owner'
require 'models/pet'
require 'models/toy'
require 'models/contract'
require 'models/company'
require 'models/developer'
require 'models/subscriber'
require 'models/book'
require 'models/subscription'
require 'models/essay'
require 'models/category'
require 'models/categorization'
require 'models/member'
require 'models/membership'
require 'models/club'

class HasManyThroughAssociationsTest < ActiveRecord::TestCase
  fixtures :posts, :readers, :people, :comments, :authors, :categories, :taggings, :tags,
           :owners, :pets, :toys, :jobs, :references, :companies, :members, :author_addresses,
           :subscribers, :books, :subscriptions, :developers, :categorizations, :essays

  # Dummies to force column loads so query counts are clean.
  def setup
    Person.create :first_name => 'gummy'
    Reader.create :person_id => 0, :post_id => 0
  end

  def test_include?
    person = Person.new
    post = Post.new
    person.posts << post
    assert person.posts.include?(post)
  end

  def test_associate_existing
    post   = posts(:thinking)
    person = people(:david)

    assert_queries(1) do
      post.people << person
    end

    assert_queries(1) do
      assert post.people.include?(person)
    end

    assert post.reload.people(true).include?(person)
  end

  def test_delete_all_for_with_dependent_option_destroy
    person = people(:david)
    assert_equal 1, person.jobs_with_dependent_destroy.count

    assert_no_difference 'Job.count' do
      assert_difference 'Reference.count', -1 do
        person.reload.jobs_with_dependent_destroy.delete_all
      end
    end
  end

  def test_delete_all_for_with_dependent_option_nullify
    person = people(:david)
    assert_equal 1, person.jobs_with_dependent_nullify.count

    assert_no_difference 'Job.count' do
      assert_no_difference 'Reference.count' do
        person.reload.jobs_with_dependent_nullify.delete_all
      end
    end
  end

  def test_delete_all_for_with_dependent_option_delete_all
    person = people(:david)
    assert_equal 1, person.jobs_with_dependent_delete_all.count

    assert_no_difference 'Job.count' do
      assert_difference 'Reference.count', -1 do
        person.reload.jobs_with_dependent_delete_all.delete_all
      end
    end
  end

<commit_msg>add a test for concat on hm:t associations<commit_after>require "cases/helper"
require 'models/post'
require 'models/person'
require 'models/reference'
require 'models/job'
require 'models/reader'
require 'models/comment'
require 'models/rating'
require 'models/tag'
require 'models/tagging'
require 'models/author'
require 'models/owner'
require 'models/pet'
require 'models/toy'
require 'models/contract'
require 'models/company'
require 'models/developer'
require 'models/subscriber'
require 'models/book'
require 'models/subscription'
require 'models/essay'
require 'models/category'
require 'models/categorization'
require 'models/member'
require 'models/membership'
require 'models/club'

class HasManyThroughAssociationsTest < ActiveRecord::TestCase
  fixtures :posts, :readers, :people, :comments, :authors, :categories, :taggings, :tags,
           :owners, :pets, :toys, :jobs, :references, :companies, :members, :author_addresses,
           :subscribers, :books, :subscriptions, :developers, :categorizations, :essays

  # Dummies to force column loads so query counts are clean.
  def setup
    Person.create :first_name => 'gummy'
    Reader.create :person_id => 0, :post_id => 0
  end

  def test_include?
    person = Person.new
    post = Post.new
    person.posts << post
    assert person.posts.include?(post)
  end

  def test_associate_existing
    post   = posts(:thinking)
    person = people(:david)

    assert_queries(1) do
      post.people << person
    end

    assert_queries(1) do
      assert post.people.include?(person)
    end

    assert post.reload.people(true).include?(person)
  end

  def test_delete_all_for_with_dependent_option_destroy
    person = people(:david)
    assert_equal 1, person.jobs_with_dependent_destroy.count

    assert_no_difference 'Job.count' do
      assert_difference 'Reference.count', -1 do
        person.reload.jobs_with_dependent_destroy.delete_all
      end
    end
  end

  def test_delete_all_for_with_dependent_option_nullify
    person = people(:david)
    assert_equal 1, person.jobs_with_dependent_nullify.count

    assert_no_difference 'Job.count' do
      assert_no_difference 'Reference.count' do
        person.reload.jobs_with_dependent_nullify.delete_all
      end
    end
  end

  def test_delete_all_for_with_dependent_option_delete_all
    person = people(:david)
    assert_equal 1, person.jobs_with_dependent_delete_all.count

    assert_no_difference 'Job.count' do
      assert_difference 'Reference.count', -1 do
        person.reload.jobs_with_dependent_delete_all.delete_all
      end
    end
  end

  def test_concat
    person = people(:david)
    post   = posts(:thinking)
    post.people.concat [person]
    assert_equal 1, post.people.size
    assert_equal 1, post.people(true).size
  end

{'fraction_non_alphanumeric': 0.09209788903418643, 'fraction_numerical': 0.0037362226788716607, 'mean_word_length': 4.094196003805899, 'pattern_counts': {'":': 0, '<': 13, '<?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': '3837320', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1661, 'n_words': 386}