diff --git a/HISTORY.md b/HISTORY.md index e689e70de..85e1347ea 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,7 @@ ### Fixed * Revert recent proxy changes which breaks proxy usage by @andrewdicken-stripe in https://github.com/NetSweet/netsuite/pull/579 +* Define `respond_to?` on `RecordRef` to match `method_missing` behavior (#608) ### Breaking Changes diff --git a/lib/netsuite/records/record_ref.rb b/lib/netsuite/records/record_ref.rb index 1ada59644..e5c96c46e 100644 --- a/lib/netsuite/records/record_ref.rb +++ b/lib/netsuite/records/record_ref.rb @@ -33,6 +33,11 @@ def method_missing(m, *args, &block) end end + def respond_to?(m, include_private = false) + return true if attributes.keys.map(&:to_sym).include?(m.to_sym) + super + end + end end end diff --git a/spec/netsuite/records/record_ref_spec.rb b/spec/netsuite/records/record_ref_spec.rb index 162f33ee9..f8503f3df 100644 --- a/spec/netsuite/records/record_ref_spec.rb +++ b/spec/netsuite/records/record_ref_spec.rb @@ -40,8 +40,16 @@ context 'readers' do it 'can take on arbitrary attributes into itself on initialization' do + expect(record_ref).to respond_to(:name) + expect(record_ref).to respond_to('name') expect(record_ref.name).to eql('This is a record_ref') + + expect(record_ref).to respond_to(:banana) + expect(record_ref).to respond_to('banana') expect(record_ref.banana).to eql('for monkeys') + + expect(record_ref).to_not respond_to(:non_existant_field) + expect(record_ref).to_not respond_to('non_existant_field') end end end