Merge branch 'master' of github.com:diaspora/diaspora_rails into socket-foo
This commit is contained in:
commit
a35892428c
43 changed files with 406 additions and 341 deletions
|
|
@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery :except => :receive
|
protect_from_forgery :except => :receive
|
||||||
layout 'application'
|
layout 'application'
|
||||||
|
|
||||||
before_filter :set_friends
|
before_filter :set_people
|
||||||
|
|
||||||
layout :layout_by_resource
|
layout :layout_by_resource
|
||||||
|
|
||||||
|
|
@ -14,8 +14,8 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_friends
|
def set_people
|
||||||
@friends = Friend.all
|
@people = Person.all
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
39
app/controllers/people_controller.rb
Normal file
39
app/controllers/people_controller.rb
Normal 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
|
||||||
37
app/controllers/person_requests_controller.rb
Normal file
37
app/controllers/person_requests_controller.rb
Normal 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
|
||||||
|
|
@ -24,10 +24,10 @@ module ApplicationHelper
|
||||||
|
|
||||||
def person_url(person)
|
def person_url(person)
|
||||||
case person.class.to_s
|
case person.class.to_s
|
||||||
when "Friend"
|
|
||||||
friend_path(person)
|
|
||||||
when "User"
|
when "User"
|
||||||
user_path(person)
|
user_path(person)
|
||||||
|
when "Person"
|
||||||
|
person_path(person)
|
||||||
else
|
else
|
||||||
"unknown person"
|
"unknown person"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class Comment
|
||||||
key :person_id, ObjectId
|
key :person_id, ObjectId
|
||||||
belongs_to :person, :class_name => "Person"
|
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
|
after_save :send_to_view
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -28,9 +28,9 @@ class Comment
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def send_friends_comments_on_my_posts
|
def send_people_comments_on_my_posts
|
||||||
if (User.first.mine?(self.post) && self.person.is_a?(Friend))
|
if User.first.mine?(self.post) && !(self.person.is_a? User)
|
||||||
self.push_to(self.post.friends_with_permissions)
|
self.push_to(self.post.people_with_permissions)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
class Friend < Person
|
|
||||||
|
|
||||||
key :active, Boolean, :default => false
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
class FriendRequest
|
|
||||||
include MongoMapper::Document
|
|
||||||
include Diaspora::Webhooks
|
|
||||||
|
|
||||||
key :url, String
|
|
||||||
|
|
||||||
attr_accessor :sender
|
|
||||||
|
|
||||||
validates_presence_of :url
|
|
||||||
|
|
||||||
before_save :shoot_off, :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 shoot_off
|
|
||||||
push_friend_request_to_url(self.url)
|
|
||||||
end
|
|
||||||
|
|
||||||
def check_for_friend_requests
|
|
||||||
f = Friend.where(:url => self.url).first
|
|
||||||
if f
|
|
||||||
f.active = true
|
|
||||||
f.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
@ -8,6 +8,7 @@ class Person
|
||||||
|
|
||||||
key :email, String
|
key :email, String
|
||||||
key :url, String
|
key :url, String
|
||||||
|
key :active, Boolean, :default => false
|
||||||
|
|
||||||
one :profile, :class_name => 'Profile', :foreign_key => :person_id
|
one :profile, :class_name => 'Profile', :foreign_key => :person_id
|
||||||
many :posts, :class_name => 'Post', :foreign_key => :person_id
|
many :posts, :class_name => 'Post', :foreign_key => :person_id
|
||||||
|
|
@ -27,7 +28,7 @@ class Person
|
||||||
before_validation :clean_url
|
before_validation :clean_url
|
||||||
|
|
||||||
def real_name
|
def real_name
|
||||||
profile.first_name.to_s + " " + profile.last_name.to_s
|
"#{profile.first_name.to_s} #{profile.last_name.to_s}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
34
app/models/person_request.rb
Normal file
34
app/models/person_request.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
class PersonRequest
|
||||||
|
include MongoMapper::Document
|
||||||
|
include Diaspora::Webhooks
|
||||||
|
include ROXML
|
||||||
|
|
||||||
|
xml_name :person_request
|
||||||
|
|
||||||
|
xml_accessor :_id
|
||||||
|
xml_accessor :person, :as => Person
|
||||||
|
|
||||||
|
key :url, String
|
||||||
|
key :person, Person
|
||||||
|
|
||||||
|
validates_presence_of :url
|
||||||
|
|
||||||
|
before_save :check_for_person_requests
|
||||||
|
|
||||||
|
def self.for(url)
|
||||||
|
request = PersonRequest.new(:url => url)
|
||||||
|
request.person = User.first
|
||||||
|
request.save
|
||||||
|
|
||||||
|
request.push_to([request])
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_for_person_requests
|
||||||
|
p = Person.where(:url => self.url).first
|
||||||
|
if p
|
||||||
|
p.active = true
|
||||||
|
p.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -20,7 +20,7 @@ class Post
|
||||||
timestamps!
|
timestamps!
|
||||||
|
|
||||||
after_save :send_to_view
|
after_save :send_to_view
|
||||||
after_save :notify_friends
|
after_save :notify_people
|
||||||
|
|
||||||
before_destroy :propagate_retraction
|
before_destroy :propagate_retraction
|
||||||
after_destroy :destroy_comments, :remove_from_view
|
after_destroy :destroy_comments, :remove_from_view
|
||||||
|
|
@ -49,7 +49,7 @@ class Post
|
||||||
end
|
end
|
||||||
|
|
||||||
def propagate_retraction
|
def propagate_retraction
|
||||||
Retraction.for(self).notify_friends
|
Retraction.for(self).notify_people
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_to_view
|
def send_to_view
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class User < Person
|
||||||
c = Comment.new(:person_id => self.id, :text => text, :post => options[:on])
|
c = Comment.new(:person_id => self.id, :text => text, :post => options[:on])
|
||||||
if c.save
|
if c.save
|
||||||
if mine?(c.post)
|
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
|
else
|
||||||
c.push_to([c.post.person])
|
c.push_to([c.post.person])
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
#content.span-24.last
|
#content.span-24.last
|
||||||
.span-3.append-1.last
|
.span-3.append-1.last
|
||||||
= link_to owner_picture, root_path
|
= link_to owner_picture, root_path
|
||||||
= render 'friends/sidebar' if user_signed_in?
|
/= render 'friends/sidebar' if user_signed_in?
|
||||||
|
|
||||||
.span-20
|
.span-20
|
||||||
- if user_signed_in?
|
- if user_signed_in?
|
||||||
|
|
|
||||||
5
app/views/people/_sidebar.html.haml
Normal file
5
app/views/people/_sidebar.html.haml
Normal 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
|
||||||
19
app/views/people/index.html.haml
Normal file
19
app/views/people/index.html.haml
Normal 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
|
||||||
27
app/views/people/new.html.haml
Normal file
27
app/views/people/new.html.haml
Normal 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
|
||||||
24
app/views/people/show.html.haml
Normal file
24
app/views/people/show.html.haml
Normal 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!
|
||||||
9
app/views/person_requests/_form.html.haml
Normal file
9
app/views/person_requests/_form.html.haml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
= form_for @person_request do |f|
|
||||||
|
= f.error_messages
|
||||||
|
|
||||||
|
%p
|
||||||
|
= f.label :url
|
||||||
|
= f.text_field :url
|
||||||
|
|
||||||
|
%p
|
||||||
|
= f.submit
|
||||||
9
app/views/person_requests/_new_person_request.haml
Normal file
9
app/views/person_requests/_new_person_request.haml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
= form_for @person_request, :remote => true do |f|
|
||||||
|
= f.error_messages
|
||||||
|
|
||||||
|
%p
|
||||||
|
= f.label :url
|
||||||
|
= f.text_field :url
|
||||||
|
|
||||||
|
%p
|
||||||
|
= f.submit
|
||||||
2
app/views/person_requests/_person_request.html.haml
Normal file
2
app/views/person_requests/_person_request.html.haml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
%li.message{:id => person_request.id}
|
||||||
|
= person_request.inspect
|
||||||
8
app/views/person_requests/edit.html.haml
Normal file
8
app/views/person_requests/edit.html.haml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
- title "Edit Person Request"
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
|
|
||||||
|
%p
|
||||||
|
= link_to "Show", person_request_path(@person_request)
|
||||||
|
|
|
||||||
|
= link_to "View All", person_request_path
|
||||||
7
app/views/person_requests/index.html.haml
Normal file
7
app/views/person_requests/index.html.haml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
%h1 person requests
|
||||||
|
= render "person_requests/new_person_request", :person_request => @person_request
|
||||||
|
%ul#stream
|
||||||
|
- for person_request in @person_requests
|
||||||
|
= render "person_request", :person_request => person_request
|
||||||
|
#pagination
|
||||||
|
= will_paginate @person_requests
|
||||||
5
app/views/person_requests/new.html.haml
Normal file
5
app/views/person_requests/new.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
- title "New Person Request"
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
|
|
||||||
|
%p= link_to "Back to List", person_requests_path
|
||||||
11
app/views/person_requests/show.html.haml
Normal file
11
app/views/person_requests/show.html.haml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
- title "Person Request"
|
||||||
|
|
||||||
|
%p
|
||||||
|
= person_request.inspect
|
||||||
|
|
||||||
|
%p
|
||||||
|
= link_to "Edit", edit_person_request_path(@person_request)
|
||||||
|
|
|
||||||
|
= link_to "Destroy", @person_request, :confirm => 'Are you sure?', :method => :delete
|
||||||
|
|
|
||||||
|
= link_to "View All", person_requests_path
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
Diaspora::Application.routes.draw do |map|
|
Diaspora::Application.routes.draw do |map|
|
||||||
resources :blogs
|
resources :blogs
|
||||||
resources :bookmarks
|
resources :bookmarks
|
||||||
resources :friends
|
resources :people
|
||||||
resources :status_messages
|
resources :status_messages
|
||||||
resources :comments
|
resources :comments
|
||||||
resources :friend_requests
|
resources :person_requests
|
||||||
|
|
||||||
match 'warzombie', :to => "dashboard#warzombie"
|
match 'warzombie', :to => "dashboard#warzombie"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ names = [ ["George", "Washington"],
|
||||||
["Abraham", "Lincoln"]
|
["Abraham", "Lincoln"]
|
||||||
]
|
]
|
||||||
|
|
||||||
# Make friends
|
# Make people
|
||||||
(1..10).each { |n|
|
(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
|
# Populate feed
|
||||||
|
|
|
||||||
|
|
@ -54,13 +54,13 @@ def create(backer_number, password)
|
||||||
email = backer_info[backer_number][2].gsub(/ /,'').downcase
|
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] ))
|
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
|
# Make connection with Diaspora Tom
|
||||||
Friend.create( :email => "tom@joindiaspora.com", :url => "http://tom.joindiaspora.com/", :profile => Profile.create(:first_name => "Alexander", :last_name => "Hamiltom"))
|
Person.create( :email => "tom@joindiaspora.com", :url => "http://tom.joindiaspora.com/", :profile => Profile.create(:first_name => "Alexander", :last_name => "Hamiltom"))
|
||||||
# Make friends
|
# Make people
|
||||||
|
|
||||||
(0..10).each { |n|
|
(0..10).each { |n|
|
||||||
email = backer_info[n][2].gsub(/ /,'').downcase
|
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
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,10 @@ names = [ ["George", "Washington"],
|
||||||
["Richard", "Nixon"]
|
["Richard", "Nixon"]
|
||||||
]
|
]
|
||||||
|
|
||||||
# Make friends
|
# Make people
|
||||||
(0..10).each { |n|
|
(0..10).each { |n|
|
||||||
email = names[n][1].gsub(/ /,'').downcase
|
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]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module Diaspora
|
||||||
def parse_owner_from_xml(xml)
|
def parse_owner_from_xml(xml)
|
||||||
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
|
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
|
||||||
email = doc.xpath("//person/email").text.to_s
|
email = doc.xpath("//person/email").text.to_s
|
||||||
Friend.where(:email => email).first
|
Person.where(:email => email).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_body_contents_from_xml(xml)
|
def parse_body_contents_from_xml(xml)
|
||||||
|
|
@ -33,13 +33,14 @@ module Diaspora
|
||||||
objects.each do |p|
|
objects.each do |p|
|
||||||
if p.is_a? Retraction
|
if p.is_a? Retraction
|
||||||
p.perform
|
p.perform
|
||||||
elsif p.is_a? Friend
|
elsif p.is_a? PersonRequest
|
||||||
if FriendRequest.where(:url => p.url).first
|
if PersonRequest.where(:url => p.url).first
|
||||||
p.active = true
|
p.active = true
|
||||||
end
|
end
|
||||||
p.save
|
p.save
|
||||||
|
p.person.save
|
||||||
#This line checks if the sender was in the database, among other things?
|
#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
|
p.save
|
||||||
end
|
end
|
||||||
#p.save if p.respond_to?(:person) && !(p.person == nil) #WTF
|
#p.save if p.respond_to?(:person) && !(p.person == nil) #WTF
|
||||||
|
|
@ -52,9 +53,9 @@ module Diaspora
|
||||||
klass.class_eval do
|
klass.class_eval do
|
||||||
@@queue = MessageHandler.new
|
@@queue = MessageHandler.new
|
||||||
|
|
||||||
def notify_friends
|
def notify_people
|
||||||
if self.person_id == User.first.id
|
if self.person_id == User.first.id
|
||||||
push_to(friends_with_permissions)
|
push_to(people_with_permissions)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -68,25 +69,12 @@ module Diaspora
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def push_friend_request_to_url(url)
|
|
||||||
if url
|
|
||||||
url = url + "receive/"
|
|
||||||
xml = "<XML>
|
|
||||||
<posts><post>
|
|
||||||
#{self.to_friend_xml.to_s}
|
|
||||||
</post></posts>
|
|
||||||
</XML>"
|
|
||||||
@@queue.add_post_request( [url], xml )
|
|
||||||
@@queue.process
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def prep_webhook
|
def prep_webhook
|
||||||
"<post>#{self.to_xml.to_s}</post>"
|
"<post>#{self.to_xml.to_s}</post>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def friends_with_permissions
|
def people_with_permissions
|
||||||
Friend.all
|
Person.where( :_type => "Person" ).all
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.build_xml_for(posts)
|
def self.build_xml_for(posts)
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,8 @@ namespace :db do
|
||||||
Post.delete_all
|
Post.delete_all
|
||||||
Person.delete_all
|
Person.delete_all
|
||||||
User.delete_all
|
User.delete_all
|
||||||
Friend.delete_all
|
|
||||||
Profile.delete_all
|
Profile.delete_all
|
||||||
FriendRequest.delete_all
|
PersonRequest.delete_all
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Purge and seed the current RAILS_ENV database using information from db/seeds.rb'
|
desc 'Purge and seed the current RAILS_ENV database using information from db/seeds.rb'
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ describe DashboardController do
|
||||||
response.should render_template(:index)
|
response.should render_template(:index)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "on index sets a friends variable" do
|
it "on index sets a person's variable" do
|
||||||
Factory.create :friend
|
Factory.create :person
|
||||||
get :index
|
get :index
|
||||||
assigns[:friends].should == Friend.all
|
assigns[:people].should == Person.all
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ end
|
||||||
|
|
||||||
Factory.define :person do |p|
|
Factory.define :person do |p|
|
||||||
p.email "bob@aol.com"
|
p.email "bob@aol.com"
|
||||||
|
p.sequence(:url) {|n|"http://google-#{n}.com/"}
|
||||||
p.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" )
|
p.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -22,12 +23,6 @@ Factory.define :user do |u|
|
||||||
u.profile Profile.new( :first_name => "Bob", :last_name => "Smith" )
|
u.profile Profile.new( :first_name => "Bob", :last_name => "Smith" )
|
||||||
end
|
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|
|
Factory.define :status_message do |m|
|
||||||
m.sequence(:message) {|n| "jimmy's #{n} whales"}
|
m.sequence(:message) {|n| "jimmy's #{n} whales"}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ include ApplicationHelper
|
||||||
describe ApplicationHelper do
|
describe ApplicationHelper do
|
||||||
before do
|
before do
|
||||||
@user = Factory.create(:user, :email => "robert@grimm.com")
|
@user = Factory.create(:user, :email => "robert@grimm.com")
|
||||||
@friend = Factory.create(:friend)
|
@person = Factory.create(:person)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should specifiy if a post is not owned user" do
|
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
|
mine?(p).should be false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -18,8 +18,8 @@ describe ApplicationHelper do
|
||||||
mine?(p).should be true
|
mine?(p).should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should provide a correct show path for a given friend" do
|
it "should provide a correct show path for a given person" do
|
||||||
person_url(@friend).should == "/friends/#{@friend.id}"
|
person_url(@person).should == "/people/#{@person.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should provide a correct show path for a given user" do
|
it "should provide a correct show path for a given user" do
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ describe Diaspora do
|
||||||
describe Webhooks do
|
describe Webhooks do
|
||||||
before do
|
before do
|
||||||
@user = Factory.create(:user, :email => "bob@aol.com")
|
@user = Factory.create(:user, :email => "bob@aol.com")
|
||||||
@friend = Factory.create(:friend)
|
@person = Factory.create(:person)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "body" do
|
describe "body" do
|
||||||
|
|
@ -17,39 +17,40 @@ describe Diaspora do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should add the following methods to Post on inclusion" do
|
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?(:prep_webhook).should be true
|
||||||
@post.respond_to?(:friends_with_permissions).should be true
|
@post.respond_to?(:people_with_permissions).should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should convert an object to a proper webhook" do
|
it "should convert an object to a proper webhook" do
|
||||||
@post.prep_webhook.should == "<post>#{@post.to_xml.to_s}</post>"
|
@post.prep_webhook.should == "<post>#{@post.to_xml.to_s}</post>"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should retrieve all valid friend endpoints" do
|
it "should retrieve all valid person endpoints" do
|
||||||
Factory.create(:friend, :url => "http://www.bob.com/")
|
Factory.create(:person, :url => "http://www.bob.com/")
|
||||||
Factory.create(:friend, :url => "http://www.alice.com/")
|
Factory.create(:person, :url => "http://www.alice.com/")
|
||||||
Factory.create(:friend, :url => "http://www.jane.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
|
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 = Post.send(:class_variable_get, :@@queue)
|
||||||
q.should_receive :process
|
q.should_receive :process
|
||||||
@post.save
|
@post.save
|
||||||
end
|
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.stub(:build_xml_for).and_return(true)
|
||||||
Post.should_not_receive(:build_xml_for)
|
Post.should_not_receive(:build_xml_for)
|
||||||
|
|
||||||
Factory.create(:status_message, :person => Factory.create(:friend))
|
Factory.create(:status_message, :person => Factory.create(:person))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should ensure one url is created for every friend" do
|
it "should ensure one url is created for every person" do
|
||||||
5.times {Factory.create(:friend)}
|
5.times {Factory.create(:person)}
|
||||||
@post.friends_with_permissions.size.should == 6
|
@post.people_with_permissions.size.should == 6
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should build an xml object containing multiple Post types" do
|
it "should build an xml object containing multiple Post types" do
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ include ApplicationHelper
|
||||||
describe "parser in application helper" do
|
describe "parser in application helper" do
|
||||||
before do
|
before do
|
||||||
@user = Factory.create(:user, :email => "bob@aol.com")
|
@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
|
end
|
||||||
|
|
||||||
it "should not store posts from me" do
|
it "should not store posts from me" do
|
||||||
|
|
@ -21,7 +21,7 @@ describe "parser in application helper" do
|
||||||
<head>
|
<head>
|
||||||
</head><posts>
|
</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><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>
|
<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>"
|
</posts></XML>"
|
||||||
store_objects_from_xml(xml)
|
store_objects_from_xml(xml)
|
||||||
|
|
@ -37,7 +37,7 @@ describe "parser in application helper" do
|
||||||
</sender>
|
</sender>
|
||||||
</head><posts>
|
</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><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>
|
<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>"
|
</posts></XML>"
|
||||||
store_objects_from_xml(xml)
|
store_objects_from_xml(xml)
|
||||||
|
|
@ -48,11 +48,11 @@ describe "parser in application helper" do
|
||||||
xml = "<XML>
|
xml = "<XML>
|
||||||
<head>
|
<head>
|
||||||
<sender>
|
<sender>
|
||||||
<email>#{Friend.first.email}</email>
|
<email>#{Person.first.email}</email>
|
||||||
</sender>
|
</sender>
|
||||||
</head>
|
</head>
|
||||||
<posts>
|
<posts>
|
||||||
<post><friend></friend></post>
|
<post><person></person></post>
|
||||||
</posts></XML>"
|
</posts></XML>"
|
||||||
|
|
||||||
store_objects_from_xml(xml)
|
store_objects_from_xml(xml)
|
||||||
|
|
@ -84,23 +84,24 @@ describe "parser in application helper" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to correctly handle comments' do
|
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)
|
post = Factory.create(:status_message)
|
||||||
comment = Factory.build(:comment, :post => post, :person => friend, :text => "Freedom!")
|
comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!")
|
||||||
xml = "<XML><head><sender><email>#{Friend.first.email}</email></sender></head>
|
xml = "<XML>
|
||||||
<posts>
|
<posts>
|
||||||
<post>#{comment.to_xml}</post>
|
<post>#{comment.to_xml}</post>
|
||||||
</posts></XML>"
|
</posts></XML>"
|
||||||
|
|
||||||
objects = parse_objects_from_xml(xml)
|
objects = parse_objects_from_xml(xml)
|
||||||
comment = objects.first
|
comment = objects.first
|
||||||
comment.text.should == "Freedom!"
|
comment.text.should == "Freedom!"
|
||||||
comment.person.should == friend
|
comment.person.should == person
|
||||||
comment.post.should == post
|
comment.post.should == post
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should marshal retractions' do
|
it 'should marshal retractions' do
|
||||||
friend = Factory.create(:friend)
|
person = Factory.create(:person)
|
||||||
message = Factory.create(:status_message, :person => friend)
|
message = Factory.create(:status_message, :person => person)
|
||||||
retraction = Retraction.for(message)
|
retraction = Retraction.for(message)
|
||||||
request = Post.build_xml_for( [retraction] )
|
request = Post.build_xml_for( [retraction] )
|
||||||
|
|
||||||
|
|
@ -109,37 +110,27 @@ describe "parser in application helper" do
|
||||||
StatusMessage.count.should == 0
|
StatusMessage.count.should == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should create a new friend upon getting a friend request" do
|
it "should create a new person upon getting a person request" do
|
||||||
friend_request = FriendRequest.new(:url => "http://www.googles.com/")
|
request = PersonRequest.new(:url => "http://www.googles.com/")
|
||||||
friend_request.sender = @friend
|
request.person = @person
|
||||||
xml = "<XML>
|
|
||||||
<posts><post>
|
|
||||||
#{friend_request.to_friend_xml.to_s}
|
|
||||||
</post></posts>
|
|
||||||
</XML>"
|
|
||||||
|
|
||||||
@friend.destroy
|
xml = Post.build_xml_for [request]
|
||||||
Friend.count.should be 0
|
|
||||||
|
@person.destroy
|
||||||
|
@user.destroy
|
||||||
|
Person.count.should be 0
|
||||||
store_objects_from_xml(xml)
|
store_objects_from_xml(xml)
|
||||||
Friend.count.should be 1
|
Person.count.should be 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should activate the Friend if I initiated a request to that url" do
|
it "should activate the Person if I initiated a request to that url" do
|
||||||
friend_request = FriendRequest.create(:url => @friend.url, :sender => @user)
|
request = PersonRequest.create(:url => @person.url, :person => @user)
|
||||||
|
request_remote = PersonRequest.new(:url => "http://www.yahoo.com/")
|
||||||
friend_request_remote = FriendRequest.new(:url => "http://www.yahoo.com/")
|
request_remote.person = @person.clone
|
||||||
friend_request_remote.sender = @friend.clone
|
|
||||||
xml = "<XML>
|
|
||||||
<posts><post>
|
|
||||||
#{friend_request_remote.to_friend_xml.to_s}
|
|
||||||
</post></posts>
|
|
||||||
</XML>"
|
|
||||||
|
|
||||||
@friend.destroy
|
xml = Post.build_xml_for [request_remote]
|
||||||
Friend.count.should be 0
|
|
||||||
store_objects_from_xml(xml)
|
Person.where(:url => @person.url).first.active.should be true
|
||||||
Friend.count.should be 1
|
|
||||||
Friend.first.active.should be true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ describe SocketRenderer do
|
||||||
before do
|
before do
|
||||||
SocketRenderer.instantiate_view
|
SocketRenderer.instantiate_view
|
||||||
@user = Factory.create(:user, :email => "bob@jones.com")
|
@user = Factory.create(:user, :email => "bob@jones.com")
|
||||||
@user.profile = Factory.build(:profile, :person => @user)
|
@user.profile = Factory.create(:profile, :person => @user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should render a partial for a status message' do
|
it 'should render a partial for a status message' do
|
||||||
|
|
@ -16,10 +16,9 @@ describe SocketRenderer do
|
||||||
|
|
||||||
it 'should prepare a class/view hash' do
|
it 'should prepare a class/view hash' do
|
||||||
message = Factory.create(:status_message, :person => @user)
|
message = Factory.create(:status_message, :person => @user)
|
||||||
|
|
||||||
hash = SocketRenderer.view_hash(message)
|
hash = SocketRenderer.view_hash(message)
|
||||||
hash[:class].should == "status_messages"
|
hash[:class].should == "status_messages"
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
=end
|
=end
|
||||||
|
|
|
||||||
|
|
@ -13,49 +13,49 @@ describe Comment do
|
||||||
StatusMessage.first.comments.first.text.should == "Yeah, it was great"
|
StatusMessage.first.comments.first.text.should == "Yeah, it was great"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to comment on a friend's status" do
|
it "should be able to comment on a person's status" do
|
||||||
friend = Factory.create :friend
|
person= Factory.create :person
|
||||||
status = Factory.create(:status_message, :person => friend)
|
status = Factory.create(:status_message, :person => person)
|
||||||
@user.comment "sup dog", :on => status
|
@user.comment "sup dog", :on => status
|
||||||
|
|
||||||
StatusMessage.first.comments.first.text.should == "sup dog"
|
StatusMessage.first.comments.first.text.should == "sup dog"
|
||||||
StatusMessage.first.comments.first.person.should == @user
|
StatusMessage.first.comments.first.person.should == @user
|
||||||
end
|
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)
|
status = Factory.create(:status_message, :person => @user)
|
||||||
Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request)
|
Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request)
|
||||||
@user.comment "sup dog", :on => status
|
@user.comment "sup dog", :on => status
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'comment propagation' do
|
describe 'comment propagation' do
|
||||||
before do
|
before do
|
||||||
@friend = Factory.create(:friend)
|
@person = Factory.create(:person)
|
||||||
@friend_two = Factory.create(:friend)
|
@person_two = Factory.create(:person)
|
||||||
@friend_status = Factory.create(:status_message, :person => @friend)
|
@person_status = Factory.create(:status_message, :person => @person)
|
||||||
@user_status = Factory.create(:status_message, :person => @user)
|
@user_status = Factory.create(:status_message, :person => @user)
|
||||||
end
|
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)
|
Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
||||||
@user.comment "yo", :on => @friend_status
|
@user.comment "yo", :on => @person_status
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send a user comment on his own post to lots of friends' do
|
it 'should send a user comment on his own post to lots of people' do
|
||||||
allowed_urls = @user_status.friends_with_permissions.map!{|x| x = x.url + "receive/"}
|
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 )
|
Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request).with(allowed_urls, anything )
|
||||||
@user.comment "yo", :on => @user_status
|
@user.comment "yo", :on => @user_status
|
||||||
end
|
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)
|
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
|
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)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,38 +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 save' do
|
|
||||||
FriendRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
|
||||||
|
|
||||||
friend_request = FriendRequest.new(:url => "http://www.google.com")
|
|
||||||
friend_request.sender = Factory.create(:user)
|
|
||||||
friend_request.save
|
|
||||||
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
|
|
||||||
|
|
@ -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
|
|
||||||
36
spec/models/person_request_spec.rb
Normal file
36
spec/models/person_request_spec.rb
Normal 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
|
||||||
|
user = Factory.create(:user)
|
||||||
|
request = PersonRequest.new(:url => "http://www.google.com/", :person => user)
|
||||||
|
|
||||||
|
xml = request.to_xml.to_s
|
||||||
|
xml.include?(user.email).should be true
|
||||||
|
xml.include?(user.url).should be true
|
||||||
|
xml.include?(user.profile.first_name).should be true
|
||||||
|
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
|
||||||
|
|
@ -1,26 +1,27 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Person do
|
describe Person do
|
||||||
it 'should not allow two friends with the same url' do
|
it 'should not allow two people with the same url' do
|
||||||
friend_one = Factory.create(:friend)
|
person_one = Factory.create(:person)
|
||||||
friend_two = Factory.build(:friend, :url => friend_one.url)
|
person_two = Factory.build(:person, :url => person_one.url)
|
||||||
friend_two.valid?.should == false
|
person_two.valid?.should == false
|
||||||
end
|
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)
|
user = Factory.create(:user)
|
||||||
friend = Factory.build(:friend, :url => user.url)
|
person = Factory.build(:person, :url => user.url)
|
||||||
friend.valid?.should == false
|
person.valid?.should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should serialize to xml' do
|
it 'should serialize to xml' do
|
||||||
friend_one = Factory.create(:friend)
|
person = Factory.create(:person)
|
||||||
xml = friend_one.to_xml.to_s
|
xml = person.to_xml.to_s
|
||||||
(xml.include? "friend").should == true
|
(xml.include? "person").should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have a profile in its xml' do
|
it 'should have a profile in its xml' do
|
||||||
user = Factory.create(:user)
|
person = Factory.create(:person)
|
||||||
xml = user.to_xml.to_s
|
xml = person.to_xml.to_s
|
||||||
(xml.include? "first_name").should == true
|
(xml.include? "first_name").should == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,11 @@ describe Post do
|
||||||
|
|
||||||
describe "newest" do
|
describe "newest" do
|
||||||
before do
|
before do
|
||||||
@friend_one = Factory.create(:friend, :email => "some@dudes.com")
|
@person_one = Factory.create(:person, :email => "some@dudes.com")
|
||||||
@friend_two = Factory.create(:friend, :email => "other@dudes.com")
|
@person_two = Factory.create(:person, :email => "other@dudes.com")
|
||||||
(2..4).each {|n| Blog.create(:title => "title #{n}", :body => "test #{n}", :person => @friend_one)}
|
(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)}
|
(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(:status_message)
|
||||||
Factory.create(:bookmark)
|
Factory.create(:bookmark)
|
||||||
|
|
@ -39,7 +39,7 @@ describe Post do
|
||||||
|
|
||||||
it "should give the most recent blog body for a given email" do
|
it "should give the most recent blog body for a given email" do
|
||||||
blog = Blog.newest_by_email("some@dudes.com")
|
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.class.should == Blog
|
||||||
blog.title.should == "title 4"
|
blog.title.should == "title 4"
|
||||||
blog.body.should == "test 4"
|
blog.body.should == "test 4"
|
||||||
|
|
@ -49,14 +49,14 @@ describe Post do
|
||||||
describe "stream" do
|
describe "stream" do
|
||||||
before do
|
before do
|
||||||
@owner = Factory.build(:user)
|
@owner = Factory.build(:user)
|
||||||
@friend_one = Factory.create(:friend, :email => "some@dudes.com")
|
@person_one = Factory.create(:person, :email => "some@dudes.com")
|
||||||
@friend_two = Factory.create(:friend, :email => "other@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(: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(: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 => @friend_two)
|
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(: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
|
end
|
||||||
|
|
||||||
it "should list child types in reverse chronological order" do
|
it "should list child types in reverse chronological order" do
|
||||||
|
|
@ -70,11 +70,11 @@ describe Post do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should get all posts for a specified user" do
|
it "should get all posts for a specified user" do
|
||||||
friend_posts = @friend_one.posts
|
person_posts = @person_one.posts
|
||||||
friend_posts.count.should == 1
|
person_posts.count.should == 1
|
||||||
|
|
||||||
friend_posts = @friend_two.posts
|
person_posts = @person_two.posts
|
||||||
friend_posts.count.should == 2
|
person_posts.count.should == 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
describe 'xml' do
|
describe 'xml' do
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ describe Retraction do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should dispatch a message on delete' do
|
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.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
||||||
@post.destroy
|
@post.destroy
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue