aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2015-03-18 08:04:21 -0400
committereileencodes <eileencodes@gmail.com>2015-03-18 08:13:54 -0400
commit4df806f95f8c64c8a1406aebf5f82807ff76c611 (patch)
tree9c4f0cc7aa8c89526026c97399de6d82d66ac3f1 /activerecord
parentcce5126eb28764cc6dee2a9f92e2edcec4715fbe (diff)
downloadrails-4df806f95f8c64c8a1406aebf5f82807ff76c611.tar.gz
rails-4df806f95f8c64c8a1406aebf5f82807ff76c611.tar.bz2
rails-4df806f95f8c64c8a1406aebf5f82807ff76c611.zip
Improve test for leaky scope chain
This is a better test for 51660f0. It is testing that the SQL is the same before and after the previously leaky scope is called. Before if `hotel.drink_designers` was called first then `hotel.recipes` would incorrectly get the scope applied. We want to be sure that the polymorphic hm:t association is not leaking into or affecting the SQL for the hm:t association on `Hotel`. The reason I couldn't do this before was because there was an issue with the SQL getting cached and wanted to resolve that later and then fix the test to be better. Because of the caching, this test requires that `Hotel.reflect_on_association(:recipes).clear_association_scope_cache` be called after the first call to `hotel.recipes` to clear the assocation scope chain and not interfere with the rest of the test.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/reflection_test.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb
index 06bc70c172..7b47c80331 100644
--- a/activerecord/test/cases/reflection_test.rb
+++ b/activerecord/test/cases/reflection_test.rb
@@ -284,8 +284,14 @@ class ReflectionTest < ActiveRecord::TestCase
drink = department.chefs.create!(employable: DrinkDesigner.create!)
Recipe.create!(chef_id: drink.id, hotel_id: hotel.id)
+ expected_sql = capture_sql { hotel.recipes.to_a }
+
+ Hotel.reflect_on_association(:recipes).clear_association_scope_cache
+ hotel.reload
hotel.drink_designers.to_a
- assert_sql(/^(?!.*employable_type).*$/) { hotel.recipes.to_a }
+ loaded_sql = capture_sql { hotel.recipes.to_a }
+
+ assert_equal expected_sql, loaded_sql
end
def test_nested?