From 5d924dadf415834f6f02fd2fac20fb654d9a09d3 Mon Sep 17 00:00:00 2001 From: maxwell Date: Thu, 5 Aug 2010 17:16:51 -0700 Subject: [PATCH] MS DG; 19 failing specs left --- app/controllers/application_controller.rb | 5 ++--- app/helpers/application_helper.rb | 2 +- app/models/person.rb | 2 +- app/models/post.rb | 11 +--------- app/models/retraction.rb | 4 ++++ lib/diaspora/webhooks.rb | 2 +- lib/message_handler.rb | 2 ++ .../controllers/dashboards_controller_spec.rb | 2 +- spec/controllers/publics_controller_spec.rb | 2 +- spec/helpers/application_helper_spec.rb | 9 +++++++- spec/lib/diaspora_parser_spec.rb | 10 ++++----- spec/models/blogs_spec.rb | 2 +- spec/models/bookmark_spec.rb | 4 ++-- spec/models/comments_spec.rb | 21 +++++++++++-------- spec/models/post_spec.rb | 19 ++++++----------- spec/models/status_message_spec.rb | 2 +- 16 files changed, 48 insertions(+), 51 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c525ad1cd..bb091706b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -16,9 +16,8 @@ class ApplicationController < ActionController::Base end def set_friends_and_status - @friends = Person.friends.all if current_user - @latest_status_message = StatusMessage.newest(current_user) if current_user - + @friends = current_user.friends if current_user + @latest_status_message = StatusMessage.newest_for(current_user) if current_user end def count_requests diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2e2895fbb..0c4c0b61e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -8,7 +8,7 @@ module ApplicationHelper end def mine?(post) - post.person == User.owner + post.person.id == current_user.person.id end def type_partial(post) diff --git a/app/models/person.rb b/app/models/person.rb index c87148b70..1dbf8eee7 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -87,7 +87,7 @@ class Person end def mine?(post) - self == post.person + self.id == post.person.id end diff --git a/app/models/post.rb b/app/models/post.rb index 1b4149fdc..fc4fea28c 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -35,19 +35,10 @@ class Post Post.sort(:created_at.desc).all end - def self.newest(person = nil) - return self.last if person.nil? - + def self.newest_for(person) self.first(:person_id => person.id, :order => '_id desc') end - def self.my_newest - self.newest(User.owner) - end - def self.newest_by_email(email) - self.newest(Person.first(:email => email)) - end - #ENCRYPTION before_validation :sign_if_mine validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature} diff --git a/app/models/retraction.rb b/app/models/retraction.rb index 9a07de141..05a207a8a 100644 --- a/app/models/retraction.rb +++ b/app/models/retraction.rb @@ -44,6 +44,10 @@ class Retraction object.person.id end end + + def person + Person.first(:id => self.person_id) + end #ENCRYPTION xml_reader :creator_signature diff --git a/lib/diaspora/webhooks.rb b/lib/diaspora/webhooks.rb index d301c999b..972a98cb2 100644 --- a/lib/diaspora/webhooks.rb +++ b/lib/diaspora/webhooks.rb @@ -39,7 +39,7 @@ module Diaspora end def people_with_permissions - self.person.owner.friends + self.person.owner.friends.all end def self.build_xml_for(posts) diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 4bc54b4c9..db987f418 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -14,6 +14,8 @@ class MessageHandler def add_post_request(destinations, body) 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/controllers/dashboards_controller_spec.rb b/spec/controllers/dashboards_controller_spec.rb index 8652223c5..a485d275a 100644 --- a/spec/controllers/dashboards_controller_spec.rb +++ b/spec/controllers/dashboards_controller_spec.rb @@ -12,7 +12,7 @@ describe DashboardsController do sign_in :user, @user Factory.create :person get :index - assigns[:friends].should == Person.friends.all + assigns[:friends].should == @user.friends end end diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index d473ae936..5b84098a4 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -4,7 +4,7 @@ describe PublicsController do render_views before do - @user = Factory.create(:user, :profile => Profile.new( :first_name => "bob", :last_name => "smith")) + @user = Factory.create(:user) @user.person.save request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user) end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index f47856265..28cb8d09a 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -6,6 +6,9 @@ describe ApplicationHelper do before do @user = Factory.create(:user) @person = Factory.create(:person) + request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user) + sign_in @user + @user.save end it "should specifiy if a post is not owned user" do @@ -14,7 +17,11 @@ describe ApplicationHelper do end it "should specifiy if a post is owned current user" do - p = Factory.create(:post, :person => @user) + ApplicatonHelper.any_instance.stub!(:current_user).and_return(@user) + p = Factory.create(:post, :person => @user.person) + + puts p.person.id == @user.person.id + mine?(p).should be true end diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index 10f02f6ef..4b9ecbcb6 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -86,7 +86,7 @@ describe Diaspora::Parser do it 'should be able to correctly handle comments' do person = Factory.create(:person, :email => "test@testing.com") - post = Factory.create(:status_message) + post = Factory.create(:status_message, :person => @user.person) comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!") xml = " @@ -166,12 +166,12 @@ describe Diaspora::Parser do #Build xml for profile, clear profile xml = Post.build_xml_for(person.profile) - reloaded_person = Person.first(:id => id) + reloaded_person = Person.first(:id => id) reloaded_person.profile = nil - reloaded_person.save + reloaded_person.profile.save #Make sure profile is cleared - Person.first(:id=> id).profile.should be nil + Person.first(:id => id).profile.should be nil old_profile.first_name.should == 'bob' #Marshal profile @@ -183,8 +183,6 @@ describe Diaspora::Parser do person.profile.first_name.should == old_profile.first_name person.profile.last_name.should == old_profile.last_name person.profile.image_url.should == old_profile.image_url - - end end end diff --git a/spec/models/blogs_spec.rb b/spec/models/blogs_spec.rb index 270339a85..9be9db74b 100644 --- a/spec/models/blogs_spec.rb +++ b/spec/models/blogs_spec.rb @@ -18,7 +18,7 @@ describe Blog do describe "XML" do it 'should serialize to XML' do - body = Factory.create(:blog, :title => "yessir", :body => "penguins") + body = Factory.create(:blog, :title => "yessir", :body => "penguins", :person => @user.person) body.to_xml.to_s.should include "yessir" body.to_xml.to_s.should include "penguins" end diff --git a/spec/models/bookmark_spec.rb b/spec/models/bookmark_spec.rb index 879408430..f583e0844 100644 --- a/spec/models/bookmark_spec.rb +++ b/spec/models/bookmark_spec.rb @@ -57,8 +57,8 @@ describe Bookmark do describe "XML" do it 'should serialize to XML' do - Factory.create(:user) - message = Factory.create(:bookmark, :title => "Reddit", :link => "http://reddit.com/") + u = Factory.create(:user) + message = Factory.create(:bookmark, :title => "Reddit", :link => "http://reddit.com/", :person => u.person) message.to_xml.to_s.should include "Reddit" message.to_xml.to_s.should include "http://reddit.com/" end diff --git a/spec/models/comments_spec.rb b/spec/models/comments_spec.rb index d40a35b35..358b46514 100644 --- a/spec/models/comments_spec.rb +++ b/spec/models/comments_spec.rb @@ -17,7 +17,7 @@ describe Comment do it "should be able to comment on a person's status" do person= Factory.create :person status = Factory.create(:status_message, :person => person) - @user.person.comment "sup dog", :on => status + @user.comment "sup dog", :on => status StatusMessage.first.comments.first.text.should == "sup dog" StatusMessage.first.comments.first.person.should == @user.person @@ -32,30 +32,33 @@ describe Comment do describe 'comment propagation' do before do @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.person) + @user.friends << Factory.create(:person) + @user.save + + @person_status = Factory.build(:status_message, :person => @person) + @user_status = Factory.build(:status_message, :person => @user.person) end 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.person.comment "yo", :on => @person_status + @user.comment "yo", :on => @person_status end 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.person.comment "yo", :on => @user_status + + 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 person made on your post to all people' do Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request) - com = Comment.create(:person => @person, :text => "balls", :post => @user_status) + Comment.create(:person => @person, :text => "balls", :post => @user_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) - com = Comment.create(:person => @person, :text => "balls", :post => @person_status) + Comment.create(:person => @person, :text => "balls", :post => @person_status) end end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 84f8c8299..c03e2c61c 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -21,7 +21,7 @@ describe Post do before do @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.person)} + (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.person)} (9..11).each { |n| Blog.create(:title => "title #{n}",:body => "test #{n}", :person => @person_two)} @@ -30,20 +30,13 @@ describe Post do end it "should give the most recent blog title and body from owner" do - blog = Blog.my_newest() - blog.person.email.should == @user.email + blog = Blog.newest_for(@user.person) + blog.person.email.should == @user.person.email blog.class.should == Blog blog.title.should == "title 8" blog.body.should == "test 8" end - - 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 == @person_one.email - blog.class.should == Blog - blog.title.should == "title 4" - blog.body.should == "test 4" - end + end describe "stream" do @@ -80,14 +73,14 @@ describe Post do describe 'xml' do it 'should serialize to xml with its person' do message = Factory.create(:status_message, :person => @user.person) - (message.to_xml.to_s.include? @user.email).should == true + (message.to_xml.to_s.include? @user.person.email).should == true end end describe 'deletion' do it 'should delete a posts comments on delete' do post = Factory.create(:status_message, :person => @user.person) - @user.comment "hey", :on=> post + @user.comment "hey", :on => post post.destroy Post.all(:id => post.id).empty?.should == true Comment.all(:text => "hey").empty?.should == true diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 4bab96af2..e4d5b0f50 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -18,7 +18,7 @@ describe StatusMessage do describe "XML" do it 'should serialize to XML' do - message = Factory.create(:status_message, :message => "I hate WALRUSES!") + message = Factory.create(:status_message, :message => "I hate WALRUSES!", :person => @user.person) message.to_xml.to_s.should include "I hate WALRUSES!" end