diff --git a/app/models/google_maps.rb b/app/models/google_maps.rb index e2a0b13..3f7fc3e 100644 --- a/app/models/google_maps.rb +++ b/app/models/google_maps.rb @@ -19,8 +19,9 @@ class GoogleMaps domain ? !domain.google_maps_key.nil? : false end - def key(domain) - Domain.find_by_name(domain).google_maps_key || '' + def key(domainname) + domain = Domain.find_by_name(domainname) + domain && domain.google_maps_key || '' end def initial_zoom diff --git a/test/unit/google_maps_test.rb b/test/unit/google_maps_test.rb index 276cced..fb57401 100644 --- a/test/unit/google_maps_test.rb +++ b/test/unit/google_maps_test.rb @@ -44,4 +44,12 @@ class GoogleMapsTest < Test::Unit::TestCase assert_equal 'http://maps.google.com/maps?file=api&v=2&key=DOMAIN_KEY', GoogleMaps.api_url(domain.name) assert_equal 'http://maps.google.com/maps?file=api&v=2&key=DIFFERENT_DOMAIN_KEY', GoogleMaps.api_url(other_domain.name) end + + should 'not crash without a domain' do + Domain.delete_all + assert_nothing_raised do + GoogleMaps.key('example.com') + end + end + end -- libgit2 0.21.2