diff options
author | Sam Stephenson <sam@37signals.com> | 2005-12-15 20:03:23 +0000 |
---|---|---|
committer | Sam Stephenson <sam@37signals.com> | 2005-12-15 20:03:23 +0000 |
commit | 85fe1ecaefe415ac1de36883f5f6162f49bd5287 (patch) | |
tree | 34f87cac51f7009928bc6ba0604cddf62be01d3e /activesupport/test | |
parent | fc4ffbdc69988b60bd17ffab5d8d81ec67a11180 (diff) | |
download | rails-85fe1ecaefe415ac1de36883f5f6162f49bd5287.tar.gz rails-85fe1ecaefe415ac1de36883f5f6162f49bd5287.tar.bz2 rails-85fe1ecaefe415ac1de36883f5f6162f49bd5287.zip |
Add Object#with_options for DRYing up multiple calls to methods having shared options
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3314 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/option_merger_test.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/activesupport/test/option_merger_test.rb b/activesupport/test/option_merger_test.rb new file mode 100644 index 0000000000..0142db5b65 --- /dev/null +++ b/activesupport/test/option_merger_test.rb @@ -0,0 +1,32 @@ +require 'test/unit' + +$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib' +require 'active_support' + +class OptionMergerTest < Test::Unit::TestCase + def setup + @options = {:hello => 'world'} + end + + def test_method_with_options_merges_options_when_options_are_present + local_options = {:cool => true} + + 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) + end + end + + def test_method_with_options_appends_options_when_options_are_missing + with_options(@options) do |o| + assert_equal Hash.new, method_with_options + assert_equal @options, o.method_with_options + end + end + + private + def method_with_options(options = {}) + options + end +end |