1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/test/ordered_options_test.rb

89 lines
2.1 KiB
Ruby
Raw Normal View History

require 'abstract_unit'
2012-03-20 10:11:27 -04:00
require 'active_support/ordered_options'
2012-01-05 20:12:46 -05:00
class OrderedOptionsTest < ActiveSupport::TestCase
def test_usage
a = ActiveSupport::OrderedOptions.new
assert_nil a[:not_set]
2013-03-30 04:31:42 -04:00
a[:allow_concurrency] = true
assert_equal 1, a.size
2013-03-30 04:31:42 -04:00
assert a[:allow_concurrency]
2013-03-30 04:31:42 -04:00
a[:allow_concurrency] = false
assert_equal 1, a.size
2013-03-30 04:31:42 -04:00
assert !a[:allow_concurrency]
a["else_where"] = 56
assert_equal 2, a.size
assert_equal 56, a[:else_where]
end
def test_looping
a = ActiveSupport::OrderedOptions.new
2013-03-30 04:31:42 -04:00
a[:allow_concurrency] = true
a["else_where"] = 56
2013-03-30 04:31:42 -04:00
test = [[:allow_concurrency, true], [:else_where, 56]]
a.each_with_index do |(key, value), index|
assert_equal test[index].first, key
assert_equal test[index].last, value
end
end
def test_method_access
a = ActiveSupport::OrderedOptions.new
assert_nil a.not_set
2013-03-30 04:31:42 -04:00
a.allow_concurrency = true
assert_equal 1, a.size
2013-03-30 04:31:42 -04:00
assert a.allow_concurrency
2013-03-30 04:31:42 -04:00
a.allow_concurrency = false
assert_equal 1, a.size
2013-03-30 04:31:42 -04:00
assert !a.allow_concurrency
a.else_where = 56
assert_equal 2, a.size
assert_equal 56, a.else_where
end
def test_inheritable_options_continues_lookup_in_parent
parent = ActiveSupport::OrderedOptions.new
parent[:foo] = true
child = ActiveSupport::InheritableOptions.new(parent)
assert child.foo
end
def test_inheritable_options_can_override_parent
parent = ActiveSupport::OrderedOptions.new
parent[:foo] = :bar
child = ActiveSupport::InheritableOptions.new(parent)
child[:foo] = :baz
assert_equal :baz, child.foo
end
def test_inheritable_options_inheritable_copy
original = ActiveSupport::InheritableOptions.new
copy = original.inheritable_copy
assert copy.kind_of?(original.class)
assert_not_equal copy.object_id, original.object_id
end
def test_introspection
a = ActiveSupport::OrderedOptions.new
assert a.respond_to?(:blah)
assert a.respond_to?(:blah=)
assert_equal 42, a.method(:blah=).call(42)
assert_equal 42, a.method(:blah).call
end
end