diff --git a/app/assets/javascripts/app/models/post.js b/app/assets/javascripts/app/models/post.js index c351ee787..b693d7b2d 100644 --- a/app/assets/javascripts/app/models/post.js +++ b/app/assets/javascripts/app/models/post.js @@ -48,12 +48,6 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, var body = this.get("text").trim() , newlineIdx = body.indexOf("\n"); 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 diff --git a/app/assets/javascripts/app/pages/single-post-viewer.js b/app/assets/javascripts/app/pages/single-post-viewer.js index c5a30f1c9..a145139b5 100644 --- a/app/assets/javascripts/app/pages/single-post-viewer.js +++ b/app/assets/javascripts/app/pages/single-post-viewer.js @@ -9,9 +9,9 @@ app.pages.SinglePostViewer = app.views.Base.extend({ }, initialize : function() { - this.model = new app.models.Post({ id : gon.post.id }); - this.model.preloadOrFetch().done(_.bind(this.initViews, this)); - this.model.interactions.fetch(); //async, yo, might want to throttle this later. + this.model = new app.models.Post(gon.post); + this.initViews(); + this.model.comments.fetch(); // async, yo, might want to throttle this later. }, initViews : function() { diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 8b5386d2b..aa1aa3e9a 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -22,11 +22,11 @@ class PostsController < ApplicationController presenter = PostPresenter.new(post, current_user) respond_to do |format| format.html do - gon.post = presenter + gon.post = presenter.with_initial_interactions render locals: {post: presenter} end format.mobile { render locals: {post: post} } - format.json { render json: presenter } + format.json { render json: presenter.with_interactions } end end diff --git a/spec/controllers/jasmine_fixtures/posts_spec.rb b/spec/controllers/jasmine_fixtures/posts_spec.rb new file mode 100644 index 000000000..aed5d118a --- /dev/null +++ b/spec/controllers/jasmine_fixtures/posts_spec.rb @@ -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 diff --git a/spec/javascripts/app/pages/single-post-viewer_spec.js b/spec/javascripts/app/pages/single-post-viewer_spec.js index df8f9c43c..c1db51394 100644 --- a/spec/javascripts/app/pages/single-post-viewer_spec.js +++ b/spec/javascripts/app/pages/single-post-viewer_spec.js @@ -1,6 +1,7 @@ describe("app.pages.SinglePostViewer", function(){ beforeEach(function() { - window.gon={};gon.post = {id: 42}; + window.gon = {}; + gon.post = $.parseJSON(spec.readFixture("post_json")); this.view = new app.pages.SinglePostViewer(); });