Skip to content

Commit 780bfcc

Browse files
author
David Dieulivol
committed
🐛 Fix find_by with symbols for values.
1 parent 6e37e26 commit 780bfcc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/netbox_client_ruby/entities.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def find_by(attributes)
8383
if filter_key.to_s.start_with?('cf_')
8484
custom_field = filter_key.to_s.sub('cf_', '')
8585

86-
netbox_object.custom_fields[custom_field] == filter_value
86+
netbox_object.custom_fields[custom_field].to_s == filter_value.to_s
8787
else
8888
if netbox_object.respond_to?(filter_key)
89-
netbox_object.public_send(filter_key) == filter_value
89+
netbox_object.public_send(filter_key).to_s == filter_value.to_s
9090
else
9191
false
9292
end

spec/netbox_client_ruby/entities_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ class TestEntities3
230230
it { expect(found_object).to be_nil }
231231
end
232232

233+
context 'with values as symbols' do
234+
let(:filter_attributes) { { 'name' => :obj2 } }
235+
236+
it { expect(found_object.name).to eq('obj2') }
237+
end
238+
233239
context 'with correct filters' do
234240
let(:filter_attributes) { { 'name' => 'obj2' } }
235241

@@ -259,6 +265,12 @@ class TestEntities3
259265
it { expect(found_object).to be_nil }
260266
end
261267

268+
context 'with values as symbols' do
269+
let(:filter_attributes) { { 'cf_nine_urn' => :'urn:nine:server:1234' } }
270+
271+
it { expect(found_object.name).to eq('my-object') }
272+
end
273+
262274
context 'with correct filters' do
263275
let(:filter_attributes) { { 'cf_nine_urn' => 'urn:nine:server:1234' } }
264276

0 commit comments

Comments
 (0)