From 25198a7e8642fef356dc1914544007cb55088bbe Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 28 Jun 2010 15:56:46 -0400 Subject: [PATCH 1/8] IZ, RS; Moved XML parser to lib --- app/helpers/application_helper.rb | 42 ++---------------------------- lib/common.rb | 43 +++++++++++++++++++++++++++++++ spec/helpers/parser_spec.rb | 22 ++++------------ 3 files changed, 50 insertions(+), 57 deletions(-) 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/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/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 From 44b25e3eaa58d2b1774241ee8952e101276d058e Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 28 Jun 2010 17:02:26 -0400 Subject: [PATCH 2/8] DG IZ; fixed javascript bug. stream fades in recents again. --- app/views/layouts/application.html.haml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index a6fde39ea..399d69c06 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -30,17 +30,16 @@ 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..."); - }; + 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}" From 5cf2e3c3eaeb3e35918c18d216d98cea779a5592 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 28 Jun 2010 14:47:23 -0700 Subject: [PATCH 3/8] commiting so i can pull --- app/controllers/comments_controller.rb | 3 +++ app/views/comments/_comments.html.haml | 2 +- app/views/comments/_new_comment.html.haml | 10 +++++----- config/initializers/socket.rb | 17 +++++++++-------- lib/message_handler.rb | 10 +++++----- 5 files changed, 23 insertions(+), 19 deletions(-) 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/views/comments/_comments.html.haml b/app/views/comments/_comments.html.haml index 374f585e5..50af21178 100644 --- a/app/views/comments/_comments.html.haml +++ b/app/views/comments/_comments.html.haml @@ -1,5 +1,5 @@ %div.comments - = render "comments/new_comment", :post => post + /= render "comments/new_comment", :post => post %ul.comment_set - for comment in post.comments = render "comments/comment", :comment => comment diff --git a/app/views/comments/_new_comment.html.haml b/app/views/comments/_new_comment.html.haml index b377602e3..7cfc43756 100644 --- a/app/views/comments/_new_comment.html.haml +++ b/app/views/comments/_new_comment.html.haml @@ -1,6 +1,6 @@ -= form_for Comment.new, :remote => true do |f| - = f.error_messages += form_tag("/comments",:remote => true, :class =>"new_comment", :id => "new_comment") 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", :name => "commit" + diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index a6e9a6aa1..b55c3e185 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -10,6 +10,7 @@ module WebSocket class << @view include ApplicationHelper include Rails.application.routes.url_helpers + include ActionView::Helpers::FormTagHelper end end @@ -30,14 +31,14 @@ module WebSocket end def self.view_hash(object) - #begin - # puts "I be working hard" - v = WebSocket.view_for(object) - #puts view.inspect - #rescue - # puts "in failzord " + view.inspect - # raise "i suck" - #end + begin + puts "I be working hard" + v = WebSocket.view_for(object) + puts v.inspect + rescue + puts "in failzord " + v .inspect + raise "i suck" + end {:class =>object.class.to_s.underscore.pluralize, :html => v} end diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 6fb15dfbe..8a7845e4f 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 @@ -17,6 +13,9 @@ class MessageHandler def add_post_request(destinations, body) + puts "yay" + puts destinations.inspect + puts body.inspect destinations.each{|dest| @queue.push(Message.new(:post, dest, body))} end @@ -25,7 +24,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 {puts query.body; process} when :get http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT http.callback {send_to_seed(query, http.response); process} @@ -34,6 +33,7 @@ class MessageHandler end http.errback { + puts query.destination + " failed!" query.try_count +=1 @queue.push query unless query.try_count >= NUM_TRIES process From b6c63168868036b4ebec14bd7081ec69afcdf1b2 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 28 Jun 2010 15:03:45 -0700 Subject: [PATCH 4/8] trying to fix status message bug --- app/views/status_messages/_status_message.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 2b42ef216cceec5ccb42a772ca04539e78aaa9e6 Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 28 Jun 2010 18:20:56 -0400 Subject: [PATCH 5/8] DG IZ; added a profile; one-to-one relation with Person (non-singleton) --- app/models/person.rb | 8 ++------ app/models/post.rb | 8 +------- app/models/profile.rb | 11 +++++++++++ spec/factories.rb | 32 ++++++++++++++++++++++++-------- spec/models/friend_spec.rb | 20 -------------------- spec/models/person_spec.rb | 12 ++++++++++++ spec/models/profile_spec.rb | 32 ++++++++++++++++++++++++++++++++ 7 files changed, 82 insertions(+), 41 deletions(-) create mode 100644 app/models/profile.rb create mode 100644 spec/models/person_spec.rb create mode 100644 spec/models/profile_spec.rb diff --git a/app/models/person.rb b/app/models/person.rb index d0db04eb2..a7ccdbf0e 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -8,13 +8,9 @@ class Person 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, :real_name, :profile - # def newest(type = nil) - # type.constantize.where(:person_id => id).last - # end end diff --git a/app/models/post.rb b/app/models/post.rb index 683083b30..2258979d1 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 diff --git a/app/models/profile.rb b/app/models/profile.rb new file mode 100644 index 000000000..16a3d22b3 --- /dev/null +++ b/app/models/profile.rb @@ -0,0 +1,11 @@ +class Profile + include MongoMapper::Document + + key :first_name, String + key :last_name, String + + belongs_to :person, :class_name => "Person" + + validates_presence_of :first_name, :last_name, :person + +end diff --git a/spec/factories.rb b/spec/factories.rb index ded4bf247..306471d97 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,11 +1,33 @@ #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", :real_name => "Bob" ) +end + +Factory.define :person do |p| + p.email "bob@aol.com" + p.real_name "Bob" + p.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" ) +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" + 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 +39,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 +47,4 @@ end Factory.define :post do |p| end -Factory.define(:comment) {} \ No newline at end of file +Factory.define(:comment) {} diff --git a/spec/models/friend_spec.rb b/spec/models/friend_spec.rb index 32ef8eaeb..5ef06a625 100644 --- a/spec/models/friend_spec.rb +++ b/spec/models/friend_spec.rb @@ -16,7 +16,6 @@ describe Friend do n.valid?.should be true end - it 'should validate its url' do friend = Factory.build(:friend) @@ -65,23 +64,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..0701b8c69 --- /dev/null +++ b/spec/models/person_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe Person do + + it 'should require a profile' do + person = Factory.build(:person, :profile => nil) + person.valid?.should be false + person.profile = Factory.build(:profile) + person.valid?.should be true + end + +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 + From f4a8671854b6e0ed60c32253a45c18088f6a726a Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 28 Jun 2010 16:15:30 -0700 Subject: [PATCH 6/8] fixed the remote socket updating bug? we will see --- app/models/post.rb | 3 +-- app/views/comments/_comments.html.haml | 2 +- app/views/layouts/application.html.haml | 1 + .../status_messages/_status_message.html.haml | 2 +- config/initializers/socket.rb | 18 +++++++++++------- lib/message_handler.rb | 5 +---- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 683083b30..4567537c9 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -43,8 +43,7 @@ class Post protected def send_to_view - self.reload - WebSocket.update_clients(self) + WebSocket.update_clients(self) end diff --git a/app/views/comments/_comments.html.haml b/app/views/comments/_comments.html.haml index 50af21178..374f585e5 100644 --- a/app/views/comments/_comments.html.haml +++ b/app/views/comments/_comments.html.haml @@ -1,5 +1,5 @@ %div.comments - /= render "comments/new_comment", :post => post + = 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 399d69c06..42b1577d7 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -30,6 +30,7 @@ ws = new WebSocket("ws://#{request.host}:8080/"); ws.onmessage = function(evt) { var obj = jQuery.parseJSON(evt.data); + debug("got a " + obj['class']); if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) { $("#stream").prepend($(obj['html']).fadeIn("fast")); }; diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index f9ec3c03b..5e643efae 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -4,7 +4,7 @@ = post.message %div.time = link_to(how_long_ago(post), status_message_path(post)) - = render "comments/comments", :post => 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 b3542cf34..52c8ea3d9 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -5,20 +5,21 @@ 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 ActionView::Helpers::FormTagHelper + #include ActionView::Helpers::FormTagHelper 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) } } @@ -33,10 +34,13 @@ module WebSocket begin puts "I be working hard" v = WebSocket.view_for(object) - puts v.inspect - rescue - puts "in failzord " + v .inspect - raise "i suck" + puts v.inspect + + rescue Exception > e + puts "in failzord " + v.inspect + puts object.inspect + puts e.inspect + raise e end {:class =>object.class.to_s.underscore.pluralize, :html => v} diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 8a7845e4f..91226a426 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -13,9 +13,6 @@ class MessageHandler def add_post_request(destinations, body) - puts "yay" - puts destinations.inspect - puts body.inspect destinations.each{|dest| @queue.push(Message.new(:post, dest, body))} end @@ -24,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.body; process} + http.callback {process} when :get http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT http.callback {send_to_seed(query, http.response); process} From 36b5a90d340e88ad039e246e9fe0f7472c3bf679 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 28 Jun 2010 17:35:38 -0700 Subject: [PATCH 7/8] MS figured out how to get comments to come thru the websocket. this is super super super hacky, and kind of terrible, but it works --- app/helpers/status_messages_helper.rb | 2 +- app/views/comments/_new_comment.html.haml | 5 ++--- app/views/layouts/application.html.haml | 2 +- app/views/status_messages/_status_message.html.haml | 2 +- config/initializers/socket.rb | 13 +++++++++---- public/javascripts/view.js | 1 + 6 files changed, 15 insertions(+), 10 deletions(-) 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/views/comments/_new_comment.html.haml b/app/views/comments/_new_comment.html.haml index 7cfc43756..bb16dffbb 100644 --- a/app/views/comments/_new_comment.html.haml +++ b/app/views/comments/_new_comment.html.haml @@ -1,6 +1,5 @@ -= form_tag("/comments",:remote => true, :class =>"new_comment", :id => "new_comment") do += form_tag("/comments", :remote => true, :class =>"new_comment", :id => "new_comment-#{post.id}") do %p = 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", :name => "commit" - + = submit_tag 'comment', :id => "comment_submit_#{post.id}", :name => "commit" diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 42b1577d7..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' diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index 5e643efae..f9ec3c03b 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -4,7 +4,7 @@ = post.message %div.time = link_to(how_long_ago(post), status_message_path(post)) - /= render "comments/comments", :post => 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 52c8ea3d9..61fb85d59 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -11,7 +11,12 @@ module WebSocket class << @view include ApplicationHelper include Rails.application.routes.url_helpers - #include ActionView::Helpers::FormTagHelper + include ActionController::RequestForgeryProtection::ClassMethods + include ActionView::Helpers::FormTagHelper + include ActionView::Helpers::UrlHelper + def protect_against_forgery? + false + end end end @@ -36,13 +41,13 @@ module WebSocket v = WebSocket.view_for(object) puts v.inspect - rescue Exception > e + rescue Exception => e puts "in failzord " + v.inspect puts object.inspect - puts e.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/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(""); From b5b9c647d76e542e6fc2b2f4937e386d6aa65582 Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 28 Jun 2010 21:32:09 -0400 Subject: [PATCH 8/8] DG IZ Created the profile model & friend view now shows the information --- app/controllers/friends_controller.rb | 1 + app/models/person.rb | 7 ++++--- app/models/profile.rb | 6 ++++-- app/models/user.rb | 1 + app/views/bookmarks/_form.html.haml | 12 ++++++++++++ app/views/friends/new.html.haml | 4 ---- app/views/friends/show.html.haml | 19 ++++++++++++++++++- spec/factories.rb | 5 +---- spec/models/friend_spec.rb | 19 +++++++------------ spec/models/person_spec.rb | 8 -------- spec/models/user_spec.rb | 11 ----------- 11 files changed, 48 insertions(+), 45 deletions(-) create mode 100644 app/views/bookmarks/_form.html.haml 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/models/person.rb b/app/models/person.rb index a7ccdbf0e..7428e9b5f 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -3,14 +3,15 @@ class Person include ROXML xml_accessor :email - xml_accessor :real_name key :email, String - key :real_name, String one :profile, :class_name => 'Profile', :foreign_key => :person_id many :posts, :class_name => 'Post', :foreign_key => :person_id - validates_presence_of :email, :real_name, :profile + validates_presence_of :email + def real_name + self.profile.first_name + " " + self.profile.last_name + end end diff --git a/app/models/profile.rb b/app/models/profile.rb index 16a3d22b3..0e4e6c913 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -4,8 +4,10 @@ class Profile key :first_name, String key :last_name, String - belongs_to :person, :class_name => "Person" + key :person_id, ObjectId - validates_presence_of :first_name, :last_name, :person + 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/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/spec/factories.rb b/spec/factories.rb index 306471d97..b75cdbc92 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -6,17 +6,15 @@ Factory.define :profile do |p| p.first_name "Robert" p.last_name "Grimm" - p.person Person.new( :email => "bob@aol.com", :real_name => "Bob" ) + p.person Person.new( :email => "bob@aol.com" ) end Factory.define :person do |p| p.email "bob@aol.com" - p.real_name "Bob" p.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" ) 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" @@ -24,7 +22,6 @@ Factory.define :user do |u| 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" ) diff --git a/spec/models/friend_spec.rb b/spec/models/friend_spec.rb index 5ef06a625..5861742a1 100644 --- a/spec/models/friend_spec.rb +++ b/spec/models/friend_spec.rb @@ -2,18 +2,13 @@ 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 - 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 + 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 validate its url' do diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 0701b8c69..ddd91e38d 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -1,12 +1,4 @@ require 'spec_helper' describe Person do - - it 'should require a profile' do - person = Factory.build(:person, :profile => nil) - person.valid?.should be false - person.profile = Factory.build(:profile) - person.valid?.should be true - 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