fix @pod_uri/@pod_url and add url_to to AppConfig
This commit is contained in:
parent
8bf54e32ae
commit
804784ed3f
3 changed files with 33 additions and 10 deletions
|
|
@ -9,8 +9,8 @@ DiasporaFederation.configure do |config|
|
|||
if person
|
||||
DiasporaFederation::WebFinger::WebFinger.new(
|
||||
acct_uri: "acct:#{person.diaspora_handle}",
|
||||
alias_url: url_to("/people/#{person.guid}"),
|
||||
hcard_url: url_to(DiasporaFederation::Engine.routes.url_helpers.hcard_path(person.guid)),
|
||||
alias_url: AppConfig.url_to("/people/#{person.guid}"),
|
||||
hcard_url: AppConfig.url_to(DiasporaFederation::Engine.routes.url_helpers.hcard_path(person.guid)),
|
||||
seed_url: AppConfig.pod_uri,
|
||||
profile_url: person.profile_url,
|
||||
atom_url: person.atom_url,
|
||||
|
|
@ -40,8 +40,4 @@ DiasporaFederation.configure do |config|
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def url_to(path)
|
||||
AppConfig.pod_uri.tap {|uri| uri.path = path }.to_s
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,19 +3,25 @@ module Configuration
|
|||
|
||||
module Methods
|
||||
def pod_uri
|
||||
return @pod_uri unless @pod_uri.nil?
|
||||
return @pod_uri.dup unless @pod_uri.nil?
|
||||
|
||||
url = environment.url.get
|
||||
url = "http://#{url}" unless url =~ /^(https?:\/\/)/
|
||||
url << "/" unless url.end_with?("/")
|
||||
|
||||
begin
|
||||
@pod_url = Addressable::URI.parse(url)
|
||||
@pod_uri = Addressable::URI.parse(url)
|
||||
rescue
|
||||
puts "WARNING: pod url #{url} is not a legal URI"
|
||||
end
|
||||
|
||||
@pod_url
|
||||
@pod_uri.dup
|
||||
end
|
||||
|
||||
# @param path [String]
|
||||
# @return [String]
|
||||
def url_to(path)
|
||||
pod_uri.tap {|uri| uri.path = path }.to_s
|
||||
end
|
||||
|
||||
def bare_pod_uri
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ describe Configuration::Methods do
|
|||
expect(@settings.pod_uri.host).to eq("example.org")
|
||||
end
|
||||
|
||||
it "adds a trailing slash if there isn't one" do
|
||||
it "adds a trailing slash if there isn't one" do
|
||||
@settings.environment.url = "http://example.org"
|
||||
expect(@settings.pod_uri.to_s).to eq("http://example.org/")
|
||||
end
|
||||
|
|
@ -40,6 +40,12 @@ describe Configuration::Methods do
|
|||
@settings.environment.url = "https://example.org/"
|
||||
expect(@settings.pod_uri.to_s).to eq("https://example.org/")
|
||||
end
|
||||
|
||||
it "returns another instance everytime" do
|
||||
@settings.environment.url = "https://example.org/"
|
||||
uri = @settings.pod_uri
|
||||
expect(@settings.pod_uri).not_to be(uri)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#bare_pod_uri" do
|
||||
|
|
@ -51,6 +57,21 @@ describe Configuration::Methods do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#url_to" do
|
||||
before do
|
||||
@settings.environment.url = "https://example.org"
|
||||
@settings.instance_variable_set(:@pod_uri, nil)
|
||||
end
|
||||
|
||||
it "appends the path to the pod url" do
|
||||
expect(@settings.url_to("/any/path")).to eq("https://example.org/any/path")
|
||||
end
|
||||
|
||||
it "does not add double slash" do
|
||||
expect(@settings.url_to("/any/path")).to eq("https://example.org/any/path")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#configured_services" do
|
||||
it "includes the enabled services only" do
|
||||
services = double
|
||||
|
|
|
|||
Loading…
Reference in a new issue