Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider 0bfc2fdd rédigé par Steffen van Bergerem's avatar Steffen van Bergerem
Parcourir les fichiers

Load likes and reshares in the SPV via gon

parent 05d19e69
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -48,12 +48,6 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, ...@@ -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({ ...@@ -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 ...@@ -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
......
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
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();
}); });
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter