Person.by_webfinger preserves case of identifier. Backfill specs for PublicsController#webfinger.

This commit is contained in:
Sarah Mei 2010-10-17 12:18:53 -07:00
parent 50f9e8f240
commit fcdcf88a79
3 changed files with 74 additions and 40 deletions

View file

@ -53,6 +53,7 @@ class Person
def real_name
"#{profile.first_name.to_s} #{profile.last_name.to_s}"
end
def owns?(post)
self.id == post.person.id
end
@ -85,7 +86,7 @@ class Person
def self.by_webfinger(identifier, opts = {})
#need to check if this is a valid email structure, maybe should do in JS
local_person = Person.first(:diaspora_handle => identifier.gsub('acct:', '').to_s.downcase)
local_person = Person.first(:diaspora_handle => identifier.gsub('acct:', '').to_s)
if local_person
Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}")

View file

@ -49,9 +49,28 @@ describe PublicsController do
end
describe 'webfinger' do
it 'should not try to webfinger out on a request to webfinger' do
Redfinger.should_not_receive :finger
post :webfinger, :q => 'remote@example.com'
it "succeeds when the person and user exist locally" do
user = Factory(:user)
post :webfinger, 'q' => user.person.diaspora_handle
response.should be_success
end
it "404s when the person exists remotely because it is local only" do
stub_success('me@mydiaspora.pod.com')
post :webfinger, 'q' => 'me@mydiaspora.pod.com'
response.should be_not_found
end
it "404s when the person is local but doesn't have an owner" do
person = Factory(:person)
post :webfinger, 'q' => person.diaspora_handle
response.should be_not_found
end
it "404s when the person does not exist locally or remotely" do
stub_failure('me@mydiaspora.pod.com')
post :webfinger, 'q' => 'me@mydiaspora.pod.com'
response.should be_not_found
end
end

View file

@ -164,17 +164,31 @@ describe Person do
people = Person.search("Casey Grippi")
people.should == [@friend_four]
end
it 'should search by diaspora_handle exactly' do
stub_success("tom@tom.joindiaspora.com")
Person.by_webfinger(@friend_one.diaspora_handle).should == @friend_one
end
it 'should create a stub for a remote user' do
describe ".by_webfinger" do
context "local people" do
before do
@local_person = Factory(:person)
Redfinger.should_not_receive :finger
end
it "finds the local person without calling out" do
person = Person.by_webfinger(@local_person.diaspora_handle)
person.should == @local_person
end
it "finds a local person with a mixed-case username" do
user = Factory(:user, :username => "SaMaNtHa")
person = Person.by_webfinger(user.person.diaspora_handle)
person.should == user.person
end
end
it 'creates a stub for a remote user' do
stub_success("tom@tom.joindiaspora.com")
tom = Person.by_webfinger('tom@tom.joindiaspora.com')
tom.real_name.include?("Hamiltom").should be true
end
end
end