Load likes and reshares in the SPV via gon
This commit is contained in:
parent
05d19e69ee
commit
0bfc2fdd77
5 changed files with 18 additions and 12 deletions
|
|
@ -48,12 +48,6 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin,
|
||||||
var body = this.get("text").trim()
|
var body = this.get("text").trim()
|
||||||
, newlineIdx = body.indexOf("\n");
|
, newlineIdx = body.indexOf("\n");
|
||||||
return (newlineIdx > 0 ) ? body.substr(newlineIdx+1, body.length) : "";
|
return (newlineIdx > 0 ) ? body.substr(newlineIdx+1, body.length) : "";
|
||||||
},
|
|
||||||
|
|
||||||
//returns a promise
|
|
||||||
preloadOrFetch : function(){
|
|
||||||
var action = app.hasPreload("post") ? this.set(app.parsePreload("post")) : this.fetch();
|
|
||||||
return $.when(action);
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
// @license-end
|
// @license-end
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@ app.pages.SinglePostViewer = app.views.Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize : function() {
|
initialize : function() {
|
||||||
this.model = new app.models.Post({ id : gon.post.id });
|
this.model = new app.models.Post(gon.post);
|
||||||
this.model.preloadOrFetch().done(_.bind(this.initViews, this));
|
this.initViews();
|
||||||
this.model.interactions.fetch(); //async, yo, might want to throttle this later.
|
this.model.comments.fetch(); // async, yo, might want to throttle this later.
|
||||||
},
|
},
|
||||||
|
|
||||||
initViews : function() {
|
initViews : function() {
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,11 @@ class PostsController < ApplicationController
|
||||||
presenter = PostPresenter.new(post, current_user)
|
presenter = PostPresenter.new(post, current_user)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
gon.post = presenter
|
gon.post = presenter.with_initial_interactions
|
||||||
render locals: {post: presenter}
|
render locals: {post: presenter}
|
||||||
end
|
end
|
||||||
format.mobile { render locals: {post: post} }
|
format.mobile { render locals: {post: post} }
|
||||||
format.json { render json: presenter }
|
format.json { render json: presenter.with_interactions }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
11
spec/controllers/jasmine_fixtures/posts_spec.rb
Normal file
11
spec/controllers/jasmine_fixtures/posts_spec.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe PostsController, type: :controller do
|
||||||
|
describe "#show" do
|
||||||
|
it "generates the post_json fixture", fixture: true do
|
||||||
|
post = alice.post(:status_message, text: "hello world", public: true)
|
||||||
|
get :show, params: {id: post.id}, format: :json
|
||||||
|
save_fixture(response.body, "post_json")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
describe("app.pages.SinglePostViewer", function(){
|
describe("app.pages.SinglePostViewer", function(){
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
window.gon={};gon.post = {id: 42};
|
window.gon = {};
|
||||||
|
gon.post = $.parseJSON(spec.readFixture("post_json"));
|
||||||
this.view = new app.pages.SinglePostViewer();
|
this.view = new app.pages.SinglePostViewer();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue