diff options
author | Frederick Cheung <frederick.cheung@gmail.com> | 2008-04-25 23:23:48 +0100 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-04-26 12:14:50 +1200 |
commit | 44d214235271cb6d2af1c327d592a3010e1ced3e (patch) | |
tree | 5db346cc10ff1dab291e62545a2480a819271f74 /activerecord/test/cases | |
parent | a37546517dad9f6d9a7de6e1dba4d960909d71e8 (diff) | |
download | rails-44d214235271cb6d2af1c327d592a3010e1ced3e.tar.gz rails-44d214235271cb6d2af1c327d592a3010e1ced3e.tar.bz2 rails-44d214235271cb6d2af1c327d592a3010e1ced3e.zip |
Ensure table names are quoted by the association preloading code.
[#45 state:resolved]
Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 28 |
1 files changed, 27 insertions, 1 deletions
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 |