aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorAkira Matsuda <ronnie@dio.jp>2015-02-27 12:14:03 +0900
committerAkira Matsuda <ronnie@dio.jp>2015-02-28 14:50:13 +0900
commit243cb81010dbf30ab99d6682a758048bfcb24bc7 (patch)
treede8cd39b30562991ba691f53c0c58ea8ba405835 /activerecord/test/cases
parent3458873642182689e835be8643a50b7634c3e0f5 (diff)
downloadrails-243cb81010dbf30ab99d6682a758048bfcb24bc7.tar.gz
rails-243cb81010dbf30ab99d6682a758048bfcb24bc7.tar.bz2
rails-243cb81010dbf30ab99d6682a758048bfcb24bc7.zip
Preserve Array#take(n) behaviour of HasManyAssociation
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 897c52a49d..675bed9bfa 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -478,6 +478,19 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_raise(ActiveRecord::RecordNotFound) { authors(:bob).posts.take! }
end
+ def test_taking_with_a_number
+ # taking from unloaded Relation
+ bob = Author.find(authors(:bob).id)
+ assert_equal [posts(:misc_by_bob)], bob.posts.take(1)
+ bob = Author.find(authors(:bob).id)
+ assert_equal [posts(:misc_by_bob), posts(:other_by_bob)], bob.posts.take(2)
+
+ # taking from loaded Relation
+ bob.posts.to_a
+ assert_equal [posts(:misc_by_bob)], authors(:bob).posts.take(1)
+ assert_equal [posts(:misc_by_bob), posts(:other_by_bob)], authors(:bob).posts.take(2)
+ end
+
def test_taking_with_inverse_of
interests(:woodsmanship).destroy
interests(:survival).destroy