Handle reshares of deleted posts in OpenGraph tags generation code
This commit is contained in:
parent
6c9f191696
commit
45b385d694
2 changed files with 30 additions and 8 deletions
|
|
@ -50,14 +50,21 @@ module OpenGraphHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def og_page_post_tags(post)
|
def og_page_post_tags(post)
|
||||||
[
|
tags = og_common_tags
|
||||||
*og_common_tags,
|
|
||||||
|
|
||||||
|
if post.message
|
||||||
|
tags.concat [
|
||||||
|
*tags,
|
||||||
og_type("#{og_namespace}:frame"),
|
og_type("#{og_namespace}:frame"),
|
||||||
og_title(post_page_title(post, :length => 140)),
|
og_title(post_page_title(post, :length => 140)),
|
||||||
og_url(post_url(post)),
|
og_url(post_url(post)),
|
||||||
og_image(post),
|
og_image(post),
|
||||||
og_description(post.message.plain_text_without_markdown truncate: 1000)
|
og_description(post.message.plain_text_without_markdown truncate: 1000)
|
||||||
].join("\n").html_safe
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
tags.join("\n").html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def og_prefix
|
def og_prefix
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,21 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe OpenGraphHelper, :type => :helper do
|
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
|
describe 'og_html' do
|
||||||
scenarios = {
|
scenarios = {
|
||||||
"article" => {
|
"article" => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue