Remove some extra receives in tests

This commit is contained in:
Raphael 2010-11-05 14:14:38 -07:00
parent cc92f61583
commit 0ce37bbfa8
5 changed files with 37 additions and 71 deletions

View file

@ -80,14 +80,11 @@ describe StatusMessagesController do
end end
it 'will not let you destroy posts visible to you' do it 'will not let you destroy posts visible to you' do
user.receive message2.to_diaspora_xml, user2.person
user.visible_posts.include?(message2).should be true
delete :destroy, :id => message2.id delete :destroy, :id => message2.id
StatusMessage.find_by_id(message2.id).should_not be_nil StatusMessage.find_by_id(message2.id).should_not be_nil
end end
it 'will not let you destory posts you do not own' do it 'will not let you destory posts you do not own' do
user.visible_posts.include?(message2).should be false
delete :destroy, :id => message2.id delete :destroy, :id => message2.id
StatusMessage.find_by_id(message2.id).should_not be_nil StatusMessage.find_by_id(message2.id).should_not be_nil
end end

View file

@ -9,8 +9,7 @@ describe Diaspora::Parser do
let(:aspect) { user.aspects.create(:name => 'spies') } let(:aspect) { user.aspects.create(:name => 'spies') }
let(:user2) { make_user } let(:user2) { make_user }
let(:aspect2) { user2.aspects.create(:name => "pandas") } let(:aspect2) { user2.aspects.create(:name => "pandas") }
let(:user3) { make_user } let(:person) { Factory.create(:person)}
let(:person) { user3.person }
describe "parsing compliant XML object" do describe "parsing compliant XML object" do
it 'should be able to correctly parse comment fields' do it 'should be able to correctly parse comment fields' do
@ -52,21 +51,13 @@ describe Diaspora::Parser do
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) user.send_friend_request_to(user2.person, aspect)
user.reload request = user2.reload.pending_requests.find_by_destination_url!(user2.receive_url)
reversed = request.reverse_for user3 user2.accept_and_respond(request.id, aspect2.id)
xml = user3.salmon(reversed).xml_for(user.person)
user3.delete
user.receive_salmon(xml)
new_person = Person.find_by_url(user3.person.url)
new_person.nil?.should be false
user.reload user.reload
aspect.reload aspect.reload
new_contact = user.contact_for(new_person) new_contact = user.contact_for(user2.person)
aspect.people.include?(new_contact).should be true aspect.people.include?(new_contact).should be true
user.friends.include?(new_contact).should be true user.friends.include?(new_contact).should be true
end end

View file

@ -120,8 +120,6 @@ describe Aspect do
message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id) message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
user.receive message.to_diaspora_xml, user2.person
aspect.reload aspect.reload
aspect.posts.include?(message).should be true aspect.posts.include?(message).should be true
user.visible_posts(:by_members_of => aspect).include?(message).should be true user.visible_posts(:by_members_of => aspect).include?(message).should be true
@ -134,14 +132,9 @@ describe Aspect do
message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id) message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
user.receive message.to_diaspora_xml, user2.person aspect.reload.post_ids.include?(message.id).should be true
aspect.reload
aspect.post_ids.include?(message.id).should be true
retraction = user2.retract(message) retraction = user2.retract(message)
user.receive retraction.to_diaspora_xml, user2.person
aspect.reload aspect.reload
aspect.post_ids.include?(message.id).should be false aspect.post_ids.include?(message.id).should be false
@ -195,11 +188,9 @@ describe Aspect do
context 'moving and removing posts' do context 'moving and removing posts' do
let(:message) { user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)}
let(:message2){user3.post(:status_message, :message => "other post", :to => aspect3.id)}
before do before do
user.receive message.to_diaspora_xml, user2.person @message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
aspect.reload aspect.reload
@post_count = aspect.posts.count @post_count = aspect.posts.count
@post_count1 = aspect1.posts.count @post_count1 = aspect1.posts.count
@ -208,9 +199,9 @@ describe Aspect do
end end
it 'moves the persons posts into the new aspect' do it 'moves the persons posts into the new aspect' do
user.add_person_to_aspect(user2.person.id, aspect1.id, :posts => [message] ) user.add_person_to_aspect(user2.person.id, aspect1.id, :posts => [@message] )
aspect1.reload aspect1.reload
aspect1.posts.should == [message] aspect1.posts.should == [@message]
end end
@ -222,10 +213,9 @@ describe Aspect do
it 'should not delete other peoples posts' do it 'should not delete other peoples posts' do
friend_users(user, aspect, user3, aspect3) friend_users(user, aspect, user3, aspect3)
user.receive message2.to_diaspora_xml, user3.person user.delete_person_from_aspect(user3.person.id, aspect.id)
user.delete_person_from_aspect(user2.person.id, aspect.id)
aspect.reload aspect.reload
aspect.posts.should == [message2] aspect.posts.should == [@message]
end end
describe '#move_friend' do describe '#move_friend' do

View file

@ -5,9 +5,9 @@
require 'spec_helper' require 'spec_helper'
describe Request do describe Request do
let(:user) { make_user } let(:user) { make_user }
let(:user2) { make_user} let(:user2) { make_user }
let(:person) {Factory :person} let(:person) { Factory :person }
let(:aspect) { user.aspects.create(:name => "dudes") } let(:aspect) { user.aspects.create(:name => "dudes") }
let(:request){ user.send_friend_request_to user2.person, aspect } let(:request){ user.send_friend_request_to user2.person, aspect }
@ -30,22 +30,19 @@ describe Request do
describe '#request_from_me' do describe '#request_from_me' do
it 'recognizes requests from me' do it 'recognizes requests from me' do
request request
user.reload user.request_from_me?(request).should be_true
user.request_from_me?(request).should be true
end end
it 'recognized when a request is not from me' do it 'recognized when a request is not from me' do
user2.receive_salmon(user.salmon(request).xml_for(user2.person)) user2.request_from_me?(request).should be_false
user2.reload
user2.request_from_me?(request).should == false
end end
end end
context 'quering request through user' do context 'quering request through user' do
it 'finds requests for that user' do it 'finds requests for that user' do
len = user2.requests_for_me.size request
user2.receive_salmon(user.salmon(request).xml_for(user2.person)) user2.reload
user2.reload.requests_for_me.size.should == len + 1 user2.requests_for_me.detect{|r| r.callback_url == user.receive_url}.should_not be_nil
end end
end end

View file

@ -15,8 +15,6 @@ describe User do
let(:user3) { make_user } let(:user3) { make_user }
let(:aspect3) { user3.aspects.create(:name => 'heroes') } let(:aspect3) { user3.aspects.create(:name => 'heroes') }
let!(:status) {user.post(:status_message, :message => "Original", :to => aspect.id)}
let(:photo) {user.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => aspect.id)}
before do before do
friend_users(user, aspect, user2, aspect2) friend_users(user, aspect, user2, aspect2)
@ -43,11 +41,9 @@ describe User do
it 'should not create new aspects on message receive' do it 'should not create new aspects on message receive' do
num_aspects = user.aspects.size num_aspects = user.aspects.size
(0..5).each{ |n| 2.times do |n|
status_message = user2.post :status_message, :message => "store this #{n}!", :to => aspect2.id status_message = user2.post :status_message, :message => "store this #{n}!", :to => aspect2.id
xml = status_message.to_diaspora_xml end
user.receive xml, user2.person
}
user.aspects.size.should == num_aspects user.aspects.size.should == num_aspects
end end
@ -56,33 +52,28 @@ describe User do
it 'should handle the case where the webfinger fails' do it 'should handle the case where the webfinger fails' do
Person.should_receive(:by_account_identifier).and_return("not a person") Person.should_receive(:by_account_identifier).and_return("not a person")
proc{user2.receive_salmon(user.salmon(status).xml_for(user2.person))}.should_not raise_error proc{
user2.post :status_message, :message => "store this!", :to => aspect2.id
}.should_not raise_error
end end
end end
context 'update posts' do context 'update posts' do
it 'does not update posts not marked as mutable' do it 'does not update posts not marked as mutable' do
user2.receive_salmon(user.salmon(status).xml_for(user2.person)) status = user.post :status_message, :message => "store this!", :to => aspect.id
status.message = 'foo' status.message = 'foo'
xml = user.salmon(status).xml_for(user2.person) xml = status.to_diaspora_xml
user2.receive(xml, user.person)
status.reload.message.should == 'Original' status.reload.message.should == 'store this!'
user2.receive_salmon(xml)
status.reload.message.should == 'Original'
end end
it 'updates posts marked as mutable' do it 'updates posts marked as mutable' do
user2.receive_salmon(user.salmon(photo).xml_for(user2.person)) photo = user.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => aspect.id)
photo.caption = 'foo' photo.caption = 'foo'
xml = user.salmon(photo).xml_for(user2.person) xml = photo.to_diaspora_xml
user2.reload.receive(xml, user.person)
photo.reload.caption.should match(/Original/)
user2.receive_salmon(xml)
photo.reload.caption.should match(/foo/) photo.reload.caption.should match(/foo/)
end end
@ -103,7 +94,7 @@ describe User do
it 'should be removed on unfriending' do it 'should be removed on unfriending' do
user.unfriend(user2.person) user.unfriend(user2.person)
user.reload user.reload
user.raw_visible_posts.count.should == 1 user.raw_visible_posts.should_not include @status_message
end end
it 'should be remove a post if the noone links to it' do it 'should be remove a post if the noone links to it' do
@ -145,7 +136,7 @@ describe User do
@comment = user3.comment('tada',:on => @post) @comment = user3.comment('tada',:on => @post)
@comment.post_creator_signature = @comment.sign_with_key(user.encryption_key) @comment.post_creator_signature = @comment.sign_with_key(user.encryption_key)
@xml = user.salmon(@comment).xml_for(user2.person) @xml = @comment.to_diaspora_xml
@comment.delete @comment.delete
end end
@ -155,7 +146,7 @@ describe User do
user2.reload.raw_visible_posts.size.should == 1 user2.reload.raw_visible_posts.size.should == 1
post_in_db = user2.raw_visible_posts.first post_in_db = user2.raw_visible_posts.first
post_in_db.comments.should == [] post_in_db.comments.should == []
user2.receive_salmon(@xml) user2.receive(@xml, user.person)
post_in_db.reload post_in_db.reload
post_in_db.comments.include?(@comment).should be true post_in_db.comments.include?(@comment).should be true
@ -168,14 +159,14 @@ describe User do
user3.delete user3.delete
#stubs async webfinger #stubs async webfinger
Person.should_receive(:by_account_identifier).twice.and_return{ |handle| if handle == user.person.diaspora_handle; user.person.save Person.should_receive(:by_account_identifier).and_return{ |handle| if handle == user.person.diaspora_handle; user.person.save
user.person; else; remote_person.save; remote_person; end } user.person; else; remote_person.save; remote_person; end }
user2.reload.raw_visible_posts.size.should == 1 user2.reload.raw_visible_posts.size.should == 1
post_in_db = user2.raw_visible_posts.first post_in_db = user2.raw_visible_posts.first
post_in_db.comments.should == [] post_in_db.comments.should == []
user2.receive_salmon(@xml) user2.receive(@xml, user.person)
post_in_db.reload post_in_db.reload
post_in_db.comments.include?(@comment).should be true post_in_db.comments.include?(@comment).should be true