diff options
author | Henare Degan <henare.degan@gmail.com> | 2012-02-16 17:10:09 +1100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2012-03-13 13:55:46 +0000 |
commit | 53b128aafadd0c134feac82aa0de36378c752bf7 (patch) | |
tree | f4cc66af44b8dda5cd19ee18999d49b7912d190c | |
parent | 3a982b1233d6809a6e9e62840921395e2b0a4840 (diff) |
Make public authority home page links work. Fixes #271
-rw-r--r-- | app/models/public_body.rb | 7 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 6 |
2 files changed, 12 insertions, 1 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 961fa3cbb..23f71333d 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -284,7 +284,12 @@ class PublicBody < ActiveRecord::Base def calculated_home_page # manual override for ones we calculate wrongly if self.home_page != '' - return self.home_page + # Add standard URL prefix + if home_page[0..10] == 'http://www.' + return self.home_page + else + return "http://www.#{self.home_page}" + end end # extract the domain name from the FOI request email diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 17d877b68..142735cb0 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -421,5 +421,11 @@ describe PublicBody do public_body.stub!(:request_email_domain).and_return nil public_body.calculated_home_page.should be_nil end + + it "should ensure home page URLs start with http://" do + public_body = PublicBody.new + public_body.home_page = "example.com" + public_body.calculated_home_page.should == "http://www.example.com" + end end end |