Skip to content

Commit

Permalink
Handle string field names in CustomFieldList#respond_to?
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cgunther committed Mar 6, 2024
1 parent dd693a3 commit 37dec19
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?` (#)

### Breaking Changes

Expand Down
4 changes: 2 additions & 2 deletions lib/netsuite/records/custom_field_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions spec/netsuite/records/custom_field_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 37dec19

Please sign in to comment.