mirror of
https://github.com/diaspora/diaspora.git
synced 2026-01-08 22:58:08 -05:00
Person.find_or_fetch_by_identifier never return nil
Person.find_or_fetch_by_identifier raises an exception if person is not found localy and not fetchable. It never returns nil. These code changes take care about this behaviour and changes specs and code to behave equally. Also related to #8253
This commit is contained in:
committed by
Benjamin Neff
parent
20a3abd864
commit
8691e650dc
@@ -442,8 +442,13 @@ class User < ApplicationRecord
|
||||
aq = self.aspects.create(:name => I18n.t('aspects.seed.acquaintances'))
|
||||
|
||||
if AppConfig.settings.autofollow_on_join?
|
||||
default_account = Person.find_or_fetch_by_identifier(AppConfig.settings.autofollow_on_join_user)
|
||||
self.share_with(default_account, aq) if default_account
|
||||
begin
|
||||
default_account = Person.find_or_fetch_by_identifier(AppConfig.settings.autofollow_on_join_user)
|
||||
share_with(default_account, aq)
|
||||
rescue DiasporaFederation::Discovery::DiscoveryError
|
||||
logger.warn "Error auto-sharing with #{AppConfig.settings.autofollow_on_join_user}
|
||||
fix autofollow_on_join_user in configuration."
|
||||
end
|
||||
end
|
||||
aq
|
||||
end
|
||||
|
||||
@@ -12,7 +12,9 @@ module Workers
|
||||
person = Person.find_or_fetch_by_identifier(account)
|
||||
|
||||
# also, schedule to fetch a few public posts from that person
|
||||
Diaspora::Fetcher::Public.queue_for(person) unless person.nil?
|
||||
Diaspora::Fetcher::Public.queue_for(person)
|
||||
rescue DiasporaFederation::Discovery::DiscoveryError
|
||||
# Ignored
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -811,10 +811,10 @@ describe User, :type => :model do
|
||||
context "with autofollow sharing enabled" do
|
||||
it "should start sharing with autofollow account" do
|
||||
AppConfig.settings.autofollow_on_join = true
|
||||
AppConfig.settings.autofollow_on_join_user = "one"
|
||||
|
||||
expect(Person).to receive(:find_or_fetch_by_identifier).with("one")
|
||||
person = FactoryBot.build(:person)
|
||||
AppConfig.settings.autofollow_on_join_user = person.diaspora_handle
|
||||
|
||||
expect(Person).to receive(:find_or_fetch_by_identifier).with(person.diaspora_handle).and_return(person)
|
||||
user.seed_aspects
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ describe Workers::FetchWebfinger do
|
||||
end
|
||||
|
||||
it "should webfinger and queue no job to fetch public posts if the person is not found" do
|
||||
allow(Person).to receive(:find_or_fetch_by_identifier).and_return(nil)
|
||||
allow(Person).to receive(:find_or_fetch_by_identifier).and_raise DiasporaFederation::Discovery::DiscoveryError
|
||||
|
||||
expect(Diaspora::Fetcher::Public).not_to receive(:queue_for)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user