From bd8d6a7d12c9b9f050ec354fa5d648f2ea858757 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 13 Sep 2008 20:12:17 +0200 Subject: [PATCH] Resolve a Hash#except edge cause caused by performance fix in a79737 (also 634e46). References #382 --- .../lib/active_support/core_ext/hash/except.rb | 2 +- activesupport/test/core_ext/hash_ext_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/hash/except.rb b/activesupport/lib/active_support/core_ext/hash/except.rb index f26d015..949976d 100644 --- a/activesupport/lib/active_support/core_ext/hash/except.rb +++ b/activesupport/lib/active_support/core_ext/hash/except.rb @@ -10,7 +10,7 @@ module ActiveSupport #:nodoc: module Except # Returns a new hash without the given keys. def except(*keys) - clone.except!(*keys) + dup.except!(*keys) end # Replaces the hash without the given keys. diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 7a414e9..3f0b82b 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -341,6 +341,20 @@ class HashExtTest < Test::Unit::TestCase assert_equal expected, original.except!(:c) assert_equal expected, original end + + def test_except_with_original_frozen + original = { :a => 'x', :b => 'y' } + original.freeze + assert_nothing_raised { original.except(:a) } + end + + uses_mocha 'except with expectation' do + def test_except_with_mocha_expectation_on_original + original = { :a => 'x', :b => 'y' } + original.expects(:delete).never + original.except(:a) + end + end end class IWriteMyOwnXML -- 1.6.0