fix @pod_uri/@pod_url and add url_to to AppConfig
This commit is contained in:
parent
0fca8ceeaf
commit
94fc378eb7
3 changed files with 33 additions and 10 deletions
|
|
@ -9,8 +9,8 @@ DiasporaFederation.configure do |config|
|
||||||
if person
|
if person
|
||||||
DiasporaFederation::WebFinger::WebFinger.new(
|
DiasporaFederation::WebFinger::WebFinger.new(
|
||||||
acct_uri: "acct:#{person.diaspora_handle}",
|
acct_uri: "acct:#{person.diaspora_handle}",
|
||||||
alias_url: url_to("/people/#{person.guid}"),
|
alias_url: AppConfig.url_to("/people/#{person.guid}"),
|
||||||
hcard_url: url_to(DiasporaFederation::Engine.routes.url_helpers.hcard_path(person.guid)),
|
hcard_url: AppConfig.url_to(DiasporaFederation::Engine.routes.url_helpers.hcard_path(person.guid)),
|
||||||
seed_url: AppConfig.pod_uri,
|
seed_url: AppConfig.pod_uri,
|
||||||
profile_url: person.profile_url,
|
profile_url: person.profile_url,
|
||||||
atom_url: person.atom_url,
|
atom_url: person.atom_url,
|
||||||
|
|
@ -40,8 +40,4 @@ DiasporaFederation.configure do |config|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def url_to(path)
|
|
||||||
AppConfig.pod_uri.tap {|uri| uri.path = path }.to_s
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,25 @@ module Configuration
|
||||||
|
|
||||||
module Methods
|
module Methods
|
||||||
def pod_uri
|
def pod_uri
|
||||||
return @pod_uri unless @pod_uri.nil?
|
return @pod_uri.dup unless @pod_uri.nil?
|
||||||
|
|
||||||
url = environment.url.get
|
url = environment.url.get
|
||||||
url = "http://#{url}" unless url =~ /^(https?:\/\/)/
|
url = "http://#{url}" unless url =~ /^(https?:\/\/)/
|
||||||
url << "/" unless url.end_with?("/")
|
url << "/" unless url.end_with?("/")
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@pod_url = Addressable::URI.parse(url)
|
@pod_uri = Addressable::URI.parse(url)
|
||||||
rescue
|
rescue
|
||||||
puts "WARNING: pod url #{url} is not a legal URI"
|
puts "WARNING: pod url #{url} is not a legal URI"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def bare_pod_uri
|
def bare_pod_uri
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ describe Configuration::Methods do
|
||||||
expect(@settings.pod_uri.host).to eq("example.org")
|
expect(@settings.pod_uri.host).to eq("example.org")
|
||||||
end
|
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"
|
@settings.environment.url = "http://example.org"
|
||||||
expect(@settings.pod_uri.to_s).to eq("http://example.org/")
|
expect(@settings.pod_uri.to_s).to eq("http://example.org/")
|
||||||
end
|
end
|
||||||
|
|
@ -40,6 +40,12 @@ describe Configuration::Methods do
|
||||||
@settings.environment.url = "https://example.org/"
|
@settings.environment.url = "https://example.org/"
|
||||||
expect(@settings.pod_uri.to_s).to eq("https://example.org/")
|
expect(@settings.pod_uri.to_s).to eq("https://example.org/")
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "#bare_pod_uri" do
|
describe "#bare_pod_uri" do
|
||||||
|
|
@ -51,6 +57,21 @@ describe Configuration::Methods do
|
||||||
end
|
end
|
||||||
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
|
describe "#configured_services" do
|
||||||
it "includes the enabled services only" do
|
it "includes the enabled services only" do
|
||||||
services = double
|
services = double
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue