diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
index 0a31a4604..785f20320 100644
--- a/app/controllers/comments_controller.rb
+++ b/app/controllers/comments_controller.rb
@@ -4,6 +4,9 @@ class CommentsController < ApplicationController
def create
target = Post.first(:id => params[:comment][:post_id])
text = params[:comment][:text]
+ puts params.inspect
+
+
if current_user.comment text, :on => target
render :text => "Woo!"
else
diff --git a/app/controllers/friends_controller.rb b/app/controllers/friends_controller.rb
index ebf2c1df8..a13c3f2e4 100644
--- a/app/controllers/friends_controller.rb
+++ b/app/controllers/friends_controller.rb
@@ -7,6 +7,7 @@ class FriendsController < ApplicationController
def show
@friend = Friend.where(:id => params[:id]).first
+ @friend_profile = @friend.profile
@friend_posts = Post.where(:person_id => @friend.id).sort(:created_at.desc)
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 2865c3476..a77a671d8 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,4 +1,6 @@
module ApplicationHelper
+ require 'lib/common'
+ include Diaspora::XMLParser
def object_path(object)
eval("#{object.class.to_s.underscore}_path(object)")
end
@@ -7,46 +9,6 @@ module ApplicationHelper
object.attributes.keys
end
- def parse_sender_id_from_xml(xml)
- doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
- doc.xpath("/XML/head/sender/email").text.to_s
- end
-
- def parse_sender_object_from_xml(xml)
- sender_id = parse_sender_id_from_xml(xml)
- Friend.where(:email => sender_id).first
- end
-
- def parse_body_contents_from_xml(xml)
- doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
- doc.xpath("/XML/posts/post")
- end
-
- 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 if object.is_a? Post
- objects << object
- rescue
- puts "Not a real type: #{object.to_s}"
- end
- end
- objects
- end
-
- def store_objects_from_xml(xml)
- objects = parse_objects_from_xml(xml)
-
- objects.each do |p|
- p.save if p.respond_to?(:person) && !(p.person.nil?) #WTF
- #p.save if p.respond_to?(:person) && !(p.person == nil) #WTF
- end
- end
-
def mine?(post)
post.person == User.first
end
diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb
index 32a742d9e..2e933d784 100644
--- a/app/helpers/status_messages_helper.rb
+++ b/app/helpers/status_messages_helper.rb
@@ -3,7 +3,7 @@ module StatusMessagesHelper
def my_latest_message
message = StatusMessage.my_newest
unless message.nil?
- return message.message + " " + how_long_ago(message)
+ return message.message + " - " + how_long_ago(message)
else
return "No message to display."
end
diff --git a/app/models/person.rb b/app/models/person.rb
index d0db04eb2..7428e9b5f 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -3,18 +3,15 @@ class Person
include ROXML
xml_accessor :email
- xml_accessor :real_name
key :email, String
- key :real_name, String
- #key :post_ids, Array#, :typecast => ObjectId
-
+ one :profile, :class_name => 'Profile', :foreign_key => :person_id
many :posts, :class_name => 'Post', :foreign_key => :person_id
- validates_presence_of :email, :real_name
+ validates_presence_of :email
- # def newest(type = nil)
- # type.constantize.where(:person_id => id).last
- # end
+ def real_name
+ self.profile.first_name + " " + self.profile.last_name
+ end
end
diff --git a/app/models/post.rb b/app/models/post.rb
index 683083b30..1366e2877 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -8,19 +8,13 @@ class Post
xml_accessor :_id
key :person_id, ObjectId
- belongs_to :person, :class_name => 'Person'
-
many :comments, :class_name => 'Comment', :foreign_key => :post_id
+ belongs_to :person, :class_name => 'Person'
timestamps!
-
-
after_save :send_to_view
- #validates_presence_of :person
-
-
def self.stream
Post.sort(:created_at.desc).all
@@ -43,8 +37,7 @@ class Post
protected
def send_to_view
- self.reload
- WebSocket.update_clients(self)
+ WebSocket.update_clients(self)
end
diff --git a/app/models/profile.rb b/app/models/profile.rb
new file mode 100644
index 000000000..0e4e6c913
--- /dev/null
+++ b/app/models/profile.rb
@@ -0,0 +1,13 @@
+class Profile
+ include MongoMapper::Document
+
+ key :first_name, String
+ key :last_name, String
+
+ key :person_id, ObjectId
+
+ belongs_to :person
+
+ validates_presence_of :first_name, :last_name, :person_id
+
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index c2b03629e..1751f15a1 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -14,6 +14,7 @@ class User < Person
Comment.new(:person_id => self.id, :text => text, :post => options[:on]).save
end
+ validates_presence_of :profile
before_validation :do_bad_things
def do_bad_things
diff --git a/app/views/bookmarks/_form.html.haml b/app/views/bookmarks/_form.html.haml
new file mode 100644
index 000000000..0e02f4082
--- /dev/null
+++ b/app/views/bookmarks/_form.html.haml
@@ -0,0 +1,12 @@
+= form_for @bookmark do |f|
+ = f.error_messages
+ %p
+ = f.label :title
+ %br
+ = f.text_field :title
+ %p
+ = f.label :link
+ %br
+ = f.text_field :link
+ %p
+ = f.submit
diff --git a/app/views/comments/_new_comment.html.haml b/app/views/comments/_new_comment.html.haml
index b377602e3..bb16dffbb 100644
--- a/app/views/comments/_new_comment.html.haml
+++ b/app/views/comments/_new_comment.html.haml
@@ -1,6 +1,5 @@
-= form_for Comment.new, :remote => true do |f|
- = f.error_messages
+= form_tag("/comments", :remote => true, :class =>"new_comment", :id => "new_comment-#{post.id}") do
%p
- = f.text_field :text, :value => "dislike!"
- = f.hidden_field :post_id, :value => post.id
- = f.submit 'comment', :class => 'button'
+ = text_field_tag "comment_text", 'dislike!', :size => 30, :name => 'comment[text]'
+ = hidden_field_tag "comment_post_id", "#{post.id}", :name => "comment[post_id]"
+ = submit_tag 'comment', :id => "comment_submit_#{post.id}", :name => "commit"
diff --git a/app/views/friends/new.html.haml b/app/views/friends/new.html.haml
index 161bd0250..d8f89f2f6 100644
--- a/app/views/friends/new.html.haml
+++ b/app/views/friends/new.html.haml
@@ -2,10 +2,6 @@
= form_for @friend do |f|
= f.error_messages
- %p
- = f.label :real_name
- %br
- = f.text_field :real_name
%p
= f.label :email
%br
diff --git a/app/views/friends/show.html.haml b/app/views/friends/show.html.haml
index f4218409b..5e91a295d 100644
--- a/app/views/friends/show.html.haml
+++ b/app/views/friends/show.html.haml
@@ -1,5 +1,22 @@
-%h1= "#{@friend.real_name}'s network stream"
+%h1= "#{@friend.real_name}"
+
+- if @friend_profile
+ %p
+ %b First Name
+ %p
+ = @friend_profile.first_name
+ %p
+ %b Last Name
+ %p
+ = @friend_profile.last_name
+
+%br
+%br
+%br
+%br
+
- if @friend.posts
+ %h3 stream
%ul#stream
- for post in @friend_posts
= render type_partial(post), :post => post
diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml
index a6fde39ea..31b14138f 100644
--- a/app/views/layouts/application.html.haml
+++ b/app/views/layouts/application.html.haml
@@ -8,7 +8,7 @@
= stylesheet_link_tag "blueprint/screen", :media => 'screen'
= stylesheet_link_tag "application"
- /= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"
+ /= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
= javascript_include_tag 'jquery142', 'rails', 'view'
= javascript_include_tag 'tiny_mce/tiny_mce.js'
@@ -30,17 +30,17 @@
ws = new WebSocket("ws://#{request.host}:8080/");
ws.onmessage = function(evt) {
var obj = jQuery.parseJSON(evt.data);
- if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) {
- $("#stream").prepend($(obj['html']).fadeIn("fast"));
- };
- }
- ws.onclose = function() { debug("socket closed"); };
- ws.onopen = function() {
- ws.send(location.pathname);
- debug("connected...");
- };
+ debug("got a " + obj['class']);
+ if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) {
+ $("#stream").prepend($(obj['html']).fadeIn("fast"));
+ };
+ };
+ ws.onclose = function() { debug("socket closed"); };
+ ws.onopen = function() {
+ ws.send(location.pathname);
+ debug("connected...");
+ };
});
- });
%body
- flash.each do |name, msg|
= content_tag :div, msg, :id => "flash_#{name}"
diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml
index a0dc4336b..f9ec3c03b 100644
--- a/app/views/status_messages/_status_message.html.haml
+++ b/app/views/status_messages/_status_message.html.haml
@@ -3,7 +3,7 @@
= link_to_person post.person
= post.message
%div.time
- = link_to "#{time_ago_in_words(post.updated_at)} ago", status_message_path(post)
+ = link_to(how_long_ago(post), status_message_path(post))
= render "comments/comments", :post => post
- if mine?(post)
= link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete
diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb
index de5eb3f3c..61fb85d59 100644
--- a/config/initializers/socket.rb
+++ b/config/initializers/socket.rb
@@ -5,19 +5,26 @@ module WebSocket
EM.next_tick {
EM.add_timer(0.1) do
@channel = EM::Channel.new
+ puts @channel.inspect
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
class << @view
include ApplicationHelper
include Rails.application.routes.url_helpers
+ include ActionController::RequestForgeryProtection::ClassMethods
+ include ActionView::Helpers::FormTagHelper
+ include ActionView::Helpers::UrlHelper
+ def protect_against_forgery?
+ false
+ end
end
end
- EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug =>false) do |ws|
+ EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug =>true) do |ws|
ws.onopen {
sid = @channel.subscribe { |msg| ws.send msg }
- ws.onmessage { |msg|}#@channel.push msg; puts msg}
+ ws.onmessage { |msg| }#@channel.push msg; puts msg}
ws.onclose { @channel.unsubscribe(sid) }
}
@@ -29,8 +36,18 @@ module WebSocket
end
def self.view_hash(object)
- v = WebSocket.view_for(object)
- puts v
+ begin
+ puts "I be working hard"
+ v = WebSocket.view_for(object)
+ puts v.inspect
+
+ rescue Exception => e
+ puts "in failzord " + v.inspect
+ puts object.inspect
+ puts e.message
+ raise e
+ end
+ puts "i made it here"
{:class =>object.class.to_s.underscore.pluralize, :html => v}
end
diff --git a/lib/common.rb b/lib/common.rb
index 36bfcd2fe..99cbb3f50 100644
--- a/lib/common.rb
+++ b/lib/common.rb
@@ -1,4 +1,47 @@
module Diaspora
+ module XMLParser
+ def parse_sender_id_from_xml(xml)
+ doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
+ doc.xpath("/XML/head/sender/email").text.to_s
+ end
+
+ def parse_sender_object_from_xml(xml)
+ sender_id = parse_sender_id_from_xml(xml)
+ Friend.where(:email => sender_id).first
+ end
+
+ def parse_body_contents_from_xml(xml)
+ doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
+ doc.xpath("/XML/posts/post")
+ end
+
+ 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 if object.is_a? Post
+ objects << object
+ rescue
+ puts "Not a real type: #{object.to_s}"
+ end
+ end
+ objects
+ end
+
+ def store_objects_from_xml(xml)
+ objects = parse_objects_from_xml(xml)
+
+ objects.each do |p|
+ p.save if p.respond_to?(:person) && !(p.person.nil?) #WTF
+ #p.save if p.respond_to?(:person) && !(p.person == nil) #WTF
+ end
+ end
+
+
+ end
module Webhooks
def self.included(klass)
klass.class_eval do
diff --git a/lib/message_handler.rb b/lib/message_handler.rb
index 6fb15dfbe..91226a426 100644
--- a/lib/message_handler.rb
+++ b/lib/message_handler.rb
@@ -1,7 +1,3 @@
-# require 'addressable/uri'
-# require 'eventmachine'
-# require 'em-http'
-
class MessageHandler
NUM_TRIES = 3
@@ -25,7 +21,7 @@ class MessageHandler
case query.type
when :post
http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body}
- http.callback {puts query.inspect; process}
+ http.callback {process}
when :get
http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT
http.callback {send_to_seed(query, http.response); process}
@@ -34,6 +30,7 @@ class MessageHandler
end
http.errback {
+ puts query.destination + " failed!"
query.try_count +=1
@queue.push query unless query.try_count >= NUM_TRIES
process
diff --git a/public/javascripts/view.js b/public/javascripts/view.js
index 3593fa4c6..31ab2d57e 100644
--- a/public/javascripts/view.js
+++ b/public/javascripts/view.js
@@ -30,6 +30,7 @@ $(document).ready(function(){
$('#bookmark_title').click(clearForm);
$('#bookmark_link').click(clearForm);
+ $('#debug_more').hide();
function clearForm(){
$(this).val("");
diff --git a/spec/factories.rb b/spec/factories.rb
index ded4bf247..b75cdbc92 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -1,11 +1,30 @@
#For Guidance
#http://github.com/thoughtbot/factory_girl
-#http://railscasts.com/episodes/158-factories-not-fixtures
+# http://railscasts.com/episodes/158-factories-not-fixtures
+
+
+Factory.define :profile do |p|
+ p.first_name "Robert"
+ p.last_name "Grimm"
+ p.person Person.new( :email => "bob@aol.com" )
+end
+
+Factory.define :person do |p|
+ p.email "bob@aol.com"
+ p.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" )
+end
+
+Factory.define :user do |u|
+ u.sequence(:email) {|n| "bob#{n}@aol.com"}
+ u.password "bluepin7"
+ u.password_confirmation "bluepin7"
+ u.profile Profile.new( :first_name => "Bob", :last_name => "Smith" )
+end
Factory.define :friend do |f|
- f.real_name 'John Doe'
f.email 'max@max.com'
f.url 'http://max.com/'
+ f.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" )
end
Factory.define :status_message do |m|
@@ -17,12 +36,6 @@ Factory.define :blog do |b|
b.sequence(:body) {|n| "jimmy's huge #{n} whales"}
end
-Factory.define :user do |u|
- u.real_name 'Bob Smith'
- u.sequence(:email) {|n| "bob#{n}@aol.com"}
- u.password "bluepin7"
- u.password_confirmation "bluepin7"
-end
Factory.define :bookmark do |b|
b.link "http://www.yahooligans.com/"
@@ -31,4 +44,4 @@ end
Factory.define :post do |p|
end
-Factory.define(:comment) {}
\ No newline at end of file
+Factory.define(:comment) {}
diff --git a/spec/helpers/parser_spec.rb b/spec/helpers/parser_spec.rb
index 40fe5aea5..3cc11f71c 100644
--- a/spec/helpers/parser_spec.rb
+++ b/spec/helpers/parser_spec.rb
@@ -15,19 +15,7 @@ describe "parser in application helper" do
store_objects_from_xml(xml)
StatusMessage.count.should == 0
end
- it 'should discard posts where it does not know the type' do
- xml = "
-
-
- #{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_objects_from_xml(xml)
- Post.count.should == 2
- Post.first.person.email.should == Friend.first.email
- end
+
it "should reject xml with no sender" do
xml = "
@@ -40,6 +28,7 @@ describe "parser in application helper" do
Post.count.should == 0
end
+
it "should reject xml with a sender not in the database" do
xml = "
@@ -54,6 +43,7 @@ describe "parser in application helper" do
store_objects_from_xml(xml)
Post.count.should == 0
end
+
it 'should discard types which are not of type post' do
xml = "
@@ -62,13 +52,11 @@ 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_objects_from_xml(xml)
- Post.count.should == 2
- Post.first.person.email.should == Friend.first.email
+ Post.count.should == 0
end
diff --git a/spec/models/friend_spec.rb b/spec/models/friend_spec.rb
index 32ef8eaeb..5861742a1 100644
--- a/spec/models/friend_spec.rb
+++ b/spec/models/friend_spec.rb
@@ -2,21 +2,15 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe Friend do
- it 'should require a diaspora username and diaspora url' do
- n = Factory.build(:friend, :url => nil)
- n.valid?.should be false
- n.url = "http://max.com/"
- n.valid?.should be true
+ describe 'requirements' do
+ it 'should include a url' do
+ n = Factory.build(:friend, :url => nil)
+ n.valid?.should be false
+ n.url = "http://max.com/"
+ n.valid?.should be true
+ end
end
- it 'should require a real name' do
- n = Factory.build(:friend, :real_name => nil)
- n.valid?.should be false
- n.real_name = "John Smith"
- n.valid?.should be true
- end
-
-
it 'should validate its url' do
friend = Factory.build(:friend)
@@ -65,23 +59,4 @@ describe Friend do
friend.url = "http:///www.asodij.com/"
friend.valid?.should == false
end
-
- describe "XML" do
- before do
- @f = Factory.build(:friend)
- @xml = "\n #{@f.url}\n #{@f.email}\n #{@f.real_name}\n"
- end
-
- it 'should serialize to XML' do
- @f.to_xml.to_s.should == @xml
- end
-
- it 'should marshal serialized XML to object' do
- parsed = Friend.from_xml(@xml)
- parsed.email.should == @f.email
- parsed.url.should == @f.url
- parsed.valid?.should be_true
- end
- end
-
end
diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb
new file mode 100644
index 000000000..ddd91e38d
--- /dev/null
+++ b/spec/models/person_spec.rb
@@ -0,0 +1,4 @@
+require 'spec_helper'
+
+describe Person do
+end
diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb
new file mode 100644
index 000000000..5cb57b270
--- /dev/null
+++ b/spec/models/profile_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe Profile do
+ before do
+ @person = Factory.build(:person)
+ end
+
+ describe 'requirements' do
+ it "should include a first name" do
+ @person.profile = Factory.build(:profile, :person => @person, :first_name => nil)
+ @person.profile.valid?.should be false
+ @person.profile.first_name = "Bob"
+ @person.profile.valid?.should be true
+ end
+
+ it "should include a last name" do
+ @person.profile = Factory.build(:profile, :person => @person, :last_name => nil)
+ @person.profile.valid?.should be false
+ @person.profile.last_name = "Smith"
+ @person.profile.valid?.should be true
+ end
+
+ it "should include a person" do
+ profile = Factory.build(:profile, :person => nil)
+ profile.valid?.should be false
+ profile.person = @person
+ profile.valid?.should be true
+ end
+ end
+
+end
+
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index b52406211..abdbdf22a 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1,20 +1,9 @@
require 'spec_helper'
describe User do
- it "should require a real name" do
- u = Factory.build(:user, :real_name => nil)
- u.valid?.should be false
- u.real_name = "John Smith"
- u.valid?.should be true
- end
- it "should create a valid user with the factory" do
- u = Factory.build(:user)
- u.valid?.should be true
- end
it "should be a person" do
n = Person.count
Factory.create(:user)
Person.count.should == n+1
end
-
end