diff --git a/app/models/comment.rb b/app/models/comment.rb index 1808952a8..40e31e257 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/person.rb b/app/models/person.rb index 1dbf8eee7..612f12a84 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/app/models/post.rb b/app/models/post.rb index fc4fea28c..74fce8881 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/lib/message_handler.rb b/lib/message_handler.rb index db987f418..17f11368c 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -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 diff --git a/spec/models/comments_spec.rb b/spec/models/comments_spec.rb index 358b46514..3f0d03659 100644 --- a/spec/models/comments_spec.rb +++ b/spec/models/comments_spec.rb @@ -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 diff --git a/test/selenium/post_and_delete_status_message_not_testing_websocket b/test/selenium/post_and_delete_status_message_not_testing_websocket deleted file mode 100644 index bb1cbf7da..000000000 --- a/test/selenium/post_and_delete_status_message_not_testing_websocket +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - -post_and_delete_status_message_not_testing_websocket - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
post_and_delete_status_message_not_testing_websocket
open/login
typeuser_passwordevankorth
clickAndWaituser_submit
typestatus_message_messageTHIS IS A RUNNING SELENIUM TEST AAAAAAAAH
clickstatus_message_submit
refreshAndWait
verifyTextPresentTHIS IS A RUNNING SELENIUM TEST AAAAAAAAH
clicklink=Delete
assertConfirmationAre you sure?
refreshAndWait
verifyTextNotPresentTHIS IS A RUNNING SELENIUM TEST AAAAAAAAH
clickAndWaitlink=logout
- -