RS, IZ; Comment spec now passes

This commit is contained in:
Raphael 2010-08-05 19:01:45 -07:00
parent 5d924dadf4
commit b5cbfab36e
6 changed files with 40 additions and 98 deletions

View file

@ -18,7 +18,6 @@ class Comment
key :person_id, ObjectId
belongs_to :person, :class_name => "Person"
after_save :send_people_comments_on_my_posts
after_save :send_to_view
@ -26,6 +25,16 @@ class Comment
(self.message == other.message) && (self.person.email == other.person.email)
end
def push_upstream
puts "Comment going upstream"
push_to([post.person])
end
def push_downstream
puts "Comment going downstream"
push_to(post.people_with_permissions)
end
#ENCRYPTION
before_validation :sign_if_mine, :sign_if_my_post
@ -69,13 +78,6 @@ class Comment
end
end
def send_people_comments_on_my_posts
if User.owner.mine?(self.post) && !(self.person.is_a? User)
self.push_to(self.post.people_with_permissions)
end
end
def send_to_view
SocketsController.new.outgoing(self)
end

View file

@ -58,6 +58,9 @@ class Person
options[:person] = self
model_class = class_name.to_s.camelize.constantize
post = model_class.instantiate(options)
if owns?(post)
post.notify_people
end
end
######## Commenting ########
@ -65,16 +68,27 @@ class Person
raise "must comment on something!" unless options[:on]
c = Comment.new(:person_id => self.id, :text => text, :post => options[:on])
if c.save
if mine?(c.post)
c.push_to(c.post.people_with_permissions) # should return plucky query
if self.owner.nil?
if c.post.person.owner.nil?
#puts "The commenter is not here, and neither is the poster"
elsif c.post.person.owner
#puts "The commenter is not here, and the poster is"
c.push_downstream
end
else
c.push_to([c.post.person])
if owns? c.post
#puts "The commenter is here, and is the poster"
c.push_downstream
else
#puts "The commenter is here, and is not the poster"
c.push_upstream
end
end
true
end
false
end
##profile
def update_profile(params)
if self.update_attributes(params)
@ -86,7 +100,7 @@ class Person
end
end
def mine?(post)
def owns?(post)
self.id == post.person.id
end

View file

@ -21,7 +21,6 @@ class Post
timestamps!
after_save :send_to_view
after_save :notify_people
before_destroy :propagate_retraction
after_destroy :destroy_comments, :remove_from_view

View file

@ -13,9 +13,8 @@ class MessageHandler
end
def add_post_request(destinations, body)
puts "sending to: #{destinations.inspect}"
b = CGI::escape( body )
puts body
puts destinations.inspect
[*destinations].each{|dest| @queue.push(Message.new(:post, dest, :body => b))}
end

View file

@ -34,7 +34,7 @@ describe Comment do
@person = Factory.create(:person)
@user.friends << Factory.create(:person)
@user.save
@person2 = Factory.create(:person)
@person_status = Factory.build(:status_message, :person => @person)
@user_status = Factory.build(:status_message, :person => @user.person)
end
@ -46,19 +46,24 @@ describe Comment do
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)
puts allowed_urls
queue = Comment.send(:class_variable_get, :@@queue)
queue.should_receive(:add_post_request).with(allowed_urls, anything)
@user.comment "yo", :on => @user_status
end
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.create(:person => @person, :text => "balls", :post => @user_status)
@person.comment "balls", :on => @user_status
end
it 'should not send a comment a person made on his own post to anyone' do
Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request)
@person.comment "balls", :on => @person_status
end
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.create(:person => @person, :text => "balls", :post => @person_status)
@person2.comment "balls", :on => @person_status
end
end
end

View file

@ -1,77 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://tom.joindiaspora.com/" />
<title>post_and_delete_status_message_not_testing_websocket</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">post_and_delete_status_message_not_testing_websocket</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/login</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>user_password</td>
<td>evankorth</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>user_submit</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>status_message_message</td>
<td>THIS IS A RUNNING SELENIUM TEST AAAAAAAAH</td>
</tr>
<tr>
<td>click</td>
<td>status_message_submit</td>
<td></td>
</tr>
<tr>
<td>refreshAndWait</td>
<td></td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>THIS IS A RUNNING SELENIUM TEST AAAAAAAAH</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Delete</td>
<td></td>
</tr>
<tr>
<td>assertConfirmation</td>
<td>Are you sure?</td>
<td></td>
</tr>
<tr>
<td>refreshAndWait</td>
<td></td>
<td></td>
</tr>
<tr>
<td>verifyTextNotPresent</td>
<td>THIS IS A RUNNING SELENIUM TEST AAAAAAAAH</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=logout</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>