aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-04-11 15:13:36 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-04-11 15:13:36 -0300
commitd447eef20b674b3fb5da4429af6ee23233ef3d8a (patch)
tree8d5ba7e5a1e5e87eb12bf918bc7f1d00233ed61e /activerecord/test
parent7bb8fd2f641c3416522e647ed32a3142ccc1e01b (diff)
parent70fffaccfc9761498cb50537d8b29c2e5d0585d1 (diff)
downloadrails-d447eef20b674b3fb5da4429af6ee23233ef3d8a.tar.gz
rails-d447eef20b674b3fb5da4429af6ee23233ef3d8a.tar.bz2
rails-d447eef20b674b3fb5da4429af6ee23233ef3d8a.zip
Merge pull request #14711 from swoker/activerecord_fix_aggregate_methods_with_select
Activerecord fix aggregate methods with select
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb8
-rw-r--r--activerecord/test/cases/relations_test.rb10
2 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 8c9797861c..3133f60bcf 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -1197,7 +1197,15 @@ class EagerAssociationTest < ActiveRecord::TestCase
author = Author.includes(:posts).references(:posts).reorder(:name).find_by('posts.title IS NOT NULL')
assert_equal authors(:bob), author
end
+
+ test "preloading with a polymorphic association and using the existential predicate but also using a select" do
+ assert_equal authors(:david), authors(:david).essays.includes(:writer).first.writer
+ assert_nothing_raised do
+ authors(:david).essays.includes(:writer).select(:name).any?
+ end
+ end
+
test "preloading with a polymorphic association and using the existential predicate" do
assert_equal authors(:david), authors(:david).essays.includes(:writer).first.writer
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 2aa6d643a5..da932b7663 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -824,6 +824,16 @@ class RelationTest < ActiveRecord::TestCase
assert_raises(ActiveRecord::ActiveRecordError) { Author.limit(10).delete_all }
end
+ def test_select_with_aggregates
+ posts = Post.select(:title, :body)
+
+ assert_equal 11, posts.count(:all)
+ assert_equal 11, posts.size
+ assert posts.any?
+ assert posts.many?
+ assert ! posts.empty?
+ end
+
def test_select_takes_a_variable_list_of_args
david = developers(:david)