From 5ae16c15a314ed85db30ee5d23609cd5b06d8229 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Fri, 24 Dec 2010 13:00:06 -0800 Subject: [PATCH] Fix bug in :pod_uri generation. --- lib/app_config.rb | 3 +++ spec/lib/app_config_spec.rb | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 spec/lib/app_config_spec.rb diff --git a/lib/app_config.rb b/lib/app_config.rb index f890b1845..512f99bd9 100644 --- a/lib/app_config.rb +++ b/lib/app_config.rb @@ -40,6 +40,9 @@ class AppConfig def self.generate_pod_uri require 'uri' + unless self.config_vars[:pod_url] =~ /^(https?:\/\/)/ + self.config_vars[:pod_url] = "http://#{self.config_vars[:pod_url]}" + end begin self.config_vars[:pod_uri] = URI.parse(self.config_vars[:pod_url]) rescue diff --git a/spec/lib/app_config_spec.rb b/spec/lib/app_config_spec.rb new file mode 100644 index 000000000..96ba4d441 --- /dev/null +++ b/spec/lib/app_config_spec.rb @@ -0,0 +1,41 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + +describe AppConfig do + describe ".generate_pod_uri" do + before do + @environment_vars = AppConfig.config_vars + AppConfig.config_vars = {} + end + after do + AppConfig.config_vars = @environment_vars + end + describe "when pod_url is prefixed with protocol" do + it "generates a URI with a host for http" do + AppConfig[:pod_url] = "http://oscar.joindiaspora.com" + AppConfig.generate_pod_uri + AppConfig[:pod_uri].host.should == "oscar.joindiaspora.com" + end + it "generates a URI with a host for https" do + AppConfig[:pod_url] = "https://oscar.joindiaspora.com" + AppConfig.generate_pod_uri + AppConfig[:pod_uri].host.should == "oscar.joindiaspora.com" + end + end + describe "when pod_url is not prefixed with protocol" do + it "generates a URI with a host" do + AppConfig[:pod_url] = "oscar.joindiaspora.com" + AppConfig.generate_pod_uri + AppConfig[:pod_uri].host.should == "oscar.joindiaspora.com" + end + it "adds http:// to the front of the pod_url" do + AppConfig[:pod_url] = "oscar.joindiaspora.com" + AppConfig.generate_pod_uri + AppConfig[:pod_url].should == "http://oscar.joindiaspora.com" + end + end + end +end \ No newline at end of file