making a few more cleanup and tests

This commit is contained in:
maxwell 2010-10-24 18:48:45 -07:00
parent 8fe339b03b
commit 9a2e3ef158
3 changed files with 16 additions and 35 deletions

View file

@ -4,7 +4,7 @@ require File.join(Rails.root, 'lib/webfinger_profile')
class EMWebfinger class EMWebfinger
TIMEOUT = 5 TIMEOUT = 5
def initialize(account) def initialize(account)
@account = account @account = account.strip.gsub('acct:','').to_s
@callbacks = [] @callbacks = []
# Raise an error if identifier has a port number # Raise an error if identifier has a port number
raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/)) raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/))
@ -14,9 +14,6 @@ class EMWebfinger
def fetch def fetch
raise 'you need to set a callback before calling fetch' if @callbacks.empty? raise 'you need to set a callback before calling fetch' if @callbacks.empty?
query = /\A^#{Regexp.escape(@account.gsub('acct:', '').to_s)}\z/i
local_person = Person.first(:diaspora_handle => query)
person = Person.by_account_identifier(@account) person = Person.by_account_identifier(@account)
if person if person
process_callbacks person process_callbacks person

View file

@ -28,7 +28,6 @@ describe EMWebfinger do
let(:non_diaspora_hcard) {File.open(File.join(Rails.root, 'spec/fixtures/evan_hcard')).read} let(:non_diaspora_hcard) {File.open(File.join(Rails.root, 'spec/fixtures/evan_hcard')).read}
context 'setup' do context 'setup' do
let(:action){ Proc.new{|person| puts person.inspect }}
describe '#intialize' do describe '#intialize' do
it 'sets account ' do it 'sets account ' do
@ -37,7 +36,16 @@ describe EMWebfinger do
end end
it 'should raise an error on an unresonable email' do it 'should raise an error on an unresonable email' do
proc{EMWebfinger.new("asfadfasdf")}.should raise_error proc{
EMWebfinger.new("joe.valid+email@my-address.com")
}.should_not raise_error(RuntimeError, "Identifier is invalid")
end
it 'should not allow port numbers' do
proc{
EMWebfinger.new('eviljoe@diaspora.local:3000')
}.should raise_error(RuntimeError, "Identifier is invalid")
end end
end end
@ -104,7 +112,6 @@ describe EMWebfinger do
} }
} }
end end
end end
end end
end end

View file

@ -199,7 +199,7 @@ describe Person do
person.should == user1.person person.should == user1.person
end end
it 'should only find people who are exact matches' do it 'should only find people who are exact matches (1/2)' do
user = Factory(:user, :username => "SaMaNtHa") user = Factory(:user, :username => "SaMaNtHa")
person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com") person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com")
user.person.diaspora_handle = "tom@tom.joindiaspora.com" user.person.diaspora_handle = "tom@tom.joindiaspora.com"
@ -207,37 +207,14 @@ describe Person do
Person.by_account_identifier("tom@tom.joindiaspora.com").diaspora_handle.should == "tom@tom.joindiaspora.com" Person.by_account_identifier("tom@tom.joindiaspora.com").diaspora_handle.should == "tom@tom.joindiaspora.com"
end end
it 'should return nil if there is not an exact match' do it 'should only find people who are exact matches (2/2)' do
pending "should check in the webfinger client"
person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com") person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com")
person1 = Factory(:person, :diaspora_handle => "tom@tom.joindiaspora.comm") person1 = Factory(:person, :diaspora_handle => "tom@tom.joindiaspora.comm")
#Person.by_webfinger("tom@tom.joindiaspora.com").should_be false f = Person.by_account_identifier("tom@tom.joindiaspora.com")
proc{ Person.by_webfinger("tom@tom.joindiaspora.com")}.should raise_error f.should be nil
end end
it 'identifier should be a valid email' do
pending "should check in the webfinger client"
stub_success("joe.valid+email@my-address.com")
Proc.new {
Person.by_account_identifier("joe.valid+email@my-address.com")
}.should_not raise_error(RuntimeError, "Identifier is invalid")
stub_success("not_a_@valid_email")
Proc.new {
Person.by_account_identifer("not_a_@valid_email")
}.should raise_error(RuntimeError, "Identifier is invalid")
end
it 'should not accept a port number' do
pending "should check the webfinger client"
stub_success("eviljoe@diaspora.local:3000")
Proc.new {
Person.by_account_identifier('eviljoe@diaspora.local:3000')
}.should raise_error(RuntimeError, "Identifier is invalid")
end
end end
describe '.local_by_account_identifier' do describe '.local_by_account_identifier' do