tests are green

This commit is contained in:
maxwell 2010-10-29 10:44:37 -07:00
parent 7c32649df4
commit 39f66cc5d9
3 changed files with 24 additions and 6 deletions

View file

@ -27,11 +27,19 @@ class EMWebfinger
end
private
def get_xrd
http = EventMachine::HttpRequest.new(xrd_url).get :timeout => TIMEOUT
http.callback {
get_webfinger_profile(webfinger_profile_url(http.response)) }
http.errback { process_callbacks "there was an error getting the xrd at #{xrd_url}" }
profile_url = webfinger_profile_url(http.response)
if profile_url
get_webfinger_profile(profile_url)
else
process_callbacks "webfinger does not seem to be enabled for #{@account}"
end
}
http.errback { process_callbacks "there was an error getting the xrd from account#{@account}" }
end
@ -73,6 +81,7 @@ class EMWebfinger
def webfinger_profile_url(xrd_response)
doc = Nokogiri::XML::Document.parse(xrd_response)
return nil if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0"
swizzle doc.at('Link[rel=lrdd]').attribute('template').value
end

View file

@ -38,7 +38,7 @@ describe EMWebfinger do
it 'should raise an error on an unresonable email' do
proc{
EMWebfinger.new("joe.valid+email@my-address.com")
EMWebfinger.new("joe.valid.email@my-address.com")
}.should_not raise_error(RuntimeError, "Identifier is invalid")
end
@ -62,14 +62,14 @@ describe EMWebfinger do
it 'should not blow up if the returned xrd is nil' do
http = FakeHttpRequest.new(:success)
fake_account = 'foo@example.com'
http.callbacks = ['']
EventMachine::HttpRequest.should_receive(:new).and_return(http)
n = EMWebfinger.new("foo@example.com")
n.on_person{|person|
person = "sad"
person.should == "webfinger does not seem to be enabled for #{fake_account}"
}
end
end
end
@ -85,6 +85,14 @@ describe EMWebfinger do
it 'should parse out the webfinger template' do
finger.send(:webfinger_profile_url, diaspora_xrd).should == "http://tom.joindiaspora.com/webfinger/?q=#{account}"
end
it 'should return nil if not an xrd' do
finger.send(:webfinger_profile_url, '<html></html>').should be nil
end
it 'should return the template for xrd' do
finger.send(:webfinger_profile_url, diaspora_xrd).should == 'http://tom.joindiaspora.com/webfinger/?q=foo@tom.joindiaspora.com'
end
end
describe '#xrd_url' do

View file

@ -123,7 +123,8 @@ describe User do
remote_person.delete
user3.delete
Person.should_receive(:by_webfinger).twice.and_return{ |handle| if handle == user.person.diaspora_handle; user.person.save
#stubs async webfinger
Person.should_receive(:by_account_identifier).twice.and_return{ |handle| if handle == user.person.diaspora_handle; user.person.save
user.person; else; remote_person.save; remote_person; end }