From 8cf420af67192aecfab090c7b7b3b078e0df80e3 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Mon, 18 Jan 2010 20:08:30 -0300 Subject: [PATCH] Resisting unexisting domains for getting map keys --- app/models/google_maps.rb | 5 +++-- test/unit/google_maps_test.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) 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