From cdd45fa09d76f7c16ccbb6682e672a44f82174a0 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Sun, 21 Feb 2016 03:28:18 +1030 Subject: Mutating the result of Relation#to_a should not affect the relation Clarifying this separation and enforcing relation immutability is the culmination of the previous efforts to remove the mutator method delegations. --- activerecord/test/cases/relations_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 090b885dd5..4c15ab6644 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1273,6 +1273,16 @@ class RelationTest < ActiveRecord::TestCase assert posts.loaded? end + def test_to_a_should_dup_target + posts = Post.all + + original_size = posts.size + removed = posts.to_a.pop + + assert_equal original_size, posts.size + assert_includes posts.to_a, removed + end + def test_build posts = Post.all -- cgit v1.2.3