From 7254b1d0997fa59090d66c306071e0bd52478fbe Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Tue, 16 Jun 2015 18:53:40 +0000 Subject: [PATCH] Fix oEmbed endpoint when only one of maxwidth/maxheight given --- app/controllers/oembed_controller.rb | 11 ++++++----- spec/api/oembed_spec.rb | 5 +++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/oembed_controller.rb b/app/controllers/oembed_controller.rb index c56eb2232..876e9f82c 100644 --- a/app/controllers/oembed_controller.rb +++ b/app/controllers/oembed_controller.rb @@ -25,11 +25,12 @@ def show def oembed_response(asciicast) asciicast_image_generator.generate(asciicast) if asciicast.image_stale? - width, height = asciicast.image_width, asciicast.image_height - - if params[:maxwidth] - width, height = size_smaller_than(width, height, params[:maxwidth], params[:maxheight]) - end + width, height = size_smaller_than( + asciicast.image_width, + asciicast.image_height, + params[:maxwidth] || asciicast.image_width, + params[:maxheight] || asciicast.image_height + ) oembed = { type: 'rich', diff --git a/spec/api/oembed_spec.rb b/spec/api/oembed_spec.rb index 1585b9495..153b1b758 100644 --- a/spec/api/oembed_spec.rb +++ b/spec/api/oembed_spec.rb @@ -14,4 +14,9 @@ expect(response.status).to eq(200) end + it "responds with status 200 when only maxwidth given" do + get "/oembed?url=http://localhost:3000/a/#{asciicast.id}&format=json&maxwidth=500" + expect(response.status).to eq(200) + end + end