Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "undefined method `[]' for #<Nori::StringIOFile>" when adding File #495

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*

### Fixed
* Fix "undefined method `[]` for #<Nori::StringIOFile>" when adding File (#495)
*

## 0.8.10
Expand Down
6 changes: 5 additions & 1 deletion lib/netsuite/actions/add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ def success?
end

def response_body
@response_body ||= response_hash[:base_ref]
@response_body ||= if response_hash[:base_ref].is_a?(Nori::StringIOFile)
{ :@internal_id => Nokogiri::XML(@response.to_s).remove_namespaces!.at_xpath('//baseRef')[:internalId] }
else
response_hash[:base_ref]
end
end

def response_errors
Expand Down
36 changes: 36 additions & 0 deletions spec/netsuite/actions/add_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,40 @@
end
end

context 'File' do
let(:file) do
NetSuite::Records::File.new(name: 'foo.pdf', content: 'abc123')
end

context 'when successful' do
before do
savon.expects(:add).with(:message => {
'platformMsgs:record' => {
:content! => {
'fileCabinet:name' => 'foo.pdf',
'fileCabinet:content' => 'abc123',
},
'@xsi:type' => 'fileCabinet:File'
},
}).returns(File.read('spec/support/fixtures/add/add_file.xml'))
end

it 'makes a valid request to the NetSuite API' do
NetSuite::Actions::Add.call([file])
end

it 'returns a valid Response object' do
response = NetSuite::Actions::Add.call([file])
expect(response).to be_kind_of(NetSuite::Response)
expect(response).to be_success
end

it 'properly extracts internal ID from response' do
file.add

expect(file.internal_id).to eq('23556')
end
end
end

end
20 changes: 20 additions & 0 deletions spec/support/fixtures/add/add_file.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<platformMsgs:documentInfo xmlns:platformMsgs="urn:messages_2020_2.platform.webservices.netsuite.com">
<platformMsgs:nsId>REDACTED</platformMsgs:nsId>
</platformMsgs:documentInfo>
</soapenv:Header>
<soapenv:Body>
<addResponse xmlns="urn:messages_2020_2.platform.webservices.netsuite.com">
<writeResponse>
<platformCore:status xmlns:platformCore="urn:core_2020_2.platform.webservices.netsuite.com" isSuccess="true">
<platformCore:statusDetail>
<platformCore:afterSubmitFailed>false</platformCore:afterSubmitFailed>
</platformCore:statusDetail>
</platformCore:status>
<baseRef xmlns:platformCore="urn:core_2020_2.platform.webservices.netsuite.com" internalId="23556" type="file" xsi:type="platformCore:RecordRef"/>
</writeResponse>
</addResponse>
</soapenv:Body>
</soapenv:Envelope>