Handle reshares of deleted posts in OpenGraph tags generation code

This commit is contained in:
Jonne Haß 2014-12-27 15:07:16 +01:00
parent 6c9f191696
commit 45b385d694
2 changed files with 30 additions and 8 deletions

View file

@ -50,14 +50,21 @@ module OpenGraphHelper
end
def og_page_post_tags(post)
[
*og_common_tags,
og_type("#{og_namespace}:frame"),
og_title(post_page_title(post, :length => 140)),
og_url(post_url(post)),
og_image(post),
og_description(post.message.plain_text_without_markdown truncate: 1000)
].join("\n").html_safe
tags = og_common_tags
if post.message
tags.concat [
*tags,
og_type("#{og_namespace}:frame"),
og_title(post_page_title(post, :length => 140)),
og_url(post_url(post)),
og_image(post),
og_description(post.message.plain_text_without_markdown truncate: 1000)
]
end
tags.join("\n").html_safe
end
def og_prefix

View file

@ -1,6 +1,21 @@
require 'spec_helper'
describe OpenGraphHelper, :type => :helper do
describe 'og_page_post_tags' do
it 'handles a reshare of a deleted post' do
reshare = FactoryGirl.build(:reshare, root: nil, id: 123)
expect {
helper.og_page_post_tags(reshare)
}.to_not raise_error
end
it 'handles a normal post' do
post = FactoryGirl.create(:status_message)
expect(helper.og_page_post_tags(post)).to include helper.og_url(post_url(post))
end
end
describe 'og_html' do
scenarios = {
"article" => {