im in ur test stubbin ur mailers

This commit is contained in:
Sarah Mei 2010-10-22 06:22:47 -07:00
parent 6620f33ae2
commit 7e4529f2bd
2 changed files with 56 additions and 45 deletions

View file

@ -6,10 +6,10 @@ require 'spec_helper'
describe PublicsController do describe PublicsController do
render_views render_views
let(:user) {Factory.create :user} let(:user) { Factory.create :user }
let(:user2){Factory.create :user} let(:user2) { Factory.create :user }
let(:aspect1){user.aspect(:name => "foo")} let(:aspect1) { user.aspect(:name => "foo") }
let(:aspect2){user2.aspect(:name => "far")} let(:aspect2) { user2.aspect(:name => "far") }
before do before do
sign_in :user, user sign_in :user, user
end end
@ -23,7 +23,7 @@ describe PublicsController do
it 'should accept a post from another node and save the information' do it 'should accept a post from another node and save the information' do
message = user2.build_post(:status_message, :message => "hi") message = user2.build_post(:status_message, :message => "hi")
friend_users(user, aspect1, user2, aspect2) friend_users(user, aspect1, user2, aspect2)
user.reload user.reload
user.visible_post_ids.include?(message.id).should be false user.visible_post_ids.include?(message.id).should be false
@ -77,10 +77,13 @@ describe PublicsController do
end end
describe 'friend requests' do describe 'friend requests' do
let(:aspect2) {user2.aspect(:name => 'disciples')} let(:aspect2) { user2.aspect(:name => 'disciples') }
let!(:req) {user2.send_friend_request_to(user.person, aspect2)} let!(:req) { user2.send_friend_request_to(user.person, aspect2) }
let!(:xml) {user2.salmon(req).xml_for(user.person)} let!(:xml) { user2.salmon(req).xml_for(user.person) }
before do before do
deliverable = Object.new
deliverable.stub!(:deliver)
Notifier.stub!(:new_request).and_return(deliverable)
req.delete req.delete
user2.reload user2.reload
user2.pending_requests.count.should be 1 user2.pending_requests.count.should be 1

View file

@ -5,15 +5,15 @@
require 'spec_helper' require 'spec_helper'
describe Diaspora::Parser do describe Diaspora::Parser do
let(:user) {Factory.create(:user)} let(:user) { Factory.create(:user) }
let(:aspect) {user.aspect(:name => 'spies')} let(:aspect) { user.aspect(:name => 'spies') }
let(:user2) {Factory.create(:user)} let(:user2) { Factory.create(:user) }
let(:aspect2){user2.aspect(:name => "pandas")} let(:aspect2) { user2.aspect(:name => "pandas") }
let(:user3) {Factory.create :user} let(:user3) { Factory.create :user }
let(:person) {user3.person} let(:person) { user3.person }
describe "parsing compliant XML object" do 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 post = user.post :status_message, :message => "hello", :to => aspect.id
comment = Factory.build(:comment, :post => post, :person => @person, :text => "Freedom!") comment = Factory.build(:comment, :post => post, :person => @person, :text => "Freedom!")
xml = comment.to_diaspora_xml xml = comment.to_diaspora_xml
@ -25,7 +25,7 @@ describe Diaspora::Parser do
end end
it 'should be able to correctly handle person on a comment with person not in db' do 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 post = user.post :status_message, :message => "hello", :to => aspect.id
comment = user2.comment "Fool!", :on => post comment = user2.comment "Fool!", :on => post
@ -40,42 +40,50 @@ describe Diaspora::Parser do
end end
it 'should accept retractions' do 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) message = Factory.create(:status_message, :person => user2.person)
retraction = Retraction.for(message) retraction = Retraction.for(message)
xml = retraction.to_diaspora_xml 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 end
it "should create a new person upon getting a person request" do context "friending" do
request = Request.instantiate(:to =>"http://www.google.com/", :from => person) 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 xml = request.to_diaspora_xml
person.destroy
user
lambda {user.receive xml, person}.should change(Person, :count).by(1)
end
it "should not create a new person if the person is already here" do user3.destroy
request = Request.instantiate(:to =>"http://www.google.com/", :from => user2.person) person.destroy
original_person_id = user2.person.id user
xml = request.to_diaspora_xml lambda { user.receive xml, person }.should change(Person, :count).by(1)
user end
lambda {user.receive xml, user2.person}.should_not change(Person, :count)
user2.reload it "should not create a new person if the person is already here" do
user2.person.reload request = Request.instantiate(:to =>"http://www.google.com/", :from => user2.person)
user2.serialized_private_key.include?("PRIVATE").should be true 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] + "/" user2.reload
Person.where(:url => url).first.id.should == original_person_id 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 end
it "should activate the Person if I initiated a request to that url" do 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 user.reload
request.reverse_for user3 request.reverse_for user3
@ -95,16 +103,16 @@ describe Diaspora::Parser do
end end
it 'should process retraction for a person' do 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 = Retraction.for(user2)
retraction_xml = retraction.to_diaspora_xml retraction_xml = retraction.to_diaspora_xml
lambda {user.receive retraction_xml, user2.person}.should change{ lambda { user.receive retraction_xml, user2.person }.should change {
aspect.reload.people.size}.by(-1) aspect.reload.people.size }.by(-1)
end end
it 'should marshal a profile for a person' do it 'should marshal a profile for a person' do
friend_users(user, aspect, user2, aspect2) friend_users(user, aspect, user2, aspect2)
#Create person #Create person
person = user2.person person = user2.person
id = person.id id = person.id
@ -132,9 +140,9 @@ describe Diaspora::Parser do
person = Person.first(:id => person.id) person = Person.first(:id => person.id)
person.profile.should_not be nil person.profile.should_not be nil
person.profile.first_name.should == old_profile.first_name person.profile.first_name.should == old_profile.first_name
person.profile.last_name.should == old_profile.last_name person.profile.last_name.should == old_profile.last_name
person.profile.image_url.should == old_profile.image_url person.profile.image_url.should == old_profile.image_url
end end
end end
end end