Skip to content

Commit 9592ac6

Browse files
committed
Add tests for the InheritingHash class
1 parent 410f011 commit 9592ac6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/cases/inheriting_hash_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
4+
class InheritingHashTest < ActiveSupport::TestCase
5+
def setup
6+
@parent = ActiveResource::InheritingHash.new({ override_me: 'foo', parent_key: 'parent_value' })
7+
@child = ActiveResource::InheritingHash.new(@parent)
8+
@child[:override_me] = 'bar'
9+
@child[:child_only] = 'baz'
10+
end
11+
12+
def test_child_key_overrides_parent_key
13+
assert_equal 'bar', @child[:override_me]
14+
end
15+
16+
def test_parent_key_available_on_lookup
17+
assert_equal 'parent_value', @child[:parent_key]
18+
end
19+
20+
def test_conversion_to_regular_hash_includes_parent_keys
21+
hash = @child.to_hash
22+
23+
assert_equal 3, hash.keys.length
24+
assert_equal 'parent_value', hash[:parent_key]
25+
end
26+
end

0 commit comments

Comments
 (0)