Error rescue in parser now is specific to not a real type error
This commit is contained in:
parent
d130b82e42
commit
62e6ea0756
3 changed files with 13 additions and 7 deletions
|
|
@ -22,7 +22,8 @@ module Diaspora
|
||||||
body.children.each do |post|
|
body.children.each do |post|
|
||||||
begin
|
begin
|
||||||
object = post.name.camelize.constantize.from_xml post.to_s
|
object = post.name.camelize.constantize.from_xml post.to_s
|
||||||
if object.respond_to? :person
|
if object.is_a? Retraction
|
||||||
|
elsif object.respond_to? :person
|
||||||
object.person = parse_owner_from_xml post.to_s
|
object.person = parse_owner_from_xml post.to_s
|
||||||
elsif object.is_a? Profile
|
elsif object.is_a? Profile
|
||||||
puts "got into parse objects from xml PROFILE"
|
puts "got into parse objects from xml PROFILE"
|
||||||
|
|
@ -31,8 +32,12 @@ module Diaspora
|
||||||
person.save
|
person.save
|
||||||
end
|
end
|
||||||
objects << object
|
objects << object
|
||||||
rescue
|
rescue NameError => e
|
||||||
|
if e.message.include? 'wrong constant name'
|
||||||
Rails.logger.info "Not a real type: #{object.to_s}"
|
Rails.logger.info "Not a real type: #{object.to_s}"
|
||||||
|
else
|
||||||
|
raise e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
objects
|
objects
|
||||||
|
|
@ -43,6 +48,7 @@ module Diaspora
|
||||||
objects.each do |p|
|
objects.each do |p|
|
||||||
Rails.logger.info("Receiving object:\n#{p.inspect}")
|
Rails.logger.info("Receiving object:\n#{p.inspect}")
|
||||||
if p.is_a? Retraction
|
if p.is_a? Retraction
|
||||||
|
puts "Got a retraction for #{p.post_id}"
|
||||||
p.perform
|
p.perform
|
||||||
elsif p.is_a? Request
|
elsif p.is_a? Request
|
||||||
User.owner.receive_friend_request(p)
|
User.owner.receive_friend_request(p)
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ describe Diaspora::Parser do
|
||||||
message = Factory.create(:status_message, :person => person)
|
message = Factory.create(:status_message, :person => person)
|
||||||
retraction = Retraction.for(message)
|
retraction = Retraction.for(message)
|
||||||
request = Post.build_xml_for( [retraction] )
|
request = Post.build_xml_for( [retraction] )
|
||||||
|
puts request
|
||||||
|
|
||||||
StatusMessage.count.should == 1
|
StatusMessage.count.should == 1
|
||||||
store_objects_from_xml( request )
|
store_objects_from_xml( request )
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,22 @@
|
||||||
require File.dirname(__FILE__) + '/../spec_helper'
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
|
|
||||||
describe Retraction do
|
describe Retraction do
|
||||||
describe "posts" do
|
|
||||||
before do
|
before do
|
||||||
@user = Factory.create(:user)
|
@user = Factory.create(:user)
|
||||||
@post = Factory.create(:status_message, :person => @user)
|
@post = Factory.create(:status_message, :person => @user)
|
||||||
end
|
end
|
||||||
|
describe 'serialization' do
|
||||||
it 'should have a post id after serialization' do
|
it 'should have a post id after serialization' do
|
||||||
retraction = Retraction.for(@post)
|
retraction = Retraction.for(@post)
|
||||||
xml = retraction.to_xml.to_s
|
xml = retraction.to_xml.to_s
|
||||||
xml.include?(@post.id.to_s).should == true
|
xml.include?(@post.id.to_s).should == true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
describe 'dispatching' do
|
||||||
it 'should dispatch a message on delete' do
|
it 'should dispatch a message on delete' do
|
||||||
Factory.create(:person)
|
Factory.create(:person)
|
||||||
Post.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
Post.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
||||||
@post.destroy
|
@post.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue