Skip to content
Snippets Groups Projects
Commit 3866b83d authored by danielvincent's avatar danielvincent
Browse files

Merge branch 'master' of github.com:diaspora/diaspora

parents 7e9585c5 fce90282
No related branches found
No related tags found
No related merge requests found
......@@ -27,21 +27,12 @@ class Person
timestamps!
before_save :strip_and_downcase_diaspora_handle
before_destroy :remove_all_traces
before_validation :clean_url
validates_presence_of :url, :profile, :serialized_public_key
validates_format_of :url, :with =>
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
def strip_and_downcase_diaspora_handle
if self.diaspora_handle
self.diaspora_handle.strip!
self.diaspora_handle.downcase!
end
end
def self.search(query)
return Person.all if query.to_s.empty?
query_tokens = query.to_s.strip.split(" ")
......@@ -95,12 +86,14 @@ 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)
query = /#{Regexp.escape(identifier.gsub('acct:', '').to_s)}/i
local_person = Person.first(:diaspora_handle => query)
if local_person
Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}")
local_person
elsif !identifier.include?("localhost") && !opts[:local]
#Get remote profile
begin
Rails.logger.info("Webfingering #{identifier}")
f = Redfinger.finger(identifier)
......
......@@ -388,7 +388,7 @@ class User
end
def diaspora_handle
"#{self.username}@#{APP_CONFIG[:terse_pod_url]}".downcase
"#{self.username}@#{APP_CONFIG[:terse_pod_url]}"
end
def as_json(opts={})
......
......@@ -33,7 +33,7 @@ if [ -n "$services" ]; then
fi
# Check if Mongo is running
if ! pgrep mongod >/dev/null
if ! ps ax | grep -v grep | grep mongod >/dev/null
then
echo "Error: Mongod not started. Exiting" >&2
exit 64
......
......@@ -14,11 +14,6 @@ describe Person do
end
describe '#diaspora_handle' do
it 'should downcase and strip the handle before it saves' do
p = Factory.build(:person, :diaspora_handle => " FOOBaR@example.com ")
p.save
p.diaspora_handle.should == "foobar@example.com"
end
context 'local people' do
it 'uses the pod config url to set the diaspora_handle' do
@user.person.diaspora_handle.should == @user.username + "@" + APP_CONFIG[:terse_pod_url]
......@@ -30,14 +25,20 @@ describe Person do
@person.diaspora_handle.include?(APP_CONFIG[:terse_pod_url]).should be false
end
end
end
describe 'validation' do
it 'is unique' do
person_two = Factory.build(:person, :url => @person.diaspora_handle)
person_two.valid?.should be_false
end
it 'should not allow two people with the same diaspora_handle' do
person_two = Factory.build(:person, :url => @person.diaspora_handle)
person_two.valid?.should == false
it 'is case insensitive' do
person_two = Factory.build(:person, :url => @person.diaspora_handle.upcase)
person_two.valid?.should be_false
end
end
end
describe 'xml' do
describe 'xml' do
before do
@xml = @person.to_xml.to_s
end
......@@ -52,7 +53,7 @@ describe Person do
end
end
it 'should know when a post belongs to it' do
it '#owns? posts' do
person_message = Factory.create(:status_message, :person => @person)
person_two = Factory.create(:person)
......@@ -188,6 +189,12 @@ describe Person do
person = Person.by_webfinger(user.person.diaspora_handle)
person.should == user.person
end
it "is case insensitive" do
user = Factory(:user, :username => "SaMaNtHa")
person = Person.by_webfinger(user.person.diaspora_handle.upcase)
person.should == user.person
end
end
it 'creates a stub for a remote user' do
......
......@@ -83,11 +83,6 @@ describe User do
it 'uses the pod config url to set the diaspora_handle' do
user.diaspora_handle.should == user.username + "@" + APP_CONFIG[:terse_pod_url]
end
it 'should be lowercase, even if username is uppercase' do
user.username = "fooBAR"
user.diaspora_handle.should == (user.username + "@" + APP_CONFIG[:terse_pod_url]).downcase
end
end
context 'profiles' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment