From 83584ccb1a7df95f0d3bd8aad52cb13ab58232fb Mon Sep 17 00:00:00 2001 From: Chris Gunther Date: Wed, 6 Mar 2024 14:46:07 -0500 Subject: [PATCH] Handle string field names in `CustomFieldList#respond_to?` Previously `respond_to?` assumed it was given a symbol argument, so it directly checked for that argument in the fields, which are force-keyed as symbols. If you passed it a string argument, it wouldn't find the corresponding field, impying it didn't respond to such a method. Now, the argument is explicitly cast to a symbol before checking if such a field exists, supporting checking `respond_to?` with both argument types. --- HISTORY.md | 1 + lib/netsuite/records/custom_field_list.rb | 4 ++-- spec/netsuite/records/custom_field_list_spec.rb | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index e689e70de..eedcc8839 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 +* Handle string field names in `CustomFieldList#respond_to?` (#606) ### Breaking Changes diff --git a/lib/netsuite/records/custom_field_list.rb b/lib/netsuite/records/custom_field_list.rb index 193bb4b84..cc7267b4c 100644 --- a/lib/netsuite/records/custom_field_list.rb +++ b/lib/netsuite/records/custom_field_list.rb @@ -60,8 +60,8 @@ def method_missing(sym, *args, &block) super(sym, *args, &block) end - def respond_to?(sym, include_private = false) - return true if @custom_fields_assoc.include?(sym) + def respond_to?(method, include_private = false) + return true if @custom_fields_assoc.include?(method.to_sym) super end diff --git a/spec/netsuite/records/custom_field_list_spec.rb b/spec/netsuite/records/custom_field_list_spec.rb index 2266f51da..5122d0254 100644 --- a/spec/netsuite/records/custom_field_list_spec.rb +++ b/spec/netsuite/records/custom_field_list_spec.rb @@ -273,8 +273,14 @@ # field accessors are tested elsewhere, but let's run tests here to check various field types expect(list).to respond_to(:custbody_multipleselectfield) + expect(list).to respond_to('custbody_multipleselectfield') expect(list).to respond_to(:custbody_salesclassification) + expect(list).to respond_to('custbody_salesclassification') expect(list).to respond_to(:custentity_registeredonline) + expect(list).to respond_to('custentity_registeredonline') + + expect(list).to_not respond_to(:non_existant_field) + expect(list).to_not respond_to('non_existant_field') expect(list.to_record).to eql(record) expect(list.to_record.length).to eq(1)