<commit_before>require "cases/helper"
require 'models/post'
require 'models/person'
require 'models/reader'

class HasManyThroughAssociationsTest < ActiveRecord::TestCase
  fixtures :posts, :readers, :people

  def test_associate_existing
    assert_queries(2) { posts(:thinking);people(:david) }
    
    assert_queries(1) do
       posts(:thinking).people << people(:david)
    end
    
    assert_queries(1) do
      assert posts(:thinking).people.include?(people(:david))
    end
    
    assert posts(:thinking).reload.people(true).include?(people(:david))
  end

  def test_associating_new
    assert_queries(1) { posts(:thinking) }
    new_person = nil # so block binding catches it
    
    assert_queries(0) do
      new_person = Person.new :first_name => 'bob'
    end<commit_msg>Fix HasManyThroughAssociationsTest tests. [#733 state:resolved]<commit_after>require "cases/helper"
require 'models/post'
require 'models/person'
require 'models/reader'
require 'models/comment'

class HasManyThroughAssociationsTest < ActiveRecord::TestCase
  fixtures :posts, :readers, :people, :comments

  def test_associate_existing
    assert_queries(2) { posts(:thinking);people(:david) }

    posts(:thinking).people

    assert_queries(1) do
      posts(:thinking).people << people(:david)
    end
    
    assert_queries(1) do
      assert posts(:thinking).people.include?(people(:david))
    end
    
    assert posts(:thinking).reload.people(true).include?(people(:david))
  end

  def test_associating_new
    assert_queries(1) { posts(:thinking) }
    new_person = nil # so block binding catches it
    
    assert_queries(0) do
      new_person = Person.new :first_name => 'bob'
    end
{'fraction_non_alphanumeric': 0.11479289940828402, 'fraction_numerical': 0.007692307692307693, 'mean_word_length': 4.093373493975903, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '6891375', 'n_tokens_mistral': 544, 'n_tokens_neox': 521, 'n_words': 107}