aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenare Degan <henare.degan@gmail.com>2012-02-17 16:08:22 +1100
committerSeb Bacon <seb.bacon@gmail.com>2012-03-13 13:55:46 +0000
commit228c6ab9387909613c215f3bcca833be5ce58b0b (patch)
tree11abcd1580af0ea2840bb4ded5947ee2ec911dcd
parent25e97c043e2ffd222c935210eb91339db13c8e68 (diff)
Don't add http when https is present
-rw-r--r--app/models/public_body.rb2
-rw-r--r--spec/models/public_body_spec.rb6
2 files changed, 7 insertions, 1 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 74c079eaa..a18af8c69 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -283,7 +283,7 @@ class PublicBody < ActiveRecord::Base
# if not known.
def calculated_home_page
if home_page && !home_page.empty?
- home_page[0..6] == 'http://' ? home_page : "http://#{home_page}"
+ home_page[URI::regexp(%w(http https))] ? home_page : "http://#{home_page}"
elsif request_email_domain
"http://www.#{request_email_domain}"
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 9b8c78010..e30916dff 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -427,5 +427,11 @@ describe PublicBody do
public_body.home_page = "example.com"
public_body.calculated_home_page.should == "http://example.com"
end
+
+ it "should not add http when https is present" do
+ public_body = PublicBody.new
+ public_body.home_page = "https://example.com"
+ public_body.calculated_home_page.should == "https://example.com"
+ end
end
end