2006-07-08 14:14:49 -04:00
|
|
|
require File.dirname(__FILE__) + '/abstract_unit'
|
2005-12-15 15:03:23 -05:00
|
|
|
|
|
|
|
class OptionMergerTest < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
@options = {:hello => 'world'}
|
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2005-12-15 15:03:23 -05:00
|
|
|
def test_method_with_options_merges_options_when_options_are_present
|
|
|
|
local_options = {:cool => true}
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2005-12-15 15:03:23 -05:00
|
|
|
with_options(@options) do |o|
|
|
|
|
assert_equal local_options, method_with_options(local_options)
|
2006-07-08 14:14:49 -04:00
|
|
|
assert_equal @options.merge(local_options),
|
2005-12-15 15:03:23 -05:00
|
|
|
o.method_with_options(local_options)
|
|
|
|
end
|
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2005-12-15 15:03:23 -05:00
|
|
|
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
|
|
|
|
|
2006-04-26 17:49:41 -04:00
|
|
|
def test_method_with_options_allows_to_overwrite_options
|
|
|
|
local_options = {:hello => 'moon'}
|
|
|
|
assert_equal @options.keys, local_options.keys
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2006-04-26 17:49:41 -04:00
|
|
|
with_options(@options) do |o|
|
|
|
|
assert_equal local_options, method_with_options(local_options)
|
2006-07-08 14:14:49 -04:00
|
|
|
assert_equal @options.merge(local_options),
|
2006-04-26 17:49:41 -04:00
|
|
|
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
|
|
|
|
|
2006-09-27 14:46:46 -04:00
|
|
|
# Needed when counting objects with the ObjectSpace
|
|
|
|
def test_option_merger_class_method
|
|
|
|
assert_equal ActiveSupport::OptionMerger, ActiveSupport::OptionMerger.new('', '').class
|
|
|
|
end
|
|
|
|
|
2005-12-15 15:03:23 -05:00
|
|
|
private
|
|
|
|
def method_with_options(options = {})
|
|
|
|
options
|
|
|
|
end
|
|
|
|
end
|