Skip to content

Commit efaa862

Browse files
committed
[Fixes #RUBY-641]: BSON::OrderedHash should allow options extraction using Array#extract_options!
1 parent 2d2c963 commit efaa862

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/bson/ordered_hash.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def ==(other)
3333
end
3434
end
3535

36+
# Allows activesupport Array#extract_options! to extract options
37+
# when they are instance of BSON::OrderedHash
38+
#
39+
# @return [true, false] true if options can be extracted
40+
def extractable_options?
41+
instance_of?(BSON::OrderedHash)
42+
end
43+
3644
# We only need the body of this class if the RUBY_VERSION is before 1.9
3745
if RUBY_VERSION < '1.9'
3846
attr_accessor :ordered_keys

test/bson/ordered_hash_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,16 @@ def test_dup
258258
assert_nil @oh['f']
259259
assert_equal ['c', 'a', 'z'], @oh.keys
260260
end
261+
262+
def test_extractable_options_for_ordered_hash
263+
assert @oh.extractable_options?
264+
end
265+
266+
# Extractable_options should not be enabled by default for
267+
# classes inherited from BSON::OrderedHash
268+
#
269+
def test_extractable_options_for_ordered_hash_inherited_classes_is_false
270+
oh_child_class = Class.new(BSON::OrderedHash)
271+
assert_false oh_child_class.new.extractable_options?
272+
end
261273
end

0 commit comments

Comments
 (0)