Content updater refactor complete for posts

This commit is contained in:
Sarah Mei 2011-05-08 14:22:40 -07:00
parent 50e67524c1
commit a904204f46
4 changed files with 18 additions and 21 deletions

View file

@ -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();
}

View file

@ -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 );
},

View file

@ -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);
});
});

View file

@ -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.