fetch unknown persons to generate url
This commit is contained in:
parent
09908a45fb
commit
3bfc4003fb
3 changed files with 27 additions and 7 deletions
|
|
@ -215,6 +215,12 @@ class Person < ActiveRecord::Base
|
|||
url_to "/receive/users/#{guid}"
|
||||
end
|
||||
|
||||
# @param path [String]
|
||||
# @return [String]
|
||||
def url_to(path)
|
||||
local? ? AppConfig.url_to(path) : pod.url_to(path)
|
||||
end
|
||||
|
||||
def public_key_hash
|
||||
Base64.encode64(OpenSSL::Digest::SHA256.new(serialized_public_key).to_s)
|
||||
end
|
||||
|
|
@ -286,12 +292,6 @@ class Person < ActiveRecord::Base
|
|||
|
||||
private
|
||||
|
||||
# @param path [String]
|
||||
# @return [String]
|
||||
def url_to(path)
|
||||
local? ? AppConfig.url_to(path) : pod.url_to(path)
|
||||
end
|
||||
|
||||
def fix_profile
|
||||
logger.info "fix profile for account: #{diaspora_handle}"
|
||||
DiasporaFederation::Discovery::Discovery.new(diaspora_handle).fetch_and_save
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ DiasporaFederation.configure do |config|
|
|||
end
|
||||
|
||||
on :fetch_person_url_to do |diaspora_id, path|
|
||||
Pod.joins(:people).find_by(people: {diaspora_handle: diaspora_id}).url_to(path)
|
||||
Person.find_or_fetch_by_identifier(diaspora_id).url_to(path)
|
||||
end
|
||||
|
||||
on :update_pod do |url, status|
|
||||
|
|
|
|||
|
|
@ -428,6 +428,26 @@ describe "diaspora federation callbacks" do
|
|||
DiasporaFederation.callbacks.trigger(:fetch_person_url_to, person.diaspora_handle, "/path/on/pod")
|
||||
).to eq("https://#{pod.host}/path/on/pod")
|
||||
end
|
||||
|
||||
it "fetches an unknown user" do
|
||||
pod = FactoryGirl.build(:pod)
|
||||
person = FactoryGirl.build(:person, pod: pod)
|
||||
expect(Person).to receive(:find_or_fetch_by_identifier).with(person.diaspora_handle).and_return(person)
|
||||
|
||||
expect(
|
||||
DiasporaFederation.callbacks.trigger(:fetch_person_url_to, person.diaspora_handle, "/path/on/pod")
|
||||
).to eq("https://#{pod.host}/path/on/pod")
|
||||
end
|
||||
|
||||
it "forwards the DiscoveryError" do
|
||||
diaspora_id = FactoryGirl.generate(:diaspora_id)
|
||||
expect(Person).to receive(:find_or_fetch_by_identifier).with(diaspora_id)
|
||||
.and_raise(DiasporaFederation::Discovery::DiscoveryError)
|
||||
|
||||
expect {
|
||||
DiasporaFederation.callbacks.trigger(:fetch_person_url_to, diaspora_id, "/path/on/pod")
|
||||
}.to raise_error DiasporaFederation::Discovery::DiscoveryError
|
||||
end
|
||||
end
|
||||
|
||||
describe ":update_pod" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue