diff --git a/app/models/google_maps.rb b/app/models/google_maps.rb index e1f875b..6f4ca90 100644 --- a/app/models/google_maps.rb +++ b/app/models/google_maps.rb @@ -31,6 +31,10 @@ class GoogleMaps config['key'] end + def initial_zoom + config['initial_zoom'] || 4 + end + def api_url "http://maps.google.com/maps?file=api&v=2&key=#{key}" end diff --git a/app/views/search/_google_maps.rhtml b/app/views/search/_google_maps.rhtml index af02c5a..7f253f4 100644 --- a/app/views/search/_google_maps.rhtml +++ b/app/views/search/_google_maps.rhtml @@ -29,7 +29,7 @@ if (GBrowserIsCompatible()) { map.addControl(new GMapTypeControl()); centerPoint = new GLatLng(-15.0, -50.1419); - map.setCenter(centerPoint, 4); + map.setCenter(centerPoint, <%= GoogleMaps.initial_zoom.to_json %>); <% missed = false @results.each do |name,results| diff --git a/test/unit/google_maps_test.rb b/test/unit/google_maps_test.rb index 7324b5c..c58c817 100644 --- a/test/unit/google_maps_test.rb +++ b/test/unit/google_maps_test.rb @@ -2,11 +2,12 @@ require File.dirname(__FILE__) + '/../test_helper' class GoogleMapsTest < Test::Unit::TestCase - CONFIG_FILE = File.join(RAILS_ROOT, 'config', 'web2.0.yml') + CONFIG_FILE = '/not/existing.yml' def setup # force loading of config at every test GoogleMaps.erase_config + GoogleMaps.stubs(:config_file).returns(CONFIG_FILE) end should 'retrieve key from "web2.0" config file' do @@ -48,4 +49,16 @@ class GoogleMapsTest < Test::Unit::TestCase assert_equal 'http://maps.google.com/maps?file=api&v=2&key=MY_FUCKING_KEY', GoogleMaps.api_url end + should 'provide initial_zoom setting' do + File.expects(:exists?).with(CONFIG_FILE).returns(true) + YAML.expects(:load_file).with(CONFIG_FILE).returns({'googlemaps' => { 'initial_zoom' => 2}}) + assert_equal 2, GoogleMaps.initial_zoom + end + + should 'use 4 as default initial_zoom' do + File.expects(:exists?).with(CONFIG_FILE).returns(true) + YAML.expects(:load_file).with(CONFIG_FILE).returns({'googlemaps' => { }}) + assert_equal 4, GoogleMaps.initial_zoom + end + end -- libgit2 0.21.2