Skip to content

Commit 222776d

Browse files
authored
There is no try (#30)
* Replace use of .try with .dig
1 parent 3037e85 commit 222776d

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
77
### Added
88

99
### Changed
10+
- Fixed bug for mappings with multiple keys and a default (resolves: [#26](https://github.com/bugcrowd/vrt-ruby/issues/26))
1011

1112
### Removed
1213
- Removed `Gemfile.lock` from source control

lib/vrt/mapping.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get(id_list, version)
2727
id_list: id_list,
2828
mapping: mapping,
2929
key: key
30-
) || default&.try(:[], key)
30+
) || default&.dig(key)
3131
end
3232
else
3333
get_key(id_list: id_list, mapping: mapping, key: @scheme) || default
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"metadata": {
3+
"default": {
4+
"one_thing": "the thing one is"
5+
},
6+
"keys": ["one_thing", "another_thing"]
7+
},
8+
"content": [
9+
{
10+
"id": "server_security_misconfiguration",
11+
"one_thing": "the thing",
12+
"another_thing": "another one"
13+
}
14+
]
15+
}

spec/vrt/mappings_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@
126126
)
127127
end
128128
end
129+
130+
context 'with a default' do
131+
subject { mapping.get(id_list, version) }
132+
133+
let(:mapping) { described_class.new(:test_mapping) }
134+
let(:id_list) { %i[server_security_misconfiguration] }
135+
let(:version) { '999.999' }
136+
137+
it { is_expected.to include(:one_thing, :another_thing) }
138+
139+
context 'when falling back to default' do
140+
let(:id_list) { %i[broken_authentication_and_session_management] }
141+
142+
it { is_expected.to include(:one_thing) }
143+
end
144+
end
129145
end
130146

131147
context 'with arrays as the mapping values' do

0 commit comments

Comments
 (0)