From 3d105e7c1eaaf16795b63ca1140185bd5970d3af Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 7 Jul 2010 16:53:52 -0700 Subject: [PATCH] DG IZ; removed Friend model, now Person is used instead. Also, broke the websocket. --- app/controllers/application_controller.rb | 6 +- app/controllers/friend_requests_controller.rb | 41 ------------ app/controllers/people_controller.rb | 39 ++++++++++++ app/controllers/person_requests_controller.rb | 37 +++++++++++ app/helpers/application_helper.rb | 4 +- app/models/comment.rb | 10 +-- app/models/friend.rb | 7 --- app/models/friend_request.rb | 38 ------------ app/models/person.rb | 3 +- app/models/person_request.rb | 38 ++++++++++++ app/models/post.rb | 4 +- app/models/user.rb | 2 +- app/views/layouts/application.html.haml | 2 +- app/views/people/_sidebar.html.haml | 5 ++ app/views/people/index.html.haml | 19 ++++++ app/views/people/new.html.haml | 27 ++++++++ app/views/people/show.html.haml | 24 +++++++ config/routes.rb | 4 +- db/seeds.rb | 4 +- db/seeds/backer.rb | 8 +-- db/seeds/tom.rb | 4 +- lib/common.rb | 20 +++--- lib/tasks/db.rake | 3 +- spec/controllers/dashboard_controller_spec.rb | 6 +- spec/factories.rb | 7 +-- spec/helpers/application_helper_spec.rb | 8 +-- spec/lib/common_spec.rb | 29 ++++----- spec/lib/parser_spec.rb | 57 +++++++++-------- spec/lib/socket_renderer_spec.rb | 5 +- spec/models/comments_spec.rb | 36 +++++------ spec/models/friend_request_spec.rb | 36 ----------- spec/models/friend_spec.rb | 62 ------------------- spec/models/person_request_spec.rb | 36 +++++++++++ spec/models/person_spec.rb | 25 ++++---- spec/models/post_spec.rb | 28 ++++----- spec/models/retraction_spec.rb | 2 +- 36 files changed, 363 insertions(+), 323 deletions(-) delete mode 100644 app/controllers/friend_requests_controller.rb create mode 100644 app/controllers/people_controller.rb create mode 100644 app/controllers/person_requests_controller.rb delete mode 100644 app/models/friend.rb delete mode 100644 app/models/friend_request.rb create mode 100644 app/models/person_request.rb create mode 100644 app/views/people/_sidebar.html.haml create mode 100644 app/views/people/index.html.haml create mode 100644 app/views/people/new.html.haml create mode 100644 app/views/people/show.html.haml delete mode 100644 spec/models/friend_request_spec.rb delete mode 100644 spec/models/friend_spec.rb create mode 100644 spec/models/person_request_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 890d32a1c..e22044141 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base protect_from_forgery :except => :receive layout 'application' - before_filter :set_friends + before_filter :set_people layout :layout_by_resource @@ -14,8 +14,8 @@ class ApplicationController < ActionController::Base end end - def set_friends - @friends = Friend.all + def set_people + @people = Person.all end end diff --git a/app/controllers/friend_requests_controller.rb b/app/controllers/friend_requests_controller.rb deleted file mode 100644 index 3c33c049b..000000000 --- a/app/controllers/friend_requests_controller.rb +++ /dev/null @@ -1,41 +0,0 @@ -class FriendRequestsController < ApplicationController - before_filter :authenticate_user! - - def index - @friend_requests = FriendRequest.paginate :page => params[:page], :order => 'created_at DESC' - @friend_request = FriendRequest.new - @person = Person.new - end - - def show - @friend_request = FriendRequest.where(:id => params[:id]).first - end - - def destroy - @friend_request = FriendRequest.where(:id => params[:id]).first - @friend_request.destroy - flash[:notice] = "Successfully destroyed friend request." - redirect_to friend_requests_url - end - - def new - @friend_request = FriendRequest.new - @recipient = Person.new - end - - def create - @friend_request = FriendRequest.new(params[:friend_request]) - @friend_request.sender = current_user - - puts - puts - puts @recipient - - if @friend_request.save - flash[:notice] = "Successfully created friend request." - redirect_to @friend_request - else - render :action => 'new' - end - end -end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb new file mode 100644 index 000000000..24c556c46 --- /dev/null +++ b/app/controllers/people_controller.rb @@ -0,0 +1,39 @@ +class PeopleController < ApplicationController + before_filter :authenticate_user! + + def index + @people = Person.paginate :page => params[:page], :order => 'created_at DESC' + end + + def show + @person= Person.where(:id => params[:id]).first + @person_profile = @person.profile + @person_posts = Post.where(:person_id => @person.id).sort(:created_at.desc) + end + + def destroy + @person = Person.where(:id => params[:id]).first + @person.destroy + flash[:notice] = "Successfully destroyed person." + redirect_to people_url + end + + def new + @person = Person.new + @profile = Profile.new + end + + def create + + puts params.inspect + @person = Person.new(params[:person]) + + + if @person.save + flash[:notice] = "Successfully created person." + redirect_to @person + else + render :action => 'new' + end + end +end diff --git a/app/controllers/person_requests_controller.rb b/app/controllers/person_requests_controller.rb new file mode 100644 index 000000000..80430ad94 --- /dev/null +++ b/app/controllers/person_requests_controller.rb @@ -0,0 +1,37 @@ +class PersonRequestsController < ApplicationController + before_filter :authenticate_user! + + def index + @person_requests = PersonRequest.paginate :page => params[:page], :order => 'created_at DESC' + @person_request = PersonRequest.new + @person = Person.new + end + + def show + @person_request = PersonRequest.where(:id => params[:id]).first + end + + def destroy + @person_request = PersonRequest.where(:id => params[:id]).first + @person_request.destroy + flash[:notice] = "Successfully destroyed person request." + redirect_to person_requests_url + end + + def new + @person_request = PersonRequest.new + @recipient = Person.new + end + + def create + @person_request = PersonRequest.new(params[:person_request]) + @person_request.sender = current_user + + if @person_request.save + flash[:notice] = "Successfully created person request." + redirect_to @person_request + else + render :action => 'new' + end + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a0e810109..dbceffe78 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -24,10 +24,10 @@ module ApplicationHelper def person_url(person) case person.class.to_s - when "Friend" - friend_path(person) when "User" user_path(person) + when "Person" + person_path(person) else "unknown person" end diff --git a/app/models/comment.rb b/app/models/comment.rb index 98b0300fc..bcc3c929b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -17,7 +17,7 @@ class Comment key :person_id, ObjectId belongs_to :person, :class_name => "Person" - after_save :send_friends_comments_on_my_posts + after_save :send_people_comments_on_my_posts after_save :send_to_view @@ -28,9 +28,9 @@ class Comment protected - def send_friends_comments_on_my_posts - if (User.first.mine?(self.post) && self.person.is_a?(Friend)) - self.push_to(self.post.friends_with_permissions) + def send_people_comments_on_my_posts + if User.first.mine?(self.post) && !(self.person.is_a? User) + self.push_to(self.post.people_with_permissions) end end @@ -38,4 +38,4 @@ class Comment def send_to_view WebSocket.update_clients(self) end -end \ No newline at end of file +end diff --git a/app/models/friend.rb b/app/models/friend.rb deleted file mode 100644 index 33e06469b..000000000 --- a/app/models/friend.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Friend < Person - - key :active, Boolean, :default => false - - - -end diff --git a/app/models/friend_request.rb b/app/models/friend_request.rb deleted file mode 100644 index 4554f5f47..000000000 --- a/app/models/friend_request.rb +++ /dev/null @@ -1,38 +0,0 @@ -class FriendRequest - include MongoMapper::Document - include Diaspora::Webhooks - - key :url, String - - attr_accessor :sender - - validates_presence_of :url - - before_save :check_for_friend_requests - - def to_friend_xml - friend = Friend.new - friend.email = sender.email - friend.url = sender.url - friend.profile = sender.profile.clone - - friend.to_xml - end - - def self.for(url) - friend_request = FriendRequest.new(:url => url) - friend_request.sender = User.first - friend_request.save - - friend_request.push_friend_request_to_url(friend_request.url) - end - - def check_for_friend_requests - f = Friend.where(:url => self.url).first - if f - f.active = true - f.save - end - end - -end diff --git a/app/models/person.rb b/app/models/person.rb index 1e7dd0f2b..843486ad4 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -8,6 +8,7 @@ class Person key :email, String key :url, String + key :active, Boolean, :default => false one :profile, :class_name => 'Profile', :foreign_key => :person_id many :posts, :class_name => 'Post', :foreign_key => :person_id @@ -27,7 +28,7 @@ class Person before_validation :clean_url def real_name - profile.first_name.to_s + " " + profile.last_name.to_s + "#{profile.first_name.to_s} #{profile.last_name.to_s}" end diff --git a/app/models/person_request.rb b/app/models/person_request.rb new file mode 100644 index 000000000..d3c9562b9 --- /dev/null +++ b/app/models/person_request.rb @@ -0,0 +1,38 @@ +class PersonRequest + include MongoMapper::Document + include Diaspora::Webhooks + + key :url, String + + attr_accessor :sender + + validates_presence_of :url + + before_save :check_for_person_requests + + def to_person_xml + person = Person.new + person.email = sender.email + person.url = sender.url + person.profile = sender.profile.clone + + person.to_xml + end + + def self.for(url) + person_request = PersonRequest.new(:url => url) + person_request.sender = User.first + person_request.save + + person_request.push_person_request_to_url(person_request.url) + end + + def check_for_person_requests + p = Person.where(:url => self.url).first + if p + p.active = true + p.save + end + end + +end diff --git a/app/models/post.rb b/app/models/post.rb index 3598dbc34..22ebc7859 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -20,7 +20,7 @@ class Post timestamps! after_save :send_to_view - after_save :notify_friends + after_save :notify_people before_destroy :propagate_retraction after_destroy :destroy_comments, :remove_from_view @@ -49,7 +49,7 @@ class Post end def propagate_retraction - Retraction.for(self).notify_friends + Retraction.for(self).notify_people end def send_to_view diff --git a/app/models/user.rb b/app/models/user.rb index 7cd6db852..2723c8b5d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,7 +10,7 @@ class User < Person c = Comment.new(:person_id => self.id, :text => text, :post => options[:on]) if c.save if mine?(c.post) - c.push_to(c.post.friends_with_permissions) # should return plucky query + c.push_to(c.post.people_with_permissions) # should return plucky query else c.push_to([c.post.person]) end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index f75c515df..12a4159e7 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -43,7 +43,7 @@ #content.span-24.last .span-3.append-1.last = link_to owner_picture, root_path - = render 'friends/sidebar' if user_signed_in? + /= render 'friends/sidebar' if user_signed_in? .span-20 - if user_signed_in? diff --git a/app/views/people/_sidebar.html.haml b/app/views/people/_sidebar.html.haml new file mode 100644 index 000000000..996401ca7 --- /dev/null +++ b/app/views/people/_sidebar.html.haml @@ -0,0 +1,5 @@ +%h3 your people +%ul#friend_stream.nav + - for person in @people + %li= link_to person.real_name, person_path(person) +/= link_to "add a new friend", new_friend_path diff --git a/app/views/people/index.html.haml b/app/views/people/index.html.haml new file mode 100644 index 000000000..4d1d5a622 --- /dev/null +++ b/app/views/people/index.html.haml @@ -0,0 +1,19 @@ +- title "People" + +%table + %tr + %th real name + %th email + %th url + - for person in @people + %tr + %td= person.real_name + %td= person.email + %td= person.url + %td= link_to 'Show', person + %td= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete + +%p= link_to "New Person", new_person_path + +#pagination + = will_paginate @people diff --git a/app/views/people/new.html.haml b/app/views/people/new.html.haml new file mode 100644 index 000000000..e341d8629 --- /dev/null +++ b/app/views/people/new.html.haml @@ -0,0 +1,27 @@ +- title "New Person" + += form_for @person do |f| + = f.error_messages + %p + = f.label :email + %br + = f.text_field :email + %p + = f.label :url + %br + = f.text_field :url + + =f.fields_for :profile do |p| + %p + = p.label :first_name + %br + = p.text_field :first_name + + %p + = p.label :last_name + %br + = p.text_field :last_name + = f.submit + + +%p= link_to "Back to List", people_path diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml new file mode 100644 index 000000000..ca2e88566 --- /dev/null +++ b/app/views/people/show.html.haml @@ -0,0 +1,24 @@ +.span-18.last + %h1= "#{@person.real_name}" +- if @person_profile + %p + %b First Name + %p + = @person_profile.first_name + %p + %b Last Name + %p + = @person_profile.last_name + %p + %b url + %p + = @person.url + +.span-18 + - if @person.posts + %h3 stream + %ul#stream + - for post in @person_posts + = render type_partial(post), :post => post + - else + %h3 no posts to display! diff --git a/config/routes.rb b/config/routes.rb index 08947f594..de1342247 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,10 @@ Diaspora::Application.routes.draw do |map| resources :blogs resources :bookmarks - resources :friends + resources :people resources :status_messages resources :comments - resources :friend_requests + resources :person_requests match 'warzombie', :to => "dashboard#warzombie" diff --git a/db/seeds.rb b/db/seeds.rb index 7ed50cd10..654131687 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -29,9 +29,9 @@ names = [ ["George", "Washington"], ["Abraham", "Lincoln"] ] -# Make friends +# Make people (1..10).each { |n| - Friend.create( :email => "b#{n}@joindiaspora.com", :url => "http://b#{n}.joindiaspora.com/", :profile => Profile.create(:first_name => names[n-1][0], :last_name => names[n-1][1])) + People.create( :email => "b#{n}@joindiaspora.com", :url => "http://b#{n}.joindiaspora.com/", :profile => Profile.create(:first_name => names[n-1][0], :last_name => names[n-1][1])) } # Populate feed diff --git a/db/seeds/backer.rb b/db/seeds/backer.rb index f706a0d85..56fedbaff 100644 --- a/db/seeds/backer.rb +++ b/db/seeds/backer.rb @@ -54,13 +54,13 @@ def create(backer_number, password) email = backer_info[backer_number][2].gsub(/ /,'').downcase user = User.create( :email => "#{email}@joindiaspora.com", :password => "#{email+backer_info[backer_number][0].to_s}", :profile => Profile.create( :first_name => backer_info[backer_number][1], :last_name => backer_info[backer_number][2] )) - # Make friends with Diaspora Tom - Friend.create( :email => "tom@joindiaspora.com", :url => "http://tom.joindiaspora.com/", :profile => Profile.create(:first_name => "Alexander", :last_name => "Hamiltom")) - # Make friends + # Make connection with Diaspora Tom + Person.create( :email => "tom@joindiaspora.com", :url => "http://tom.joindiaspora.com/", :profile => Profile.create(:first_name => "Alexander", :last_name => "Hamiltom")) + # Make people (0..10).each { |n| email = backer_info[n][2].gsub(/ /,'').downcase - Friend.create( :email => "#{email}@joindiaspora.com", :url => "http://#{email}.joindiaspora.com/", :profile => Profile.create(:first_name => backer_info[n][1], :last_name => backer_info[n][2])) unless n == backer_number + People.create( :email => "#{email}@joindiaspora.com", :url => "http://#{email}.joindiaspora.com/", :profile => Profile.create(:first_name => backer_info[n][1], :last_name => backer_info[n][2])) unless n == backer_number } end diff --git a/db/seeds/tom.rb b/db/seeds/tom.rb index e3bcd7bd0..dc5ad445f 100644 --- a/db/seeds/tom.rb +++ b/db/seeds/tom.rb @@ -49,10 +49,10 @@ names = [ ["George", "Washington"], ["Richard", "Nixon"] ] -# Make friends +# Make people (0..10).each { |n| email = names[n][1].gsub(/ /,'').downcase - Friend.create( :email => "#{email}@joindiaspora.com", :url => "http://#{email}.joindiaspora.com/", :profile => Profile.create(:first_name => names[n][0], :last_name => names[n][1])) + Person.create( :email => "#{email}@joindiaspora.com", :url => "http://#{email}.joindiaspora.com/", :profile => Profile.create(:first_name => names[n][0], :last_name => names[n][1])) } diff --git a/lib/common.rb b/lib/common.rb index c6fc304c7..699f5f443 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -4,7 +4,7 @@ module Diaspora def parse_owner_from_xml(xml) doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks } email = doc.xpath("//person/email").text.to_s - Friend.where(:email => email).first + Person.where(:email => email).first end def parse_body_contents_from_xml(xml) @@ -33,13 +33,13 @@ module Diaspora objects.each do |p| if p.is_a? Retraction p.perform - elsif p.is_a? Friend - if FriendRequest.where(:url => p.url).first + elsif p.is_a? Person + if PersonRequest.where(:url => p.url).first p.active = true end p.save #This line checks if the sender was in the database, among other things? - elsif p.respond_to?(:person) && !(p.person.nil?) #WTF + elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User) #WTF p.save end #p.save if p.respond_to?(:person) && !(p.person == nil) #WTF @@ -52,9 +52,9 @@ module Diaspora klass.class_eval do @@queue = MessageHandler.new - def notify_friends + def notify_people if self.person_id == User.first.id - push_to(friends_with_permissions) + push_to(people_with_permissions) end end @@ -68,12 +68,12 @@ module Diaspora end end - def push_friend_request_to_url(url) + def push_person_request_to_url(url) if url url = url + "receive/" xml = " - #{self.to_friend_xml.to_s} + #{self.to_person_xml.to_s} " @@queue.add_post_request( [url], xml ) @@ -85,8 +85,8 @@ module Diaspora "#{self.to_xml.to_s}" end - def friends_with_permissions - Friend.all + def people_with_permissions + Person.where( :_type => "Person" ).all end def self.build_xml_for(posts) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index caa98ba86..a6fe26ef6 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -22,9 +22,8 @@ namespace :db do Post.delete_all Person.delete_all User.delete_all - Friend.delete_all Profile.delete_all - FriendRequest.delete_all + PersonRequest.delete_all end desc 'Purge and seed the current RAILS_ENV database using information from db/seeds.rb' diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboard_controller_spec.rb index 499d43ba3..97656369e 100644 --- a/spec/controllers/dashboard_controller_spec.rb +++ b/spec/controllers/dashboard_controller_spec.rb @@ -13,10 +13,10 @@ describe DashboardController do response.should render_template(:index) end - it "on index sets a friends variable" do - Factory.create :friend + it "on index sets a person's variable" do + Factory.create :person get :index - assigns[:friends].should == Friend.all + assigns[:people].should == Person.all end end diff --git a/spec/factories.rb b/spec/factories.rb index 37032592f..b208bc056 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -11,6 +11,7 @@ end Factory.define :person do |p| p.email "bob@aol.com" + p.sequence(:url) {|n|"http://google-#{n}.com/"} p.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" ) end @@ -21,12 +22,6 @@ Factory.define :user do |u| u.profile Profile.new( :first_name => "Bob", :last_name => "Smith" ) end -Factory.define :friend do |f| - f.email 'max@max.com' - f.sequence(:url) {|n|"http://max#{n}.com/"} - f.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" ) -end - Factory.define :status_message do |m| m.sequence(:message) {|n| "jimmy's #{n} whales"} end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index b4c82c919..20261308f 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -5,11 +5,11 @@ include ApplicationHelper describe ApplicationHelper do before do @user = Factory.create(:user, :email => "robert@grimm.com") - @friend = Factory.create(:friend) + @person = Factory.create(:person) end it "should specifiy if a post is not owned user" do - p = Factory.create(:post, :person => @friend) + p = Factory.create(:post, :person => @person) mine?(p).should be false end @@ -18,8 +18,8 @@ describe ApplicationHelper do mine?(p).should be true end - it "should provide a correct show path for a given friend" do - person_url(@friend).should == "/friends/#{@friend.id}" + it "should provide a correct show path for a given person" do + person_url(@person).should == "/people/#{@person.id}" end it "should provide a correct show path for a given user" do diff --git a/spec/lib/common_spec.rb b/spec/lib/common_spec.rb index fbda649b2..7e2073d4d 100644 --- a/spec/lib/common_spec.rb +++ b/spec/lib/common_spec.rb @@ -8,7 +8,7 @@ describe Diaspora do describe Webhooks do before do @user = Factory.create(:user, :email => "bob@aol.com") - @friend = Factory.create(:friend) + @person = Factory.create(:person) end describe "body" do @@ -17,39 +17,40 @@ describe Diaspora do end it "should add the following methods to Post on inclusion" do - @post.respond_to?(:notify_friends).should be true + @post.respond_to?(:notify_people).should be true @post.respond_to?(:prep_webhook).should be true - @post.respond_to?(:friends_with_permissions).should be true + @post.respond_to?(:people_with_permissions).should be true end it "should convert an object to a proper webhook" do @post.prep_webhook.should == "#{@post.to_xml.to_s}" end - it "should retrieve all valid friend endpoints" do - Factory.create(:friend, :url => "http://www.bob.com/") - Factory.create(:friend, :url => "http://www.alice.com/") - Factory.create(:friend, :url => "http://www.jane.com/") + it "should retrieve all valid person endpoints" do + Factory.create(:person, :url => "http://www.bob.com/") + Factory.create(:person, :url => "http://www.alice.com/") + Factory.create(:person, :url => "http://www.jane.com/") - @post.friends_with_permissions.should == Friend.all + non_users = Person.where( :_type => "Person" ).all + @post.people_with_permissions.should == non_users end - it "should send an owners post to their friends" do + it "should send an owners post to their people" do q = Post.send(:class_variable_get, :@@queue) q.should_receive :process @post.save end - it "should check that it does not send a friends post to an owners friends" do + it "should check that it does not send a person's post to an owners people" do Post.stub(:build_xml_for).and_return(true) Post.should_not_receive(:build_xml_for) - Factory.create(:status_message, :person => Factory.create(:friend)) + Factory.create(:status_message, :person => Factory.create(:person)) end - it "should ensure one url is created for every friend" do - 5.times {Factory.create(:friend)} - @post.friends_with_permissions.size.should == 6 + it "should ensure one url is created for every person" do + 5.times {Factory.create(:person)} + @post.people_with_permissions.size.should == 6 end it "should build an xml object containing multiple Post types" do diff --git a/spec/lib/parser_spec.rb b/spec/lib/parser_spec.rb index 8bff50717..4bde168d2 100644 --- a/spec/lib/parser_spec.rb +++ b/spec/lib/parser_spec.rb @@ -5,7 +5,7 @@ include ApplicationHelper describe "parser in application helper" do before do @user = Factory.create(:user, :email => "bob@aol.com") - @friend =Factory.create(:friend, :email => "bill@gates.com") + @person = Factory.create(:person, :email => "bill@gates.com") end it "should not store posts from me" do @@ -21,7 +21,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_objects_from_xml(xml) @@ -37,7 +37,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_objects_from_xml(xml) @@ -48,11 +48,11 @@ describe "parser in application helper" do xml = " - #{Friend.first.email} + #{Person.first.email} - + " store_objects_from_xml(xml) @@ -84,23 +84,24 @@ describe "parser in application helper" do end it 'should be able to correctly handle comments' do - friend = Factory.create(:friend) + person = Factory.create(:person, :email => "test@testing.com") post = Factory.create(:status_message) - comment = Factory.build(:comment, :post => post, :person => friend, :text => "Freedom!") - xml = "#{Friend.first.email} + comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!") + xml = " #{comment.to_xml} " + objects = parse_objects_from_xml(xml) comment = objects.first comment.text.should == "Freedom!" - comment.person.should == friend + comment.person.should == person comment.post.should == post end it 'should marshal retractions' do - friend = Factory.create(:friend) - message = Factory.create(:status_message, :person => friend) + person = Factory.create(:person) + message = Factory.create(:status_message, :person => person) retraction = Retraction.for(message) request = Post.build_xml_for( [retraction] ) @@ -109,37 +110,39 @@ describe "parser in application helper" do StatusMessage.count.should == 0 end - it "should create a new friend upon getting a friend request" do - friend_request = FriendRequest.new(:url => "http://www.googles.com/") - friend_request.sender = @friend + it "should create a new person upon getting a person request" do + person_request = PersonRequest.new(:url => "http://www.googles.com/") + person_request.sender = @person xml = " - #{friend_request.to_friend_xml.to_s} + #{person_request.to_person_xml.to_s} " - @friend.destroy - Friend.count.should be 0 + @person.destroy + @user.destroy + Person.count.should be 0 store_objects_from_xml(xml) - Friend.count.should be 1 + Person.count.should be 1 end - it "should activate the Friend if I initiated a request to that url" do - friend_request = FriendRequest.create(:url => @friend.url, :sender => @user) + it "should activate the Person if I initiated a request to that url" do + person_request = PersonRequest.create(:url => @person.url, :sender => @user) - friend_request_remote = FriendRequest.new(:url => "http://www.yahoo.com/") - friend_request_remote.sender = @friend.clone + person_request_remote = PersonRequest.new(:url => "http://www.yahoo.com/") + person_request_remote.sender = @person.clone xml = " - #{friend_request_remote.to_friend_xml.to_s} + #{person_request_remote.to_person_xml.to_s} " - @friend.destroy - Friend.count.should be 0 + @person.destroy + @user.destroy + Person.count.should be 0 store_objects_from_xml(xml) - Friend.count.should be 1 - Friend.first.active.should be true + Person.count.should be 1 + Person.first.active.should be true end end diff --git a/spec/lib/socket_renderer_spec.rb b/spec/lib/socket_renderer_spec.rb index 19144d852..0b3e48505 100644 --- a/spec/lib/socket_renderer_spec.rb +++ b/spec/lib/socket_renderer_spec.rb @@ -4,7 +4,7 @@ describe SocketRenderer do before do SocketRenderer.instantiate_view @user = Factory.create(:user, :email => "bob@jones.com") - @user.profile = Factory.build(:profile, :person => @user) + @user.profile = Factory.create(:profile, :person => @user) end it 'should render a partial for a status message' do @@ -15,9 +15,8 @@ describe SocketRenderer do it 'should prepare a class/view hash' do message = Factory.create(:status_message, :person => @user) - + hash = SocketRenderer.view_hash(message) hash[:class].should == "status_messages" - end end diff --git a/spec/models/comments_spec.rb b/spec/models/comments_spec.rb index b5ebaf23c..7bb5fe372 100644 --- a/spec/models/comments_spec.rb +++ b/spec/models/comments_spec.rb @@ -13,49 +13,49 @@ describe Comment do StatusMessage.first.comments.first.text.should == "Yeah, it was great" end - it "should be able to comment on a friend's status" do - friend = Factory.create :friend - status = Factory.create(:status_message, :person => friend) + it "should be able to comment on a person's status" do + person= Factory.create :person + status = Factory.create(:status_message, :person => person) @user.comment "sup dog", :on => status StatusMessage.first.comments.first.text.should == "sup dog" StatusMessage.first.comments.first.person.should == @user end - it 'should not send out comments when we have no friends' do + + it 'should not send out comments when we have no people' do status = Factory.create(:status_message, :person => @user) Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request) @user.comment "sup dog", :on => status end + describe 'comment propagation' do before do - @friend = Factory.create(:friend) - @friend_two = Factory.create(:friend) - @friend_status = Factory.create(:status_message, :person => @friend) + @person = Factory.create(:person) + @person_two = Factory.create(:person) + @person_status = Factory.create(:status_message, :person => @person) @user_status = Factory.create(:status_message, :person => @user) end - it "should send a user's comment on a friend's post to that friend" do + it "should send a user's comment on a person's post to that person" do Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request) - @user.comment "yo", :on => @friend_status + @user.comment "yo", :on => @person_status end - it 'should send a user comment on his own post to lots of friends' do - allowed_urls = @user_status.friends_with_permissions.map!{|x| x = x.url + "receive/"} + it 'should send a user comment on his own post to lots of people' do + allowed_urls = @user_status.people_with_permissions.map!{|x| x = x.url + "receive/"} Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request).with(allowed_urls, anything ) @user.comment "yo", :on => @user_status end - it 'should send a comment a friend made on your post to all friends' do + it 'should send a comment a person made on your post to all people' do Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request) - com = Comment.create(:person => @friend, :text => "balls", :post => @user_status) + com = Comment.create(:person => @person, :text => "balls", :post => @user_status) end - it 'should not send a comment a friend made on a friend post to anyone' do + it 'should not send a comment a person made on a person post to anyone' do Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request) - com = Comment.create(:person => @friend, :text => "balls", :post => @friend_status) + com = Comment.create(:person => @person, :text => "balls", :post => @person_status) end - - end end -end \ No newline at end of file +end diff --git a/spec/models/friend_request_spec.rb b/spec/models/friend_request_spec.rb deleted file mode 100644 index 0d2e3069a..000000000 --- a/spec/models/friend_request_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'spec_helper' - -describe FriendRequest do - - it 'should require a url' do - friend_request = FriendRequest.new - friend_request.valid?.should be false - friend_request.url = "http://google.com/" - friend_request.valid?.should be true - end - - it 'should generate xml for the User as a Friend' do - friend_request = FriendRequest.new(:url => "http://www.google.com") - user = Factory.create(:user) - friend_request.sender = user - friend_xml = friend_request.to_friend_xml.to_s - friend_xml.include?(user.email).should be true - friend_xml.include?(user.url).should be true - friend_xml.include?(user.profile.first_name).should be true - friend_xml.include?(user.profile.last_name).should be true - end - - it 'should be sent to the url upon for action' do - FriendRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request) - Factory.create(:user) - FriendRequest.for("http://www.google.com") - end - - it "should activate a friend if it exists on creation of a request for that url" do - user = Factory.create(:user) - friend = Factory.create(:friend, :url => "http://google.com/") - FriendRequest.create(:url => friend.url, :sender => user) - Friend.first.active.should be true - end - -end diff --git a/spec/models/friend_spec.rb b/spec/models/friend_spec.rb deleted file mode 100644 index 5861742a1..000000000 --- a/spec/models/friend_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -require File.dirname(__FILE__) + '/../spec_helper' - -describe Friend do - - 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 - friend = Factory.build(:friend) - - #urls changed valid - friend.url = "google.com" - friend.valid?.should == true - friend.url.should == "http://google.com/" - - friend.url = "www.google.com" - friend.valid?.should == true - friend.url.should == "http://www.google.com/" - - friend.url = "google.com/" - friend.valid?.should == true - friend.url.should == "http://google.com/" - - friend.url = "www.google.com/" - friend.valid?.should == true - friend.url.should == "http://www.google.com/" - - friend.url = "http://google.com" - friend.valid?.should == true - friend.url.should == "http://google.com/" - - friend.url = "http://www.google.com" - friend.valid?.should == true - - #url with a port - friend.url = "192.168.1.1:3000" - friend.valid?.should == true - friend.url.should == "http://192.168.1.1:3000/" - - #invalid urls - #friend.url = "zsdvzxdg" - #friend.valid?.should == false - #friend.url = "sdfasfa.c" - #friend.valid?.should == false - friend.url = "http://.com/" - friend.valid?.should == false - friend.url = "http://www..com/" - friend.valid?.should == false - friend.url = "http:/www.asodij.com/" - friend.valid?.should == false - friend.url = "https:/www.asodij.com/" - friend.valid?.should == false - friend.url = "http:///www.asodij.com/" - friend.valid?.should == false - end -end diff --git a/spec/models/person_request_spec.rb b/spec/models/person_request_spec.rb new file mode 100644 index 000000000..78b45b5f3 --- /dev/null +++ b/spec/models/person_request_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe PersonRequest do + + it 'should require a url' do + person_request = PersonRequest.new + person_request.valid?.should be false + person_request.url = "http://google.com/" + person_request.valid?.should be true + end + + it 'should generate xml for the User as a Person' do + person_request = PersonRequest.new(:url => "http://www.google.com") + user = Factory.create(:user) + person_request.sender = user + person_xml = person_request.to_person_xml.to_s + person_xml.include?(user.email).should be true + person_xml.include?(user.url).should be true + person_xml.include?(user.profile.first_name).should be true + person_xml.include?(user.profile.last_name).should be true + end + + it 'should be sent to the url upon for action' do + PersonRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request) + Factory.create(:user) + PersonRequest.for("http://www.google.com") + end + + it "should activate a person if it exists on creation of a request for that url" do + user = Factory.create(:user) + person = Factory.create(:person, :url => "http://123google.com/") + PersonRequest.for(person.url) + Person.where(:url => person.url).first.active.should be true + end + +end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 74602cebb..9218313db 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -1,26 +1,27 @@ require 'spec_helper' describe Person do - it 'should not allow two friends with the same url' do - friend_one = Factory.create(:friend) - friend_two = Factory.build(:friend, :url => friend_one.url) - friend_two.valid?.should == false + it 'should not allow two people with the same url' do + person_one = Factory.create(:person) + person_two = Factory.build(:person, :url => person_one.url) + person_two.valid?.should == false end - it 'should not allow a friend with the same url as the user' do + it 'should not allow a person with the same url as the user' do user = Factory.create(:user) - friend = Factory.build(:friend, :url => user.url) - friend.valid?.should == false + person = Factory.build(:person, :url => user.url) + person.valid?.should == false end it 'should serialize to xml' do - friend_one = Factory.create(:friend) - xml = friend_one.to_xml.to_s - (xml.include? "friend").should == true + person = Factory.create(:person) + xml = person.to_xml.to_s + (xml.include? "person").should == true end + it 'should have a profile in its xml' do - user = Factory.create(:user) - xml = user.to_xml.to_s + person = Factory.create(:person) + xml = person.to_xml.to_s (xml.include? "first_name").should == true end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 091edd71f..e2e068b6d 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -19,11 +19,11 @@ describe Post do describe "newest" do before do - @friend_one = Factory.create(:friend, :email => "some@dudes.com") - @friend_two = Factory.create(:friend, :email => "other@dudes.com") - (2..4).each {|n| Blog.create(:title => "title #{n}", :body => "test #{n}", :person => @friend_one)} + @person_one = Factory.create(:person, :email => "some@dudes.com") + @person_two = Factory.create(:person, :email => "other@dudes.com") + (2..4).each {|n| Blog.create(:title => "title #{n}", :body => "test #{n}", :person => @person_one)} (5..8).each { |n| Blog.create(:title => "title #{n}",:body => "test #{n}", :person => @user)} - (9..11).each { |n| Blog.create(:title => "title #{n}",:body => "test #{n}", :person => @friend_two)} + (9..11).each { |n| Blog.create(:title => "title #{n}",:body => "test #{n}", :person => @person_two)} Factory.create(:status_message) Factory.create(:bookmark) @@ -39,7 +39,7 @@ describe Post do it "should give the most recent blog body for a given email" do blog = Blog.newest_by_email("some@dudes.com") - blog.person.email.should == @friend_one.email + blog.person.email.should == @person_one.email blog.class.should == Blog blog.title.should == "title 4" blog.body.should == "test 4" @@ -49,14 +49,14 @@ describe Post do describe "stream" do before do @owner = Factory.build(:user) - @friend_one = Factory.create(:friend, :email => "some@dudes.com") - @friend_two = Factory.create(:friend, :email => "other@dudes.com") + @person_one = Factory.create(:person, :email => "some@dudes.com") + @person_two = Factory.create(:person, :email => "other@dudes.com") Factory.create(:status_message, :message => "puppies", :created_at => Time.now+1, :person => @owner) - Factory.create(:bookmark, :title => "Reddit", :link => "http://reddit.com", :created_at => Time.now+2, :person => @friend_one) - Factory.create(:status_message, :message => "kittens", :created_at => Time.now+3, :person => @friend_two) + Factory.create(:bookmark, :title => "Reddit", :link => "http://reddit.com", :created_at => Time.now+2, :person => @person_one) + Factory.create(:status_message, :message => "kittens", :created_at => Time.now+3, :person => @person_two) Factory.create(:blog, :title => "Bears", :body => "Bear's body", :created_at => Time.now+4, :person => @owner) - Factory.create(:bookmark, :title => "Google", :link => "http://google.com", :created_at => Time.now+5, :person => @friend_two) + Factory.create(:bookmark, :title => "Google", :link => "http://google.com", :created_at => Time.now+5, :person => @person_two) end it "should list child types in reverse chronological order" do @@ -70,11 +70,11 @@ describe Post do end it "should get all posts for a specified user" do - friend_posts = @friend_one.posts - friend_posts.count.should == 1 + person_posts = @person_one.posts + person_posts.count.should == 1 - friend_posts = @friend_two.posts - friend_posts.count.should == 2 + person_posts = @person_two.posts + person_posts.count.should == 2 end end describe 'xml' do diff --git a/spec/models/retraction_spec.rb b/spec/models/retraction_spec.rb index f3fe8a212..81ea52a1a 100644 --- a/spec/models/retraction_spec.rb +++ b/spec/models/retraction_spec.rb @@ -14,7 +14,7 @@ describe Retraction do end it 'should dispatch a message on delete' do - Factory.create(:friend) + Factory.create(:person) Post.send(:class_variable_get, :@@queue).should_receive(:add_post_request) @post.destroy end