aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/option_merger.rb4
-rw-r--r--activesupport/test/option_merger_test.rb16
3 files changed, 20 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 3a4b4e477f..bdd1c4d9f8 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Allow default options in with_options to be overridden. Closes #4480. [murphy@cYcnus.de]
+
* Added Module#alias_method_chain [Jamis Buck]
* Updated to Builder 2.0 [DHH]
diff --git a/activesupport/lib/active_support/option_merger.rb b/activesupport/lib/active_support/option_merger.rb
index 51a2ea1328..f944729bbc 100644
--- a/activesupport/lib/active_support/option_merger.rb
+++ b/activesupport/lib/active_support/option_merger.rb
@@ -15,8 +15,8 @@ module ActiveSupport
end
def merge_argument_options!(arguments)
- arguments << if arguments.last.respond_to? :merge!
- arguments.pop.dup.merge!(@options)
+ arguments << if arguments.last.respond_to? :to_hash
+ @options.merge(arguments.pop)
else
@options.dup
end
diff --git a/activesupport/test/option_merger_test.rb b/activesupport/test/option_merger_test.rb
index f5287d5725..e97a4f918b 100644
--- a/activesupport/test/option_merger_test.rb
+++ b/activesupport/test/option_merger_test.rb
@@ -27,6 +27,22 @@ class OptionMergerTest < Test::Unit::TestCase
end
end
+ def test_method_with_options_allows_to_overwrite_options
+ local_options = {:hello => 'moon'}
+ assert_equal @options.keys, local_options.keys
+
+ with_options(@options) do |o|
+ assert_equal local_options, method_with_options(local_options)
+ assert_equal @options.merge(local_options),
+ o.method_with_options(local_options)
+ assert_equal local_options, o.method_with_options(local_options)
+ end
+ with_options(local_options) do |o|
+ assert_equal local_options.merge(@options),
+ o.method_with_options(@options)
+ end
+ end
+
private
def method_with_options(options = {})
options