Skip to content

Commit f381152

Browse files
Handle multiple file params (#25)
1 parent e613089 commit f381152

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

lib/convert_api/task.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def normalize_params(params)
3333
result = {}
3434

3535
symbolize_keys(params).each do |key, value|
36-
case key
37-
when :File
38-
result[:File] = FileParam.build(value)
39-
when :Files
36+
case
37+
when key != :StoreFile && key.to_s.end_with?('File')
38+
result[key] = FileParam.build(value)
39+
when key == :Files
4040
result[:Files] = files_batch(value)
4141
else
4242
result[key] = value

spec/convert_api/task_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,31 @@
2727
expect(subject).to be_instance_of(ConvertApi::Result)
2828
end
2929
end
30+
31+
context 'when file is instance of ResultFile' do
32+
let(:file) { ConvertApi::ResultFile.new('Url' => 'testurl') }
33+
let(:expected_params) { hash_including(File: 'testurl') }
34+
35+
it 'uses file url' do
36+
expect(ConvertApi.client).to(
37+
receive(:post).with('convert/txt/to/pdf', expected_params, instance_of(Hash)).and_return(result)
38+
)
39+
40+
expect(subject).to be_instance_of(ConvertApi::Result)
41+
end
42+
end
43+
44+
context 'when multiple file params' do
45+
let(:file) { ConvertApi::ResultFile.new('Url' => 'testurl') }
46+
let(:params) { { File: file, CompareFile: file } }
47+
let(:expected_params) { hash_including(File: 'testurl', CompareFile: 'testurl') }
48+
49+
it 'uses multiple file urls' do
50+
expect(ConvertApi.client).to(
51+
receive(:post).with('convert/txt/to/pdf', expected_params, instance_of(Hash)).and_return(result)
52+
)
53+
54+
expect(subject).to be_instance_of(ConvertApi::Result)
55+
end
56+
end
3057
end

0 commit comments

Comments
 (0)