From 44d214235271cb6d2af1c327d592a3010e1ced3e Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Fri, 25 Apr 2008 23:23:48 +0100 Subject: Ensure table names are quoted by the association preloading code. [#45 state:resolved] Signed-off-by: Michael Koziarski --- activerecord/test/cases/associations/eager_test.rb | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases/associations') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 0bc345428f..1a3017a22c 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -9,11 +9,13 @@ require 'models/person' require 'models/reader' require 'models/owner' require 'models/pet' +require 'models/reference' +require 'models/job' class EagerAssociationTest < ActiveRecord::TestCase fixtures :posts, :comments, :authors, :categories, :categories_posts, :companies, :accounts, :tags, :taggings, :people, :readers, - :owners, :pets, :author_favorites + :owners, :pets, :author_favorites, :jobs, :references def test_loading_with_one_association posts = Post.find(:all, :include => :comments) @@ -194,6 +196,30 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal authors(:mary), assert_no_queries { author_favorite.favorite_author } end + def test_eager_load_belongs_to_quotes_table_and_column_names + job = Job.find jobs(:unicyclist).id, :include => :ideal_reference + references(:michael_unicyclist) + assert_no_queries{ assert_equal references(:michael_unicyclist), job.ideal_reference} + end + + def test_eager_load_has_one_quotes_table_and_column_names + michael = Person.find(people(:michael), :include => :favourite_reference) + references(:michael_unicyclist) + assert_no_queries{ assert_equal references(:michael_unicyclist), michael.favourite_reference} + end + + def test_eager_load_has_many_quotes_table_and_column_names + michael = Person.find(people(:michael), :include => :references) + references(:michael_magician,:michael_unicyclist) + assert_no_queries{ assert_equal references(:michael_magician,:michael_unicyclist), michael.references.sort_by(&:id) } + end + + def test_eager_load_has_many_through_quotes_table_and_column_names + michael = Person.find(people(:michael), :include => :jobs) + jobs(:magician, :unicyclist) + assert_no_queries{ assert_equal jobs(:unicyclist, :magician), michael.jobs.sort_by(&:id) } + end + def test_eager_association_loading_with_explicit_join posts = Post.find(:all, :include => :comments, :joins => "INNER JOIN authors ON posts.author_id = authors.id AND authors.name = 'Mary'", :limit => 1, :order => 'author_id') assert_equal 1, posts.length -- cgit v1.2.3