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

Set default convert language to English #167

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions lib/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ class App < Sinatra::Base
end

body = params[:file][:tempfile].read
content = Converter.new(logger:@logger).convert_file( params[:action], body, params[:language] )
language = params.fetch(:language, 'en')
content = Converter.new(logger:@logger).convert_file( params[:action], body, language )
content_type content.mime_type
content
rescue StandardError => e
Expand All @@ -221,7 +222,8 @@ class App < Sinatra::Base
else
raise DocumentNotFound.new "Please specify either 'file' or 'url' POST variable"
end
path = LegacyConverter.new.convert_file params[:action], body, params[:language]
language = params.fetch(:language, 'en')
path = LegacyConverter.new.convert_file params[:action], body, language
converted_url = @legacy_url_base + path
content_type 'application/json'
{
Expand Down
29 changes: 26 additions & 3 deletions spec/lib/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def show_backtrace response
action: 'pdf',
file: Rack::Test::UploadedFile.new(__FILE__, 'application/ruby'),
}
expect(foo).to receive(:convert_file).with(params[:action],String,nil) { "%PDF-1.4" }
expect(foo).to receive(:convert_file).with(params[:action],String,'en') { "%PDF-1.4" }
post "/convert", params
expect(last_response.status).to eq 200
expect(last_response.content_type).to eq 'application/pdf; charset=us-ascii'
Expand All @@ -284,6 +284,17 @@ def show_backtrace response
expect(body).to be_a Hash
expect(body['description']).to eq 'Argh'
end
it 'allows to specify language' do
foo = double(Colore::Converter)
allow(Colore::Converter).to receive(:new) { foo }
params = {
action: 'pdf',
file: Rack::Test::UploadedFile.new(__FILE__, 'application/ruby'),
language: 'fr'
}
expect(foo).to receive(:convert_file).with(params[:action],String,'fr') { "%PDF-1.4" }
post "/convert", params
end
end

context 'POST /legacy/convert' do
Expand All @@ -294,7 +305,7 @@ def show_backtrace response
action: 'pdf',
file: Rack::Test::UploadedFile.new(__FILE__, 'application/ruby'),
}
expect(foo).to receive(:convert_file).with(params[:action],String,nil) { 'foobar' }
expect(foo).to receive(:convert_file).with(params[:action],String,'en') { 'foobar' }
post "/#{Colore::LegacyConverter::LEGACY}/convert", params
expect(last_response.status).to eq 200
expect(last_response.content_type).to eq 'application/json'
Expand All @@ -310,7 +321,7 @@ def show_backtrace response
url: 'http://localhost/foo/bar',
}
expect(Net::HTTP).to receive(:get).with(URI(params[:url])) { 'The quick brown flox' }
expect(foo).to receive(:convert_file).with(params[:action],String,nil) { 'foobar' }
expect(foo).to receive(:convert_file).with(params[:action],String,'en') { 'foobar' }
post "/#{Colore::LegacyConverter::LEGACY}/convert", params
expect(last_response.status).to eq 200
expect(last_response.content_type).to eq 'application/json'
Expand All @@ -333,6 +344,18 @@ def show_backtrace response
expect(body).to be_a Hash
expect(body['error']).to eq 'Argh'
end
it 'allows to specify language' do
foo = double(Colore::LegacyConverter)
allow(Colore::LegacyConverter).to receive(:new) { foo }
params = {
action: 'pdf',
url: 'http://localhost/foo/bar',
language: 'fr'
}
expect(Net::HTTP).to receive(:get).with(URI(params[:url])) { 'The quick brown flox' }
expect(foo).to receive(:convert_file).with(params[:action],String,'fr') { 'foobar' }
post "/#{Colore::LegacyConverter::LEGACY}/convert", params
end
end

context 'GET /legacy/:file_id' do
Expand Down