Merge pull request #5208 from jaideng123/5081-truncate_open_graph_data
Fixed Open Graph db insertion
This commit is contained in:
commit
d5474c3992
5 changed files with 35 additions and 5 deletions
|
|
@ -44,6 +44,7 @@ The default for including jQuery from a CDN has changed. If you want to continue
|
|||
## Bug fixes
|
||||
* orca cannot see 'Add Contact' button [#5158](https://github.com/diaspora/diaspora/pull/5158)
|
||||
* Move submit button to the right in conversations view [#4960](https://github.com/diaspora/diaspora/pull/4960)
|
||||
* Handle long URLs and titles in OpenGraph descriptions [#5208](https://github.com/diaspora/diaspora/pull/5208)
|
||||
|
||||
## Features
|
||||
* Don't pull jQuery from a CDN by default [#5105](https://github.com/diaspora/diaspora/pull/5105)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class OpenGraphCache < ActiveRecord::Base
|
|||
|
||||
return if response.blank? || response.type.blank?
|
||||
|
||||
self.title = response.title
|
||||
self.title = response.title.truncate(255)
|
||||
self.ob_type = response.type
|
||||
self.image = response.images[0]
|
||||
self.url = response.url
|
||||
|
|
|
|||
10
db/migrate/20140906192846_fix_open_graph_data.rb
Normal file
10
db/migrate/20140906192846_fix_open_graph_data.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
class FixOpenGraphData < ActiveRecord::Migration
|
||||
def self.up
|
||||
change_column :open_graph_caches, :url, :text
|
||||
change_column :open_graph_caches, :image, :text
|
||||
end
|
||||
def self.down
|
||||
change_column :open_graph_caches, :url, :string
|
||||
change_column :open_graph_caches, :image, :string
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20140826165533) do
|
||||
ActiveRecord::Schema.define(version: 20140906192846) do
|
||||
|
||||
create_table "account_deletions", force: true do |t|
|
||||
t.string "diaspora_handle"
|
||||
|
|
@ -219,8 +219,8 @@ ActiveRecord::Schema.define(version: 20140826165533) do
|
|||
create_table "open_graph_caches", force: true do |t|
|
||||
t.string "title"
|
||||
t.string "ob_type"
|
||||
t.string "image"
|
||||
t.string "url"
|
||||
t.text "image"
|
||||
t.text "url"
|
||||
t.text "description"
|
||||
end
|
||||
|
||||
|
|
@ -570,4 +570,4 @@ ActiveRecord::Schema.define(version: 20140826165533) do
|
|||
|
||||
add_foreign_key "share_visibilities", "contacts", name: "post_visibilities_contact_id_fk", dependent: :delete
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -16,12 +16,25 @@ describe Workers::GatherOpenGraphData do
|
|||
<meta property=\"og:description\" content=\"#{@ogsite_description}\" />
|
||||
</head><body></body></html>"
|
||||
|
||||
@oglong_title = "D" * 256
|
||||
@oglong_url = 'http://www.we-are-too-long.com'
|
||||
@oglong_body =
|
||||
"<html><head><title>#{@oglong_title}</title>
|
||||
<meta property=\"og:title\" content=\"#{@oglong_title}\"/>
|
||||
<meta property=\"og:type\" content=\"#{@ogsite_type}\" />
|
||||
<meta property=\"og:image\" content=\"#{@ogsite_image}\" />
|
||||
<meta property=\"og:url\" content=\"#{@oglong_url}\" />
|
||||
<meta property=\"og:description\" content=\"#{@ogsite_description}\" />
|
||||
</head><body></body></html>"
|
||||
|
||||
@no_open_graph_url = 'http://www.we-do-not-support-open-graph.com/index.html'
|
||||
|
||||
@status_message = FactoryGirl.create(:status_message)
|
||||
|
||||
stub_request(:get, @ogsite_url).to_return(:status => 200, :body => @ogsite_body)
|
||||
stub_request(:get, @no_open_graph_url).to_return(:status => 200, :body => '<html><body>hello there</body></html>')
|
||||
stub_request(:get, @oglong_url).to_return(:status => 200, :body => @oglong_body)
|
||||
|
||||
end
|
||||
|
||||
describe '.perform' do
|
||||
|
|
@ -65,5 +78,11 @@ describe Workers::GatherOpenGraphData do
|
|||
Workers::GatherOpenGraphData.new.perform(0, @ogsite_url)
|
||||
}.to_not raise_error
|
||||
end
|
||||
it 'truncates + inserts titles that are too long' do
|
||||
Workers::GatherOpenGraphData.new.perform(@status_message.id, @oglong_url)
|
||||
ogc = OpenGraphCache.find_by_url(@oglong_url)
|
||||
expect(ogc).to be_truthy
|
||||
expect(ogc.title.length).to be <= 255
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue