From 98e69078d5e2fe9a13bd912bbb5da00be4d43497 Mon Sep 17 00:00:00 2001
From: Jan Habermann <jan@habermann24.com>
Date: Thu, 3 Apr 2014 01:52:42 +0200
Subject: Properly handle scoping with has_many :through. Fixes #14537.

---
 .../cases/associations/has_many_through_associations_test.rb | 12 ++++++++++++
 1 file changed, 12 insertions(+)

(limited to 'activerecord/test/cases/associations')

diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 026a7fe635..fee0d2c627 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -1105,4 +1105,16 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
   def test_has_many_through_with_includes_in_through_association_scope
     assert_not_empty posts(:welcome).author_address_extra_with_address
   end
+  
+  def test_has_many_through_unscope_default_scope
+    post = Post.create!(:title => 'Beaches', :body => "I like beaches!")
+    Reader.create! :person => people(:david), :post => post
+    LazyReader.create! :person => people(:susan), :post => post
+    
+    assert_equal 2, post.people.to_a.size
+    assert_equal 1, post.lazy_people.to_a.size
+    
+    assert_equal 2, post.lazy_readers_unscope_skimmers.to_a.size
+    assert_equal 2, post.lazy_people_unscope_skimmers.to_a.size
+  end
 end
-- 
cgit v1.2.3


From 8116411abcb7dd887f06a1fe63885e105ea862e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?=
 <rafael.franca@plataformatec.com.br>
Date: Tue, 22 Apr 2014 18:27:19 -0500
Subject: Fix syntax error

---
 .../test/cases/associations/has_many_through_associations_test.rb        | 1 +
 1 file changed, 1 insertion(+)

(limited to 'activerecord/test/cases/associations')

diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index e30577fb49..4755966259 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -1116,6 +1116,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
 
     club.reload
     assert_equal [member], club.favourites
+  end
 
   def test_has_many_through_unscope_default_scope
     post = Post.create!(:title => 'Beaches', :body => "I like beaches!")
-- 
cgit v1.2.3


From d10e2ca9f199105849444b39f55d4922339d9c8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?=
 <rafaelmfranca@gmail.com>
Date: Tue, 22 Apr 2014 18:29:16 -0500
Subject: Perfer to define methods instead of calling test

This file is using this pattern already
---
 .../test/cases/associations/has_many_through_associations_test.rb | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'activerecord/test/cases/associations')

diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 4755966259..e68ad74f70 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -1082,7 +1082,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
     assert_equal ["parrot", "bulbul"], owner.toys.map { |r| r.pet.name }
   end
 
-  test "has many through associations on new records use null relations" do
+  def test_has_many_through_associations_on_new_records_use_null_relations
     person = Person.new
 
     assert_no_queries do
@@ -1094,7 +1094,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
     end
   end
 
-  test "has many through with default scope on the target" do
+  def test_has_many_through_with_default_scope_on_the_target
     person = people(:michael)
     assert_equal [posts(:thinking)], person.first_posts
 
@@ -1102,11 +1102,11 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
     assert_equal [posts(:thinking)], person.reload.first_posts
   end
 
-  test "has many through with includes in through association scope" do
+  def test_has_many_through_with_includes_in_through_association_scope
     assert_not_empty posts(:welcome).author_address_extra_with_address
   end
 
-  test "insert records via has_many_through association with scope" do
+  def test_insert_records_via_has_many_through_association_with_scope
     club = Club.create!
     member = Member.create!
     Membership.create!(club: club, member: member)
-- 
cgit v1.2.3