From 48c95627aa3b9b6e4c117ca82c4b4ec172e942c8 Mon Sep 17 00:00:00 2001 From: wmoxam Date: Fri, 7 Aug 2009 22:29:48 -0400 Subject: [PATCH] Failing test for #2493 --- activerecord/test/cases/associations/eager_test.rb | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index d23f86b..6cde79b 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -193,6 +193,12 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal [1,2,3,5,6], comments.collect { |c| c.id } end + def test_eager_association_loading_with_belongs_to_and_limit_non_selected_order_by + posts = Post.find(:all, :include => :comments, :limit => 5, :order => 'comments.post_id') + assert_equal 5, posts.length + assert_equal [1,2,4,5,7], posts.collect { |p| p.id } + end + def test_eager_association_loading_with_belongs_to_and_limit_and_conditions comments = Comment.find(:all, :include => :post, :conditions => 'post_id = 4', :limit => 3, :order => 'comments.id') assert_equal 3, comments.length -- 1.5.5.3 From 9af953488c923ca018d9d9b73350095ab0732b26 Mon Sep 17 00:00:00 2001 From: wmoxam Date: Sat, 8 Aug 2009 20:30:35 -0400 Subject: [PATCH] Adds test as described in ticket #2493 --- .../abstract/schema_statements.rb | 17 +++++++++++++- activerecord/test/cases/associations/eager_test.rb | 11 ++++++++- activerecord/test/fixtures/aas.yml | 9 +++++++ activerecord/test/fixtures/bbs.yml | 24 ++++++++++++++++++++ activerecord/test/models/aa.rb | 3 ++ activerecord/test/models/bb.rb | 3 ++ activerecord/test/schema/schema.rb | 9 +++++++ 8 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 activerecord/test/fixtures/aas.yml create mode 100644 activerecord/test/fixtures/bbs.yml create mode 100644 activerecord/test/models/aa.rb create mode 100644 activerecord/test/models/bb.rb diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 6cde79b..6f8c187 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -17,9 +17,11 @@ require 'models/subscription' require 'models/book' require 'models/developer' require 'models/project' +require 'models/aa' +require 'models/bb' class EagerAssociationTest < ActiveRecord::TestCase - fixtures :posts, :comments, :authors, :author_addresses, :categories, :categories_posts, + fixtures :aas, :bbs, :posts, :comments, :authors, :author_addresses, :categories, :categories_posts, :companies, :accounts, :tags, :taggings, :people, :readers, :owners, :pets, :author_favorites, :jobs, :references, :subscribers, :subscriptions, :books, :developers, :projects, :developers_projects @@ -194,6 +196,13 @@ class EagerAssociationTest < ActiveRecord::TestCase end def test_eager_association_loading_with_belongs_to_and_limit_non_selected_order_by + puts Aa.find(:all, :include => :bbs, :order => 'bbs.position desc').collect { |p| p.id }.inspect + records = Aa.find(:all, :include => :bbs, :order => 'bbs.position desc', :limit => 2) + assert_equal 2, records.length + assert_equal [2,1], records.collect { |r| r.id } + + # This is actually a different problem, the order returned is [3, 6, 1, 2, 4], since posts 3 & 6 have + # no comments, so comments.post_id is NULL. In PostgresSQL 3 & 6 are ordered last posts = Post.find(:all, :include => :comments, :limit => 5, :order => 'comments.post_id') assert_equal 5, posts.length assert_equal [1,2,4,5,7], posts.collect { |p| p.id } diff --git a/activerecord/test/fixtures/aas.yml b/activerecord/test/fixtures/aas.yml new file mode 100644 index 0000000..b96a23e --- /dev/null +++ b/activerecord/test/fixtures/aas.yml @@ -0,0 +1,9 @@ +a1: + id: 1 + name: A1 +a2: + id: 2 + name: A2 +a3: + id: 3 + name: A3 diff --git a/activerecord/test/fixtures/bbs.yml b/activerecord/test/fixtures/bbs.yml new file mode 100644 index 0000000..c36875e --- /dev/null +++ b/activerecord/test/fixtures/bbs.yml @@ -0,0 +1,24 @@ +one: + id: 1 + aa_id: 1 + position: 1 +two: + id: 2 + aa_id: 1 + position: 4 +three: + id: 3 + aa_id: 2 + position: 6 +four: + id: 4 + aa_id: 2 + position: 2 +five: + id: 5 + aa_id: 2 + position: 5 +six: + id: 6 + aa_id: 3 + position: 3 diff --git a/activerecord/test/models/aa.rb b/activerecord/test/models/aa.rb new file mode 100644 index 0000000..15bc55e --- /dev/null +++ b/activerecord/test/models/aa.rb @@ -0,0 +1,3 @@ +class Aa < ActiveRecord::Base + has_many :bbs, :select => 'id, position, aa_id' +end diff --git a/activerecord/test/models/bb.rb b/activerecord/test/models/bb.rb new file mode 100644 index 0000000..06acdfb --- /dev/null +++ b/activerecord/test/models/bb.rb @@ -0,0 +1,3 @@ +class Bb < ActiveRecord::Base + belongs_to :aa +end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index d080140..39de989 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -21,6 +21,10 @@ ActiveRecord::Schema.define do # Please keep these create table statements in alphabetical order # unless the ordering matters. In which case, define them below + create_table :aas, :force => true do |t| + t.string :name + end + create_table :accounts, :force => true do |t| t.integer :firm_id t.integer :credit_limit @@ -51,6 +55,11 @@ ActiveRecord::Schema.define do t.integer :value end + create_table :bbs, :force => true do |t| + t.integer :aa_id + t.integer :position + end + create_table :binaries, :force => true do |t| t.binary :data end -- 1.5.5.3