Navigation Menu

Skip to content

Commit

Permalink
Fix local_contact_importer error with nil URLs
Browse files Browse the repository at this point in the history
This was blowing up if the CSV didn't contain a URL entry for a
particular authority.
  • Loading branch information
alext committed Feb 9, 2015
1 parent 3e1c54e commit ded7397
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/local_contact_importer.rb
Expand Up @@ -18,7 +18,7 @@ def process_row(row)
authority.contact_address = parse_address(row)
authority.contact_phone = decode_broken_entities( row['Telephone Number 1'] )
url = row['Contact page URL']
unless url.start_with?("http://") || url.start_with?("https://")
unless url.blank? || url.start_with?("http://") || url.start_with?("https://")
url = "http://" + url
end
authority.contact_url = url
Expand Down
16 changes: 16 additions & 0 deletions test/unit/local_contact_importer_test.rb
Expand Up @@ -133,5 +133,21 @@ def fixture_file(file)
auth.reload
assert_equal "http://www.southsomerset.gov.uk", auth.contact_url
end

should "handle missing contact URLs" do
source=StringIO.new(<<-END)
Name,Home page URL,Contact page URL,SNAC Code,Address Line 1,Address Line 2,Town,City,County,Postcode,Telephone Number 1 Description,Telephone Number 1,Telephone Number 2 Description,Telephone Number 2,Telephone Number 3 Description,Telephone Number 3,Fax,Main Contact Email,Opening Hours
South Somerset District Council,,,40UD,Council Offices,Brympton Way,Yeovil,,Somerset,BA20 2HT,,01935 462 462,,,,,,,
END

auth = FactoryGirl.create(:local_authority, :snac => "40UD")
# Call process_row directly to bypass the top-level error rescue
importer = LocalContactImporter.new(nil)
csv = CSV.new(source, :headers => true)
importer.send(:process_row, csv.shift)

auth.reload
assert_equal nil, auth.contact_url
end
end
end

0 comments on commit ded7397

Please sign in to comment.