diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index cf1a71d88..11a35da95 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -6,10 +6,10 @@ require 'spec_helper' describe PublicsController do render_views - let(:user) {Factory.create :user} - let(:user2){Factory.create :user} - let(:aspect1){user.aspect(:name => "foo")} - let(:aspect2){user2.aspect(:name => "far")} + let(:user) { Factory.create :user } + let(:user2) { Factory.create :user } + let(:aspect1) { user.aspect(:name => "foo") } + let(:aspect2) { user2.aspect(:name => "far") } before do sign_in :user, user end @@ -23,7 +23,7 @@ describe PublicsController do it 'should accept a post from another node and save the information' do message = user2.build_post(:status_message, :message => "hi") friend_users(user, aspect1, user2, aspect2) - + user.reload user.visible_post_ids.include?(message.id).should be false @@ -77,10 +77,13 @@ describe PublicsController do end describe 'friend requests' do - let(:aspect2) {user2.aspect(:name => 'disciples')} - let!(:req) {user2.send_friend_request_to(user.person, aspect2)} - let!(:xml) {user2.salmon(req).xml_for(user.person)} + let(:aspect2) { user2.aspect(:name => 'disciples') } + let!(:req) { user2.send_friend_request_to(user.person, aspect2) } + let!(:xml) { user2.salmon(req).xml_for(user.person) } before do + deliverable = Object.new + deliverable.stub!(:deliver) + Notifier.stub!(:new_request).and_return(deliverable) req.delete user2.reload user2.pending_requests.count.should be 1 diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index 72b3d96e0..f97a514c3 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -5,15 +5,15 @@ require 'spec_helper' describe Diaspora::Parser do - let(:user) {Factory.create(:user)} - let(:aspect) {user.aspect(:name => 'spies')} - let(:user2) {Factory.create(:user)} - let(:aspect2){user2.aspect(:name => "pandas")} - let(:user3) {Factory.create :user} - let(:person) {user3.person} + let(:user) { Factory.create(:user) } + let(:aspect) { user.aspect(:name => 'spies') } + let(:user2) { Factory.create(:user) } + let(:aspect2) { user2.aspect(:name => "pandas") } + let(:user3) { Factory.create :user } + let(:person) { user3.person } describe "parsing compliant XML object" do - it 'should be able to correctly handle comments with person in db' do + it 'should be able to correctly handle comments with person in db' do post = user.post :status_message, :message => "hello", :to => aspect.id comment = Factory.build(:comment, :post => post, :person => @person, :text => "Freedom!") xml = comment.to_diaspora_xml @@ -25,7 +25,7 @@ describe Diaspora::Parser do end it 'should be able to correctly handle person on a comment with person not in db' do - friend_users(user, aspect, user2, aspect2) + friend_users(user, aspect, user2, aspect2) post = user.post :status_message, :message => "hello", :to => aspect.id comment = user2.comment "Fool!", :on => post @@ -40,42 +40,50 @@ describe Diaspora::Parser do end it 'should accept retractions' do - friend_users(user, aspect, user2, aspect2) + friend_users(user, aspect, user2, aspect2) message = Factory.create(:status_message, :person => user2.person) retraction = Retraction.for(message) xml = retraction.to_diaspora_xml - proc {user.receive xml, user2.person}.should change(StatusMessage, :count).by(-1) + proc { user.receive xml, user2.person }.should change(StatusMessage, :count).by(-1) end - it "should create a new person upon getting a person request" do - request = Request.instantiate(:to =>"http://www.google.com/", :from => person) + context "friending" do + before do + deliverable = Object.new + deliverable.stub!(:deliver) + Notifier.stub!(:new_request).and_return(deliverable) + end - xml = request.to_diaspora_xml + it "should create a new person upon getting a person request" do + request = Request.instantiate(:to =>"http://www.google.com/", :from => person) - user3.destroy - person.destroy - user - lambda {user.receive xml, person}.should change(Person, :count).by(1) - end + xml = request.to_diaspora_xml - it "should not create a new person if the person is already here" do - request = Request.instantiate(:to =>"http://www.google.com/", :from => user2.person) - original_person_id = user2.person.id - xml = request.to_diaspora_xml - user - lambda {user.receive xml, user2.person}.should_not change(Person, :count) + user3.destroy + person.destroy + user + lambda { user.receive xml, person }.should change(Person, :count).by(1) + end - user2.reload - user2.person.reload - user2.serialized_private_key.include?("PRIVATE").should be true + it "should not create a new person if the person is already here" do + request = Request.instantiate(:to =>"http://www.google.com/", :from => user2.person) + original_person_id = user2.person.id + xml = request.to_diaspora_xml + user + lambda { user.receive xml, user2.person }.should_not change(Person, :count) - url = "http://" + request.callback_url.split("/")[2] + "/" - Person.where(:url => url).first.id.should == original_person_id + user2.reload + user2.person.reload + user2.serialized_private_key.include?("PRIVATE").should be true + + url = "http://" + request.callback_url.split("/")[2] + "/" + Person.where(:url => url).first.id.should == original_person_id + end end it "should activate the Person if I initiated a request to that url" do - request = user.send_friend_request_to( user3.person, aspect) + request = user.send_friend_request_to(user3.person, aspect) user.reload request.reverse_for user3 @@ -95,16 +103,16 @@ describe Diaspora::Parser do end it 'should process retraction for a person' do - friend_users(user, aspect, user2, aspect2) + friend_users(user, aspect, user2, aspect2) retraction = Retraction.for(user2) retraction_xml = retraction.to_diaspora_xml - lambda {user.receive retraction_xml, user2.person}.should change{ - aspect.reload.people.size}.by(-1) + lambda { user.receive retraction_xml, user2.person }.should change { + aspect.reload.people.size }.by(-1) end it 'should marshal a profile for a person' do - friend_users(user, aspect, user2, aspect2) + friend_users(user, aspect, user2, aspect2) #Create person person = user2.person id = person.id @@ -132,9 +140,9 @@ describe Diaspora::Parser do person = Person.first(:id => person.id) person.profile.should_not be nil 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 + person.profile.last_name.should == old_profile.last_name + person.profile.image_url.should == old_profile.image_url + end end end