aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-04-30 23:30:50 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-04-30 23:30:50 -0500
commit6f20efdaf733db26fbf337da73121983785064d5 (patch)
tree18dbb4c1dde8b2862df67502d1a9b8ca224d5fc3 /activerecord/test
parent1eb686a0e5944d99d40bc8ab8039e4179ed78cf7 (diff)
downloadrails-6f20efdaf733db26fbf337da73121983785064d5.tar.gz
rails-6f20efdaf733db26fbf337da73121983785064d5.tar.bz2
rails-6f20efdaf733db26fbf337da73121983785064d5.zip
Fixed AssociationsPreload such that it doesnt require foreign keys to be integers (fcheung) [#33 state:resolved]
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb23
-rw-r--r--activerecord/test/models/subscriber.rb2
-rw-r--r--activerecord/test/schema/schema.rb5
3 files changed, 29 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 1a3017a22c..546ed80894 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -11,11 +11,14 @@ require 'models/owner'
require 'models/pet'
require 'models/reference'
require 'models/job'
+require 'models/subscriber'
+require 'models/subscription'
+require 'models/book'
class EagerAssociationTest < ActiveRecord::TestCase
fixtures :posts, :comments, :authors, :categories, :categories_posts,
:companies, :accounts, :tags, :taggings, :people, :readers,
- :owners, :pets, :author_favorites, :jobs, :references
+ :owners, :pets, :author_favorites, :jobs, :references, :subscribers, :subscriptions, :books
def test_loading_with_one_association
posts = Post.find(:all, :include => :comments)
@@ -220,6 +223,24 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_no_queries{ assert_equal jobs(:unicyclist, :magician), michael.jobs.sort_by(&:id) }
end
+ def test_eager_load_has_many_with_string_keys
+ subscriptions = subscriptions(:webster_awdr, :webster_rfr)
+ subscriber =Subscriber.find(subscribers(:second).id, :include => :subscriptions)
+ assert_equal subscriptions, subscriber.subscriptions.sort_by(&:id)
+ end
+
+ def test_eager_load_has_many_through_with_string_keys
+ books = books(:awdr, :rfr)
+ subscriber = Subscriber.find(subscribers(:second).id, :include => :books)
+ assert_equal books, subscriber.books.sort_by(&:id)
+ end
+
+ def test_eager_load_belongs_to_with_string_keys
+ subscriber = subscribers(:second)
+ subscription = Subscription.find(subscriptions(:webster_awdr).id, :include => :subscriber)
+ assert_equal subscriber, subscription.subscriber
+ 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
diff --git a/activerecord/test/models/subscriber.rb b/activerecord/test/models/subscriber.rb
index 51335a8f20..5b78014e6f 100644
--- a/activerecord/test/models/subscriber.rb
+++ b/activerecord/test/models/subscriber.rb
@@ -1,5 +1,7 @@
class Subscriber < ActiveRecord::Base
set_primary_key 'nick'
+ has_many :subscriptions
+ has_many :books, :through => :subscriptions
end
class SpecialSubscriber < Subscriber
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index e22b78749c..818237f076 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -349,6 +349,11 @@ ActiveRecord::Schema.define do
end
add_index :subscribers, :nick, :unique => true
+ create_table :subscriptions, :force => true do |t|
+ t.string :subscriber_id
+ t.integer :book_id
+ end
+
create_table :tasks, :force => true do |t|
t.datetime :starting
t.datetime :ending