From 0d700046c4070dbda0a681715d8cee8f4865752c Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 25 Jun 2010 22:29:08 -0700 Subject: [PATCH 01/10] MS^2 Object parser can handle comments --- app/helpers/application_helper.rb | 20 +++++++++---------- spec/helpers/parser_spec.rb | 32 +++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 50b8f700b..b2b5e076b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -22,27 +22,27 @@ module ApplicationHelper doc.xpath("/XML/posts/post") end - def parse_posts_from_xml(xml) - posts = [] + def parse_objects_from_xml(xml) + objects = [] sender = parse_sender_object_from_xml(xml) body = parse_body_contents_from_xml(xml) body.children.each do |post| begin object = post.name.camelize.constantize.from_xml post.to_s - object.person = sender - posts << object if object.is_a? Post + object.person = sender if object.is_a? Post + objects << object rescue - puts "Not a real type: #{post.to_s}" + puts "Not a real type: #{object.to_s}" end end - posts + objects end - def store_posts_from_xml(xml) - posts = parse_posts_from_xml(xml) + def kk(xml) + objects = parse_objects_from_xml(xml) - posts.each do |p| - p.save unless p.person.nil? + objects.each do |p| + p.save if p.respond_to?(:person) && p.person end end diff --git a/spec/helpers/parser_spec.rb b/spec/helpers/parser_spec.rb index eae4ce7fd..445553e5f 100644 --- a/spec/helpers/parser_spec.rb +++ b/spec/helpers/parser_spec.rb @@ -12,7 +12,7 @@ describe "parser in application helper" do status_messages = [] 10.times { status_messages << Factory.build(:status_message, :person => @user)} xml = Post.build_xml_for(status_messages) - store_posts_from_xml(xml) + store_objects_from_xml(xml) StatusMessage.count.should == 0 end it 'should discard posts where it does not know the type' do @@ -24,7 +24,7 @@ describe "parser in application helper" do \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n " - store_posts_from_xml(xml) + store_objects_from_xml(xml) Post.count.should == 2 Post.first.person.email.should == Friend.first.email end @@ -36,7 +36,7 @@ describe "parser in application helper" do \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n " - store_posts_from_xml(xml) + store_objects_from_xml(xml) Post.count.should == 0 end @@ -51,7 +51,7 @@ describe "parser in application helper" do \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n " - store_posts_from_xml(xml) + store_objects_from_xml(xml) Post.count.should == 0 end it 'should discard types which are not of type post' do @@ -60,12 +60,13 @@ describe "parser in application helper" do #{Friend.first.email} - + + \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n - " - store_posts_from_xml(xml) + " + store_objects_from_xml(xml) Post.count.should == 2 Post.first.person.email.should == Friend.first.email end @@ -94,10 +95,25 @@ describe "parser in application helper" do end it 'should be able to extract all posts to an array' do - posts = parse_posts_from_xml(@xml) + posts = parse_objects_from_xml(@xml) posts.is_a?(Array).should be true posts.count.should == 10 end + + it 'should be able to correctly handle comments' do + friend = Factory.create(:friend) + post = Factory.create(:status_message) + xml = "#{Friend.first.email} + + \n Freedom!\n #{friend.id}\n #{post.id}}\n + " + objects = parse_objects_from_xml(xml) + comment = objects.first + comment.text.should == "Freedom!" + comment.person.should == friend + comment.post.should == post + + end end From e4e2d52bcb9f263ad7174d4b96571bcdef923460 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 25 Jun 2010 22:29:36 -0700 Subject: [PATCH 02/10] reverting typos --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b2b5e076b..227f5528b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -38,7 +38,7 @@ module ApplicationHelper objects end - def kk(xml) + def store_objects_from_xml(xml) objects = parse_objects_from_xml(xml) objects.each do |p| From 6467f943da212c0cdc06e2a4b6d87808d4665d73 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 25 Jun 2010 22:49:53 -0700 Subject: [PATCH 03/10] MS^2 Comments serialize and deserialize properly --- app/helpers/application_helper.rb | 3 ++- spec/factories.rb | 2 ++ spec/helpers/parser_spec.rb | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 227f5528b..ce2847aa0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -42,7 +42,8 @@ module ApplicationHelper objects = parse_objects_from_xml(xml) objects.each do |p| - p.save if p.respond_to?(:person) && p.person + p.save if p.respond_to?(:person) && !(p.person.nil?) #WTF + #p.save if p.respond_to?(:person) && !(p.person == nil) #WTF end end diff --git a/spec/factories.rb b/spec/factories.rb index 5055b0023..ded4bf247 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -30,3 +30,5 @@ end Factory.define :post do |p| end + +Factory.define(:comment) {} \ No newline at end of file diff --git a/spec/helpers/parser_spec.rb b/spec/helpers/parser_spec.rb index 445553e5f..40fe5aea5 100644 --- a/spec/helpers/parser_spec.rb +++ b/spec/helpers/parser_spec.rb @@ -103,16 +103,16 @@ describe "parser in application helper" do it 'should be able to correctly handle comments' do friend = Factory.create(:friend) post = Factory.create(:status_message) + comment = Factory.build(:comment, :post => post, :person => friend, :text => "Freedom!") xml = "#{Friend.first.email} - \n Freedom!\n #{friend.id}\n #{post.id}}\n + #{comment.to_xml} " objects = parse_objects_from_xml(xml) comment = objects.first comment.text.should == "Freedom!" comment.person.should == friend comment.post.should == post - end end From a7d46bffab01a9eead4d1463394f657e85e1fecd Mon Sep 17 00:00:00 2001 From: ilya Date: Sat, 26 Jun 2010 02:08:19 -0400 Subject: [PATCH 04/10] removed socket.js --- public/javascripts/socket.js | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 public/javascripts/socket.js diff --git a/public/javascripts/socket.js b/public/javascripts/socket.js deleted file mode 100644 index 7db6c9130..000000000 --- a/public/javascripts/socket.js +++ /dev/null @@ -1,14 +0,0 @@ -$(document).ready(function(){ - function debug(str){ $("#debug").append("

" + str); }; - - ws = new WebSocket("ws://localhost:8080/"); - ws.onmessage = function(evt) { - $("#stream").prepend($(evt.data).fadeIn("fast")); - }; - ws.onclose = function() { debug("socket closed"); }; - ws.onopen = function() { - debug("connected..."); - //ws.send("hello server"); - // ws.send("hello again"); - }; -}); From c99416ca670c3bfb19b2b1781988c531c4d1722e Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 25 Jun 2010 23:08:59 -0700 Subject: [PATCH 05/10] fixed a broken common.rb spec --- lib/common.rb | 2 +- spec/lib/common_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/common.rb b/lib/common.rb index 0d1320361..36bfcd2fe 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -7,7 +7,7 @@ module Diaspora def notify_friends if self.person_id == User.first.id - xml = Post.build_xml_for(self) + xml = Post.build_xml_for([self]) @@queue.add_post_request( friends_with_permissions, CGI::escape(xml) ) @@queue.process end diff --git a/spec/lib/common_spec.rb b/spec/lib/common_spec.rb index 3b4be323b..8a37fc20a 100644 --- a/spec/lib/common_spec.rb +++ b/spec/lib/common_spec.rb @@ -59,8 +59,8 @@ describe Diaspora do end it "should send an owners post to their friends" do - Post.stub(:build_xml_for).and_return(true) - Post.should_receive(:build_xml_for).and_return true + q = Post.send (:class_variable_get, :@@queue) + q.should_receive :process @post.save end From 2bbfcb0bb1af5ab64d3416df6d02f1ccef7fb719 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Sat, 26 Jun 2010 14:16:19 -0700 Subject: [PATCH 07/10] putting debug in for master so I can check deployed servers out --- app/controllers/dashboard_controller.rb | 4 +++- app/helpers/application_helper.rb | 2 +- app/models/post.rb | 4 ---- lib/message_handler.rb | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 834b33395..0dae8e54e 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -9,7 +9,9 @@ class DashboardController < ApplicationController def receive - store_posts_from_xml CGI::unescape(params[:xml]) + xml = CGI::unescape(params[:xml]) + puts xml + store_posts_from_xml xml render :nothing => true end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ce2847aa0..2865c3476 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -67,7 +67,7 @@ module ApplicationHelper when "User" user_path(person) else - "#" + link_to "unknown person", "#" end end diff --git a/app/models/post.rb b/app/models/post.rb index 6a450ebac..0aba89918 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -25,10 +25,6 @@ class Post Post.sort(:created_at.desc).all end - def each - yield self - end - def self.newest(person = nil) return self.last if person.nil? diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 7d75ce08c..6fb15dfbe 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -25,7 +25,7 @@ class MessageHandler case query.type when :post http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body} - http.callback { process} + http.callback {puts query.inspect; process} when :get http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT http.callback {send_to_seed(query, http.response); process} From 4402a84c32bb3e8959421dcd9f7a25761e8d3c0c Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Sat, 26 Jun 2010 15:21:23 -0700 Subject: [PATCH 08/10] fixed the webhook bug, now going to deploy and test --- app/controllers/dashboard_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 0dae8e54e..183d0db99 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -11,7 +11,7 @@ class DashboardController < ApplicationController def receive xml = CGI::unescape(params[:xml]) puts xml - store_posts_from_xml xml + store_objects_from_xml xml render :nothing => true end From b804bdc220ae47c7f2661d19cef66c5883722341 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Sat, 26 Jun 2010 15:40:33 -0700 Subject: [PATCH 09/10] forgot to take out a debug line. i kept comments in, but they prevent a new post to be sent from the database to the view. on refresh everything works. also moved comments to its own partial so we can add it to all posts --- app/controllers/dashboard_controller.rb | 4 +--- app/views/comments/_new_comment.html.haml | 3 +-- app/views/layouts/application.html.haml | 2 +- app/views/status_messages/_status_message.html.haml | 7 +------ 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 183d0db99..4bf1ade9d 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -9,9 +9,7 @@ class DashboardController < ApplicationController def receive - xml = CGI::unescape(params[:xml]) - puts xml - store_objects_from_xml xml + store_objects_from_xml CGI::unescape(params[:xml]) render :nothing => true end diff --git a/app/views/comments/_new_comment.html.haml b/app/views/comments/_new_comment.html.haml index 0480c968f..b377602e3 100644 --- a/app/views/comments/_new_comment.html.haml +++ b/app/views/comments/_new_comment.html.haml @@ -1,7 +1,6 @@ = form_for Comment.new, :remote => true do |f| = f.error_messages %p - /= f.label :message = f.text_field :text, :value => "dislike!" = f.hidden_field :post_id, :value => post.id - = f.submit 'comment', :class => 'button' \ No newline at end of file + = f.submit 'comment', :class => 'button' diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 8377906d2..ed68a43be 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -2,7 +2,7 @@ %html %head %title - = yield(:title) || "diaspora" + = "diaspora" %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ %meta{"http-equiv"=> "X-UA-Compatible", :content =>"chrome=1" } diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index 0eb914faf..d1c6611c1 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -4,12 +4,7 @@ = post.message %div.time = link_to "#{time_ago_in_words(post.updated_at)} ago", status_message_path(post) - %div.comments - = render "comments/new_comment", :post => post - %ul.comment_set - - for comment in post.comments - = render "comments/comment", :comment => comment - + = render "comments/comments", :post => post - if mine?(post) = link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete From b017f1b0f9cd9c6427bf57176a4b8beddee7cd36 Mon Sep 17 00:00:00 2001 From: maxwell Date: Sat, 26 Jun 2010 23:43:30 -0700 Subject: [PATCH 10/10] forgot to add partial file to git...sorry --- app/views/comments/_comments.html.haml | 6 ++++++ app/views/layouts/application.html.haml | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 app/views/comments/_comments.html.haml diff --git a/app/views/comments/_comments.html.haml b/app/views/comments/_comments.html.haml new file mode 100644 index 000000000..374f585e5 --- /dev/null +++ b/app/views/comments/_comments.html.haml @@ -0,0 +1,6 @@ +%div.comments + = render "comments/new_comment", :post => post + %ul.comment_set + - for comment in post.comments + = render "comments/comment", :comment => comment + diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index ed68a43be..d10b10d2f 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -26,8 +26,6 @@ :javascript $(document).ready(function(){ - - function debug(str){ $("#debug").append("

" + str); }; ws = new WebSocket("ws://#{request.host}:8080/");