moved tests and slayed the profile not updating bug
This commit is contained in:
parent
4328f72bfb
commit
e4d9ec64cd
4 changed files with 92 additions and 75 deletions
|
|
@ -36,9 +36,10 @@ class Profile < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def receive(user, person)
|
||||
person.profile = self
|
||||
person.save
|
||||
self
|
||||
Rails.logger.info("event=receive payload_type=profile sender=#{person} to=#{user}")
|
||||
person.profile.update_attributes self.attributes
|
||||
|
||||
person.profile
|
||||
end
|
||||
|
||||
def diaspora_handle
|
||||
|
|
|
|||
|
|
@ -272,4 +272,80 @@ describe 'a user receives a post' do
|
|||
@user2.raw_visible_posts.include?(post).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'retractions' do
|
||||
it 'should accept retractions' do
|
||||
message = @user2.post(:status_message, :message => "cats", :to => @aspect2.id)
|
||||
retraction = Retraction.for(message)
|
||||
xml = retraction.to_diaspora_xml
|
||||
|
||||
lambda {
|
||||
zord = Postzord::Receiver.new(@user1, :person => @user2.person)
|
||||
zord.parse_and_receive(xml)
|
||||
}.should change(StatusMessage, :count).by(-1)
|
||||
end
|
||||
|
||||
it "should activate the Person if I initiated a request to that url" do
|
||||
begin
|
||||
@user1.send_contact_request_to(@user3.person, @aspect)
|
||||
rescue Exception => e
|
||||
raise e.original_exception
|
||||
end
|
||||
request = @user3.request_from(@user1.person)
|
||||
fantasy_resque do
|
||||
@user3.accept_and_respond(request.id, @aspect3.id)
|
||||
end
|
||||
@user1.reload
|
||||
@aspect.reload
|
||||
new_contact = @user1.contact_for(@user3.person)
|
||||
@aspect.contacts.include?(new_contact).should be true
|
||||
@user1.contacts.include?(new_contact).should be true
|
||||
end
|
||||
|
||||
it 'should process retraction for a person' do
|
||||
retraction = Retraction.for(@user2)
|
||||
retraction_xml = retraction.to_diaspora_xml
|
||||
|
||||
lambda {
|
||||
zord = Postzord::Receiver.new(@user1, :person => @user2.person)
|
||||
zord.parse_and_receive(retraction_xml)
|
||||
}.should change {
|
||||
@aspect.contacts(true).size }.by(-1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it 'should marshal a profile for a person' do
|
||||
#Create person
|
||||
person = @user2.person
|
||||
id = person.id
|
||||
person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com")
|
||||
person.save
|
||||
|
||||
#Cache profile for checking against marshaled profile
|
||||
old_profile = person.profile.dup
|
||||
old_profile.first_name.should == 'bob'
|
||||
|
||||
#Build xml for profile, clear profile
|
||||
xml = person.profile.to_diaspora_xml
|
||||
reloaded_person = Person.find(id)
|
||||
reloaded_person.profile.delete
|
||||
reloaded_person.save(:validate => false)
|
||||
|
||||
#Make sure profile is cleared
|
||||
Person.find(id).profile.should be nil
|
||||
old_profile.first_name.should == 'bob'
|
||||
|
||||
#Marshal profile
|
||||
zord = Postzord::Receiver.new(@user1, :person => person)
|
||||
zord.parse_and_receive(xml)
|
||||
|
||||
#Check that marshaled profile is the same as old profile
|
||||
person = Person.find(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
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,78 +29,6 @@ describe Diaspora::Parser do
|
|||
comment_from_xml.text.should == "Freedom!"
|
||||
comment_from_xml.should_not be comment
|
||||
end
|
||||
|
||||
it 'should accept retractions' do
|
||||
message = @user2.post(:status_message, :message => "cats", :to => @aspect2.id)
|
||||
retraction = Retraction.for(message)
|
||||
xml = retraction.to_diaspora_xml
|
||||
|
||||
lambda {
|
||||
zord = Postzord::Receiver.new(@user1, :person => @user2.person)
|
||||
zord.parse_and_receive(xml)
|
||||
}.should change(StatusMessage, :count).by(-1)
|
||||
end
|
||||
|
||||
it "should activate the Person if I initiated a request to that url" do
|
||||
begin
|
||||
@user1.send_contact_request_to(@user3.person, @aspect1)
|
||||
rescue Exception => e
|
||||
raise e.original_exception
|
||||
end
|
||||
request = @user3.request_from(@user1.person)
|
||||
fantasy_resque do
|
||||
@user3.accept_and_respond(request.id, @aspect3.id)
|
||||
end
|
||||
@user1.reload
|
||||
@aspect1.reload
|
||||
new_contact = @user1.contact_for(@user3.person)
|
||||
@aspect1.contacts.include?(new_contact).should be true
|
||||
@user1.contacts.include?(new_contact).should be true
|
||||
end
|
||||
|
||||
it 'should process retraction for a person' do
|
||||
retraction = Retraction.for(@user2)
|
||||
retraction_xml = retraction.to_diaspora_xml
|
||||
|
||||
lambda {
|
||||
zord = Postzord::Receiver.new(@user1, :person => @user2.person)
|
||||
zord.parse_and_receive(retraction_xml)
|
||||
}.should change {
|
||||
@aspect1.contacts(true).size }.by(-1)
|
||||
end
|
||||
|
||||
it 'should marshal a profile for a person' do
|
||||
#Create person
|
||||
person = @user2.person
|
||||
id = person.id
|
||||
person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com")
|
||||
person.save
|
||||
|
||||
#Cache profile for checking against marshaled profile
|
||||
old_profile = person.profile.dup
|
||||
old_profile.first_name.should == 'bob'
|
||||
|
||||
#Build xml for profile, clear profile
|
||||
xml = person.profile.to_diaspora_xml
|
||||
reloaded_person = Person.find(id)
|
||||
reloaded_person.profile.delete
|
||||
reloaded_person.save(:validate => false)
|
||||
|
||||
#Make sure profile is cleared
|
||||
Person.find(id).profile.should be nil
|
||||
old_profile.first_name.should == 'bob'
|
||||
|
||||
#Marshal profile
|
||||
zord = Postzord::Receiver.new(@user1, :person => person)
|
||||
zord.parse_and_receive(xml)
|
||||
|
||||
#Check that marshaled profile is the same as old profile
|
||||
person = Person.find(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
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -146,4 +146,16 @@ describe Profile do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#receive' do
|
||||
|
||||
it 'updates the profile in place' do
|
||||
local_luke, local_leia, remote_raphael = set_up_friends
|
||||
new_profile = Factory.build :profile
|
||||
lambda{
|
||||
new_profile.receive(local_leia, remote_raphael)
|
||||
}.should_not change(Profile, :count)
|
||||
remote_raphael.last_name.should == new_profile.last_name
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue