DG MS tests now green, plus autotest works again
This commit is contained in:
parent
25f388d903
commit
85295015ee
4 changed files with 74 additions and 32 deletions
|
|
@ -4,3 +4,12 @@
|
||||||
|
|
||||||
Autotest.add_discovery { "rails" }
|
Autotest.add_discovery { "rails" }
|
||||||
Autotest.add_discovery { "rspec2" }
|
Autotest.add_discovery { "rspec2" }
|
||||||
|
Autotest.add_hook :initialize do |at|
|
||||||
|
at.add_mapping(%r%^spec/(intergration|mailers|config)/.*rb$%) { |filename, _|
|
||||||
|
filename
|
||||||
|
}
|
||||||
|
|
||||||
|
at.add_mapping(%r%^spec/misc_spec.rb$%) { |filename, _|
|
||||||
|
filename
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,8 @@ module Postzord
|
||||||
def initialize(user, opts={})
|
def initialize(user, opts={})
|
||||||
@user = user
|
@user = user
|
||||||
@user_person = @user.person
|
@user_person = @user.person
|
||||||
|
|
||||||
@salmon_xml = opts[:salmon_xml]
|
@salmon_xml = opts[:salmon_xml]
|
||||||
|
|
||||||
|
|
||||||
@sender = opts[:person] || Webfinger.new(self.salmon.author_email).fetch
|
@sender = opts[:person] || Webfinger.new(self.salmon.author_email).fetch
|
||||||
@author = @sender
|
@author = @sender
|
||||||
|
|
||||||
|
|
@ -30,54 +28,58 @@ module Postzord
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_and_receive(xml)
|
def parse_and_receive(xml)
|
||||||
|
Rails.logger.info("event=receive status=start recipient=#{@user_person.diaspora_handle} payload_type=#{@object.class} sender=#{@sender.diaspora_handle}")
|
||||||
@object ||= Diaspora::Parser.from_xml(xml)
|
@object ||= Diaspora::Parser.from_xml(xml)
|
||||||
if self.valid_object?
|
if self.validate_object
|
||||||
receive_object
|
receive_object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def receive_object
|
def receive_object
|
||||||
obj = @object.receive(@user, @author)
|
obj = @object.receive(@user, @author)
|
||||||
Notification.notify(@user, @object, @author) unless @object.is_a?(Retraction)
|
Notification.notify(@user, @object, @author) if @object.respond_to?(:notification_type)
|
||||||
|
Rails.logger.info("event=receive status=complete recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type#{@object.class}")
|
||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
|
|
||||||
def salmon
|
|
||||||
@salmon ||= Salmon::SalmonSlap.parse(@salmon_xml, @user)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def valid_object?
|
def salmon
|
||||||
Rails.logger.info("event=receive status=start recipient=#{@user_person.diaspora_handle} payload_type=#{@object.class} sender=#{@sender.diaspora_handle}")
|
@salmon ||= Salmon::SalmonSlap.parse(@salmon_xml, @user)
|
||||||
|
end
|
||||||
|
|
||||||
#special casey
|
def xml_author
|
||||||
if @object.is_a?(Request)
|
|
||||||
@object.sender_handle = @sender.diaspora_handle
|
|
||||||
end
|
|
||||||
if @object.is_a?(Comment)
|
if @object.is_a?(Comment)
|
||||||
xml_author = (@user.owns?(@object.post))? @object.diaspora_handle : @object.post.person.diaspora_handle
|
#if A and B are friends, and A sends B a comment from C, we delegate the validation to the owner of the post being commented on
|
||||||
|
xml_author = @user.owns?(@object.post) ? @object.diaspora_handle : @object.post.person.diaspora_handle
|
||||||
@author = Webfinger.new(@object.diaspora_handle).fetch
|
@author = Webfinger.new(@object.diaspora_handle).fetch
|
||||||
else
|
else
|
||||||
xml_author = @object.diaspora_handle
|
xml_author = @object.diaspora_handle
|
||||||
end
|
end
|
||||||
|
xml_author
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_object
|
||||||
#begin similar
|
#begin similar
|
||||||
unless @object.is_a?(Request) || @user.contact_for(@sender)
|
unless @object.is_a?(Request) || @user.contact_for(@sender)
|
||||||
Rails.logger.info("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class}")
|
Rails.logger.info("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class}")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
#special casey
|
||||||
|
if @object.is_a?(Request)
|
||||||
|
@object.sender_handle = @sender.diaspora_handle
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
if (@author.diaspora_handle != xml_author)
|
if (@author.diaspora_handle != xml_author)
|
||||||
Rails.logger.info("event=receive status=abort reason='author in xml does not match retrieved person' payload_type=#{@object.class} recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}")
|
Rails.logger.info("event=receive status=abort reason='author in xml does not match retrieved person' payload_type=#{@object.class} recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if @author
|
if @author
|
||||||
Rails.logger.info("event=receive status=complete recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type#{@object.class}")
|
|
||||||
|
|
||||||
@object.person = @author if @object.respond_to? :person=
|
@object.person = @author if @object.respond_to? :person=
|
||||||
end
|
end
|
||||||
|
|
||||||
@object
|
@object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,17 +15,25 @@ describe 'a user receives a post' do
|
||||||
let(:user3) { make_user }
|
let(:user3) { make_user }
|
||||||
let(:aspect3) { user3.aspects.create(:name => 'heroes') }
|
let(:aspect3) { user3.aspects.create(:name => 'heroes') }
|
||||||
|
|
||||||
|
def zord(user, person, xml)
|
||||||
|
zord = Postzord::Receiver.new(user, :person => person)
|
||||||
|
zord.parse_and_receive(xml)
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
connect_users(user, aspect, user2, aspect2)
|
connect_users(user, aspect, user2, aspect2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it 'should stream only one message to the everyone aspect when a multi-aspected contacts posts' do
|
it 'should stream only one message to the everyone aspect when a multi-aspected contacts posts' do
|
||||||
contact = user.contact_for(user2.person)
|
contact = user.contact_for(user2.person)
|
||||||
user.add_contact_to_aspect(contact, user.aspects.create(:name => "villains"))
|
user.add_contact_to_aspect(contact, user.aspects.create(:name => "villains"))
|
||||||
status = user2.post(:status_message, :message => "Users do things", :to => aspect2.id)
|
status = user2.post(:status_message, :message => "Users do things", :to => aspect2.id)
|
||||||
xml = status.to_diaspora_xml
|
#xml = status.to_diaspora_xml
|
||||||
Diaspora::WebSocket.should_receive(:queue_to_user).exactly(:once)
|
Diaspora::WebSocket.should_receive(:queue_to_user).exactly(:once)
|
||||||
Postzord::Receiver.new(user, :object => status, :person => user2.person)
|
zord = Postzord::Receiver.new(user, :object => status, :person => user2.person)
|
||||||
|
zord.receive_object
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to parse and store a status message from xml' do
|
it 'should be able to parse and store a status message from xml' do
|
||||||
|
|
@ -36,8 +44,7 @@ describe 'a user receives a post' do
|
||||||
status_message.destroy
|
status_message.destroy
|
||||||
|
|
||||||
lambda {
|
lambda {
|
||||||
zord = Postzord::Receiver.new(user, :person => user2.person)
|
zord(user, user2.person, xml)
|
||||||
zord.parse_and_receive(xml)
|
|
||||||
}.should change(Post,:count).by(1)
|
}.should change(Post,:count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -56,7 +63,9 @@ describe 'a user receives a post' do
|
||||||
status = user.post :status_message, :message => "store this!", :to => aspect.id
|
status = user.post :status_message, :message => "store this!", :to => aspect.id
|
||||||
status.message = 'foo'
|
status.message = 'foo'
|
||||||
xml = status.to_diaspora_xml
|
xml = status.to_diaspora_xml
|
||||||
user2.receive(xml, user.person)
|
|
||||||
|
zord(user2, user.person, xml)
|
||||||
|
|
||||||
status.reload.message.should == 'store this!'
|
status.reload.message.should == 'store this!'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -64,7 +73,10 @@ describe 'a user receives a post' do
|
||||||
photo = user.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => aspect.id)
|
photo = user.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => aspect.id)
|
||||||
photo.caption = 'foo'
|
photo.caption = 'foo'
|
||||||
xml = photo.to_diaspora_xml
|
xml = photo.to_diaspora_xml
|
||||||
user2.reload.receive(xml, user.person)
|
user2.reload
|
||||||
|
|
||||||
|
zord(user2, user.person, xml)
|
||||||
|
|
||||||
photo.reload.caption.should match(/foo/)
|
photo.reload.caption.should match(/foo/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -110,7 +122,9 @@ describe 'a user receives a post' do
|
||||||
|
|
||||||
it 'should not override userrefs on receive by another person' do
|
it 'should not override userrefs on receive by another person' do
|
||||||
user3.activate_contact(user2.person, aspect3)
|
user3.activate_contact(user2.person, aspect3)
|
||||||
user3.receive @status_message.to_diaspora_xml, user2.person
|
xml = @status_message.to_diaspora_xml
|
||||||
|
|
||||||
|
zord(user3, user2.person, xml)
|
||||||
|
|
||||||
@status_message.reload
|
@status_message.reload
|
||||||
@status_message.user_refs.should == 2
|
@status_message.user_refs.should == 2
|
||||||
|
|
@ -126,8 +140,10 @@ describe 'a user receives a post' do
|
||||||
connect_users(user, aspect, user3, aspect3)
|
connect_users(user, aspect, user3, aspect3)
|
||||||
@post = user.post :status_message, :message => "hello", :to => aspect.id
|
@post = user.post :status_message, :message => "hello", :to => aspect.id
|
||||||
|
|
||||||
user2.receive @post.to_diaspora_xml, user.person
|
xml = @post.to_diaspora_xml
|
||||||
user3.receive @post.to_diaspora_xml, user.person
|
|
||||||
|
zord(user2, user.person, xml)
|
||||||
|
zord(user3, user.person, xml)
|
||||||
|
|
||||||
@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)
|
||||||
|
|
@ -141,7 +157,9 @@ describe 'a user receives a post' 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(@xml, user.person)
|
|
||||||
|
zord(user2, user.person, @xml)
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -157,11 +175,12 @@ describe 'a user receives a post' do
|
||||||
Person.should_receive(:by_account_identifier).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(@xml, user.person)
|
|
||||||
|
zord(user2, user.person, @xml)
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -174,7 +193,11 @@ describe 'a user receives a post' do
|
||||||
let(:salmon){user.salmon( post )}
|
let(:salmon){user.salmon( post )}
|
||||||
|
|
||||||
it 'should receive a salmon for a post' do
|
it 'should receive a salmon for a post' do
|
||||||
user2.receive_salmon( salmon.xml_for(user2.person) )
|
salmon_xml = salmon.xml_for(user2.person)
|
||||||
|
|
||||||
|
zord = Postzord::Receiver.new(user2, :salmon_xml => salmon_xml)
|
||||||
|
zord.perform
|
||||||
|
|
||||||
user2.visible_post_ids.include?(post.id).should be true
|
user2.visible_post_ids.include?(post.id).should be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,16 @@ describe Postzord::Receiver do
|
||||||
@salmon = @zord.instance_variable_get(:@salmon)
|
@salmon = @zord.instance_variable_get(:@salmon)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls Notification.notify' do
|
it 'calls Notification.notify if object responds to notification_type' do
|
||||||
Notification.should_receive(:notify)
|
cm = Comment.new
|
||||||
|
cm.stub!(:receive)
|
||||||
|
Notification.should_receive(:notify).with(@user, cm, @person2)
|
||||||
|
zord = Postzord::Receiver.new(@user, :person => @person2, :object => cm)
|
||||||
|
zord.receive_object
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not call Notification.notify if object does not respond to notification_type' do
|
||||||
|
Notification.should_not_receive(:notify)
|
||||||
@zord.receive_object
|
@zord.receive_object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue