DG IZ; removed Friend model, now Person is used instead. Also, broke the websocket.

This commit is contained in:
danielvincent 2010-07-07 16:53:52 -07:00
parent d705d39f70
commit 3d105e7c1e
36 changed files with 363 additions and 323 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +0,0 @@
class Friend < Person
key :active, Boolean, :default => false
end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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 = "<XML>
<posts><post>
#{self.to_friend_xml.to_s}
#{self.to_person_xml.to_s}
</post></posts>
</XML>"
@@queue.add_post_request( [url], xml )
@ -85,8 +85,8 @@ module Diaspora
"<post>#{self.to_xml.to_s}</post>"
end
def friends_with_permissions
Friend.all
def people_with_permissions
Person.where( :_type => "Person" ).all
end
def self.build_xml_for(posts)

View file

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

View file

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

View file

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

View file

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

View file

@ -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>#{@post.to_xml.to_s}</post>"
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

View file

@ -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
<head>
</head><posts>
<post><status_message>\n <message>Here is another message</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post>
<post><friend></friend></post>
<post><person></person></post>
<post><status_message>\n <message>HEY DUDE</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post>
</posts></XML>"
store_objects_from_xml(xml)
@ -37,7 +37,7 @@ describe "parser in application helper" do
</sender>
</head><posts>
<post><status_message>\n <message>Here is another message</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post>
<post><friend></friend></post>
<post><person></person></post>
<post><status_message>\n <message>HEY DUDE</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post>
</posts></XML>"
store_objects_from_xml(xml)
@ -48,11 +48,11 @@ describe "parser in application helper" do
xml = "<XML>
<head>
<sender>
<email>#{Friend.first.email}</email>
<email>#{Person.first.email}</email>
</sender>
</head>
<posts>
<post><friend></friend></post>
<post><person></person></post>
</posts></XML>"
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 = "<XML><head><sender><email>#{Friend.first.email}</email></sender></head>
comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!")
xml = "<XML>
<posts>
<post>#{comment.to_xml}</post>
</posts></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 = "<XML>
<posts><post>
#{friend_request.to_friend_xml.to_s}
#{person_request.to_person_xml.to_s}
</post></posts>
</XML>"
@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 = "<XML>
<posts><post>
#{friend_request_remote.to_friend_xml.to_s}
#{person_request_remote.to_person_xml.to_s}
</post></posts>
</XML>"
@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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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