Commit 177f6082 authored by danielgrippi's avatar danielgrippi

fix oembed issues in backbone land

parent 20360794
......@@ -5,6 +5,12 @@ class OEmbedCache < ActiveRecord::Base
has_many :posts
# NOTE API V1 to be extracted
acts_as_api
api_accessible :backbone do |t|
t.add :data
end
def self.find_or_create_by_url(url)
cache = OEmbedCache.find_or_initialize_by_url(url)
return cache if cache.persisted?
......
......@@ -29,6 +29,10 @@ class Reshare < Post
self.root.author.diaspora_handle
end
def o_embed_cache
self.root ? root.o_embed_cache : super
end
def raw_message
self.root ? root.raw_message : super
end
......
......@@ -39,9 +39,7 @@
<%= text %>
<% if(o_embed_cache) { %>
<%= root.o_embed_cache.posts.data.html %>
<% } %>
<%= o_embed_html %>
<!-- end duplication -->
</div>
......
......@@ -14,6 +14,4 @@
<%= text %>
<% if(o_embed_cache) { %>
<%= o_embed_cache.posts.data.html %>
<% } %>
<%= o_embed_html %>
......@@ -2,7 +2,8 @@ app.views.Content = app.views.StreamObject.extend({
presenter : function(){
var model = this.model
return _.extend(this.defaultPresenter(), {
text : metafyText(model.get("text"))
text : metafyText(model.get("text")),
o_embed_html : embedHTML(model)
})
function metafyText(text) {
......@@ -48,6 +49,11 @@ app.views.Content = app.views.StreamObject.extend({
return "<a href='" + protocol + url + "' target=_blank>" + url + "</a>"
})
}
function embedHTML(model){
if(!model.get("o_embed_cache")) { return ""; }
return model.get("o_embed_cache").data.html
}
}
})
......
......@@ -167,6 +167,26 @@ describe("app.views.Post", function(){
})
})
context("embed_html", function(){
it("provides oembed html from the model response", function(){
this.statusMessage.set({"o_embed_cache" : {
"data" : {
"html" : "some html"
}
}})
var view = new app.views.Content({model : this.statusMessage});
expect(view.presenter().o_embed_html).toContain("some html")
})
it("does not provide oembed html from the model response if none is present", function(){
this.statusMessage.set({"o_embed_cache" : null})
var view = new app.views.Content({model : this.statusMessage});
expect(view.presenter().o_embed_html).toBe("");
})
})
context("user not signed in", function(){
it("does not provide a Feedback view", function(){
logout()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment