From a904204f46df9ab117dfaad92324c322532a16db Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Sun, 8 May 2011 14:22:40 -0700 Subject: [PATCH] Content updater refactor complete for posts --- ...{content-updates.js => content-updater.js} | 11 +++++----- public/javascripts/web-socket-receiver.js | 6 +----- ...pdates-spec.js => content-updater-spec.js} | 20 ++++++++++--------- spec/javascripts/support/jasmine.yml | 2 +- 4 files changed, 18 insertions(+), 21 deletions(-) rename public/javascripts/{content-updates.js => content-updater.js} (72%) rename spec/javascripts/{content-updates-spec.js => content-updater-spec.js} (59%) diff --git a/public/javascripts/content-updates.js b/public/javascripts/content-updater.js similarity index 72% rename from public/javascripts/content-updates.js rename to public/javascripts/content-updater.js index 55eca2422..7cb24d308 100644 --- a/public/javascripts/content-updates.js +++ b/public/javascripts/content-updater.js @@ -3,11 +3,12 @@ * the COPYRIGHT file. */ -var ContentUpdates = { - addPostToStream: function(postId, html) { - if( $(".stream_element[data-guid='" + postId + "']").length === 0 ) { - var streamElement = $(html); +var ContentUpdater = { + addPostToStream: function(html) { + var streamElement = $(html); + var postId = streamElement.attr("data-guid"); + if($(".stream_element[data-guid='" + postId + "']").length === 0) { if($("#no_posts").length) { $("#no_posts").detach(); } @@ -16,9 +17,7 @@ var ContentUpdates = { streamElement.find("label").inFieldLabels(); }); - Diaspora.widgets.publish("stream/postAdded", [postId]); - Diaspora.widgets.timeago.updateTimeAgo(); Diaspora.widgets.directionDetector.updateBinds(); } diff --git a/public/javascripts/web-socket-receiver.js b/public/javascripts/web-socket-receiver.js index 64e4c6ba8..c244ea05a 100644 --- a/public/javascripts/web-socket-receiver.js +++ b/public/javascripts/web-socket-receiver.js @@ -128,14 +128,10 @@ var WebSocketReceiver = { processPost: function(className, postId, html, aspectIds) { if(WebSocketReceiver.onPageForAspects(aspectIds)) { - WebSocketReceiver.addPostToStream(postId, html); + ContentUpdater.addPostToStream(postId, html); } }, - addPostToStream: function(postId, html) { - - }, - onPageForClass: function(className) { return (location.href.indexOf(className) != -1 ); }, diff --git a/spec/javascripts/content-updates-spec.js b/spec/javascripts/content-updater-spec.js similarity index 59% rename from spec/javascripts/content-updates-spec.js rename to spec/javascripts/content-updater-spec.js index eea6abecf..df0bc5ae0 100644 --- a/spec/javascripts/content-updates-spec.js +++ b/spec/javascripts/content-updater-spec.js @@ -2,30 +2,32 @@ * licensed under the Affero General Public License version 3 or later. See * the COPYRIGHT file. */ -describe("ContentUpdates", function() { + +describe("ContentUpdater", function() { describe("addPostToStream", function() { + beforeEach(function() { $("#jasmine_content").empty(); - spec.loadFixture("aspects_index_with_posts"); + spec.loadFixture("aspects_index"); }); it("adds a post to the stream", function() { var originalPostCount = $(".stream_element").length; - ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream")); - expect($(".stream_element").length).toBeGreaterThan(originalPostCount); + ContentUpdater.addPostToStream(spec.fixtureHtml("status_message_in_stream")); + expect($(".stream_element").length).toEqual(originalPostCount + 1); }); it("does not add duplicate posts", function() { - ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream")); var originalPostCount = $(".stream_element").length; - ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream")); - expect($(".stream_element").length).toEqual(originalPostCount); + ContentUpdater.addPostToStream(spec.fixtureHtml("status_message_in_stream")); + expect($(".stream_element").length).toEqual(originalPostCount + 1); + ContentUpdater.addPostToStream(spec.fixtureHtml("status_message_in_stream")); + expect($(".stream_element").length).toEqual(originalPostCount + 1); }); it("removes the div that says you have no posts if it exists", function() { - spec.loadFixture("aspects_index"); expect($("#no_posts").length).toEqual(1); - ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream")); + ContentUpdater.addPostToStream(spec.fixtureHtml("status_message_in_stream")); expect($("#no_posts").length).toEqual(0); }); }); diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml index 9f56fb62b..707fb41ad 100644 --- a/spec/javascripts/support/jasmine.yml +++ b/spec/javascripts/support/jasmine.yml @@ -40,7 +40,7 @@ src_files: - public/javascripts/validation.js - public/javascripts/rails.js - public/javascripts/aspect-filters.js - - public/javascripts/content-updates.js + - public/javascripts/content-updater.js # stylesheets # # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.