diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index 81e4e8726..60d0ec9f3 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -56,8 +56,12 @@ class PostsController < ApplicationController
def oembed
post_id = OEmbedPresenter.id_from_url(params.delete(:url))
post = find_by_guid_or_id_with_current_user(post_id)
- oembed = OEmbedPresenter.new(post, params.slice(:format, :maxheight, :minheight))
- render :json => oembed
+ if post.present?
+ oembed = OEmbedPresenter.new(post, params.slice(:format, :maxheight, :minheight))
+ render :json => oembed
+ else
+ render :nothing => true, :status => 404
+ end
end
def destroy
diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb
index 9f5c4aeaf..e12ed5901 100644
--- a/app/helpers/posts_helper.rb
+++ b/app/helpers/posts_helper.rb
@@ -20,6 +20,7 @@ module PostsHelper
def post_iframe_url(post_id, opts={})
opts[:width] ||= 516
opts[:height] ||= 315
- "".html_safe
+ host = AppConfig[:pod_uri].port ==80 ? AppConfig[:pod_uri].host : "#{AppConfig[:pod_uri].host}:#{AppConfig[:pod_uri].port}"
+ "".html_safe
end
end
diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb
index 2a53a661b..221beaca8 100644
--- a/spec/controllers/posts_controller_spec.rb
+++ b/spec/controllers/posts_controller_spec.rb
@@ -120,6 +120,19 @@ describe PostsController do
end
end
+ describe 'oembed' do
+ it 'works when you can see it' do
+ sign_in alice
+ get :oembed, :url => "/posts/#{@message.id}"
+ response.body.should match /iframe/
+ end
+
+ it 'returns a 404 response when the post is not found' do
+ get :oembed, :url => "/posts/#{@message.id}"
+ response.should_not be_success
+ end
+ end
+
describe '#destroy' do
before do
sign_in alice