Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9167: test_eager_with_conditional_properly_counts_the_records_stable.diff

File test_eager_with_conditional_properly_counts_the_records_stable.diff, 2.3 kB (added by danger, 1 year ago)

Patch for the 1-2 stable branch

  • activerecord/test/associations/eager_test.rb

    old new  
    271271    assert_not_nil f.account 
    272272    assert_equal companies(:first_firm, :reload).account, f.account 
    273273  end 
     274   
     275  def test_eager_with_multi_table_conditional_properly_counts_the_records_when_using_size 
     276    author = authors(:david) 
     277    posts_with_no_comments = author.posts.select { |post| post.comments.blank? } 
     278    assert_equal posts_with_no_comments.size, author.posts_with_no_comments.size 
     279    assert_equal posts_with_no_comments, author.posts_with_no_comments 
     280  end 
    274281 
    275282  def test_eager_with_invalid_association_reference 
    276283    assert_raises(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it?  You specified :include => :monkeys") { 
  • activerecord/test/fixtures/author.rb

    old new  
    2525 
    2626  has_many :hello_posts, :class_name => "Post", :conditions => "posts.body = 'hello'" 
    2727  has_many :hello_post_comments, :through => :hello_posts, :source => :comments 
     28  has_many :posts_with_no_comments, :class_name => 'Post', :conditions => 'comments.id is null', :include => :comments 
    2829 
    2930  has_many :other_posts,          :class_name => "Post" 
    3031  has_many :posts_with_callbacks, :class_name => "Post", :before_add => :log_before_adding, 
  • activerecord/lib/active_record/associations/has_many_association.rb

    old new  
    138138          elsif @reflection.options[:counter_sql] 
    139139            @reflection.klass.count_by_sql(@counter_sql) 
    140140          else 
    141             @reflection.klass.count(:conditions => @counter_sql
     141            @reflection.klass.count(:conditions => @counter_sql, :include => @reflection.options[:include]
    142142          end 
    143143           
    144144          @target = [] and loaded if count == 0