Commit 55a5a2a5c88e333ed15c53551cbfa7b405ce0516
Committed by
Antonio Terceiro
1 parent
c00a313f
Exists in
master
and in
29 other branches
Each domain is alowed to have its own GoogleMap key
* Added google_maps_key to domain (ActionItem1341)
Showing
10 changed files
with
90 additions
and
19 deletions
Show diff stats
app/helpers/search_helper.rb
app/models/google_maps.rb
... | ... | @@ -14,20 +14,20 @@ class GoogleMaps |
14 | 14 | @config ||= (web2_conf['googlemaps'] || {}) |
15 | 15 | end |
16 | 16 | |
17 | - def enabled? | |
18 | - !config['key'].nil? | |
17 | + def enabled?(domain) | |
18 | + !Domain.find_by_name(domain).google_maps_key.nil? | |
19 | 19 | end |
20 | 20 | |
21 | - def key | |
22 | - config['key'] || '' | |
21 | + def key(domain) | |
22 | + Domain.find_by_name(domain).google_maps_key || '' | |
23 | 23 | end |
24 | 24 | |
25 | 25 | def initial_zoom |
26 | 26 | config['initial_zoom'] || 4 |
27 | 27 | end |
28 | 28 | |
29 | - def api_url | |
30 | - "http://maps.google.com/maps?file=api&v=2&key=#{key}" | |
29 | + def api_url(domain) | |
30 | + "http://maps.google.com/maps?file=api&v=2&key=#{key(domain)}" | |
31 | 31 | end |
32 | 32 | |
33 | 33 | end | ... | ... |
app/models/location_block.rb
... | ... | @@ -20,7 +20,7 @@ class LocationBlock < Block |
20 | 20 | '<img src="http://maps.google.com/staticmap?center=' + profile.lat.to_s() + |
21 | 21 | ',' + profile.lng.to_s() + '&zoom=' + zoom.to_s() + |
22 | 22 | '&size=205x250&maptype=' + map_type + '&markers=' + profile.lat.to_s() + ',' + |
23 | - profile.lng.to_s() + ',green&key=' + GoogleMaps::key + '&sensor=false"/>', | |
23 | + profile.lng.to_s() + ',green&key=' + GoogleMaps::key(profile.default_hostname) + '&sensor=false"/>', | |
24 | 24 | :class => 'the-localization-map' ) |
25 | 25 | else |
26 | 26 | content_tag('i', _('This profile has no geographical position registered.')) | ... | ... |
app/views/maps/_google_map.rhtml
app/views/search/_google_maps.rhtml
test/functional/maps_controller_test.rb
... | ... | @@ -45,4 +45,13 @@ class MapsControllerTest < Test::Unit::TestCase |
45 | 45 | assert_tag :tag => 'input', :attributes => { :name => 'profile_data[city]' } |
46 | 46 | end |
47 | 47 | |
48 | + should 'add script tag for google maps' do | |
49 | + domain = fast_create(Domain, :name => 'domain-with-key', :google_maps_key => 'DOMAIN_KEY') | |
50 | + profile.preferred_domain = domain | |
51 | + profile.save! | |
52 | + | |
53 | + get 'edit_location', :profile => profile.identifier | |
54 | + | |
55 | + assert_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&v=2&key=DOMAIN_KEY'} | |
56 | + end | |
48 | 57 | end | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -13,6 +13,10 @@ class SearchControllerTest < Test::Unit::TestCase |
13 | 13 | @category = Category.create!(:name => 'my category', :environment => Environment.default) |
14 | 14 | Profile.rebuild_index |
15 | 15 | Article.rebuild_index |
16 | + | |
17 | + domain = Environment.default.domains.first | |
18 | + domain.google_maps_key = 'ENVIRONMENT_KEY' | |
19 | + domain.save! | |
16 | 20 | end |
17 | 21 | |
18 | 22 | def test_local_files_reference |
... | ... | @@ -1001,6 +1005,36 @@ class SearchControllerTest < Test::Unit::TestCase |
1001 | 1005 | assert_includes assigns(:results)[:products], prod |
1002 | 1006 | end |
1003 | 1007 | |
1008 | + should 'add script tag for google maps if searching products' do | |
1009 | + get 'index', :query => 'product', :display => 'map', :find_in => ['products'] | |
1010 | + | |
1011 | + assert_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&v=2&key=ENVIRONMENT_KEY'} | |
1012 | + end | |
1013 | + | |
1014 | + should 'add script tag for google maps if searching enterprises' do | |
1015 | + get 'index', :query => 'enterprise', :display => 'map', :find_in => ['enterprises'] | |
1016 | + | |
1017 | + assert_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&v=2&key=ENVIRONMENT_KEY'} | |
1018 | + end | |
1019 | + | |
1020 | + should 'not add script tag for google maps if searching articles' do | |
1021 | + get 'index', :query => 'article', :display => 'map', :find_in => ['articles'] | |
1022 | + | |
1023 | + assert_no_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&v=2&key=ENVIRONMENT_KEY'} | |
1024 | + end | |
1025 | + | |
1026 | + should 'not add script tag for google maps if searching people' do | |
1027 | + get 'index', :query => 'person', :display => 'map', :find_in => ['people'] | |
1028 | + | |
1029 | + assert_no_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&v=2&key=ENVIRONMENT_KEY'} | |
1030 | + end | |
1031 | + | |
1032 | + should 'not add script tag for google maps if searching communities' do | |
1033 | + get 'index', :query => 'community', :display => 'map', :find_in => ['communities'] | |
1034 | + | |
1035 | + assert_no_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&v=2&key=ENVIRONMENT_KEY'} | |
1036 | + end | |
1037 | + | |
1004 | 1038 | should 'show events of specific day' do |
1005 | 1039 | person = create_user('anotheruser').person |
1006 | 1040 | event = create_event(person, :name => 'Joao Birthday', :start_date => Date.new(2009, 10, 28)) | ... | ... |
test/unit/domain_test.rb
... | ... | @@ -100,4 +100,14 @@ class DomainTest < Test::Unit::TestCase |
100 | 100 | assert_equal false, Domain.hosting_profile_at('example.com') |
101 | 101 | end |
102 | 102 | |
103 | + should 'not crash if key is not defined' do | |
104 | + domain = fast_create(Domain, :name => 'domain-without-key') | |
105 | + assert_nil domain.google_maps_key | |
106 | + end | |
107 | + | |
108 | + should 'return key if defined' do | |
109 | + domain = fast_create(Domain, :name => 'domain-with-key', :google_maps_key => 'DOMAIN_KEY') | |
110 | + assert_equal 'DOMAIN_KEY', domain.google_maps_key | |
111 | + end | |
112 | + | |
103 | 113 | end | ... | ... |
test/unit/google_maps_test.rb
... | ... | @@ -3,28 +3,29 @@ require File.dirname(__FILE__) + '/../test_helper' |
3 | 3 | class GoogleMapsTest < Test::Unit::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | + @domain = fast_create(Domain, :name => 'example-domain', :google_maps_key => 'DOMAIN_KEY') | |
6 | 7 | # force loading of config at every test |
7 | 8 | GoogleMaps.erase_config |
8 | 9 | end |
9 | 10 | |
10 | - should 'enable when key is defined' do | |
11 | - GoogleMaps.stubs(:config).returns({ 'key' => 'MYKEY' }) | |
12 | - assert GoogleMaps.enabled? | |
11 | + attr_reader :domain | |
12 | + | |
13 | + should 'enable when key on domain is defined' do | |
14 | + assert GoogleMaps.enabled?(domain.name) | |
13 | 15 | end |
14 | 16 | |
15 | - should 'disable if key not defined' do | |
16 | - GoogleMaps.stubs(:config).returns({}) | |
17 | - assert !GoogleMaps.enabled? | |
17 | + should 'disable if key on domain is not defined' do | |
18 | + fast_create(Domain, :name => 'domain-without-key') | |
19 | + assert !GoogleMaps.enabled?('domain-without-key') | |
18 | 20 | end |
19 | 21 | |
20 | 22 | should 'not crash if config not informed' do |
21 | 23 | GoogleMaps.stubs(:config).returns({}) |
22 | - assert_equal '', GoogleMaps.key | |
24 | + assert_equal({}, GoogleMaps.config) | |
23 | 25 | end |
24 | 26 | |
25 | 27 | should 'point correctly to google maps' do |
26 | - GoogleMaps.expects(:key).returns('MY_FUCKING_KEY') | |
27 | - assert_equal 'http://maps.google.com/maps?file=api&v=2&key=MY_FUCKING_KEY', GoogleMaps.api_url | |
28 | + assert_equal 'http://maps.google.com/maps?file=api&v=2&key=DOMAIN_KEY', GoogleMaps.api_url(domain.name) | |
28 | 29 | end |
29 | 30 | |
30 | 31 | should 'provide initial_zoom setting' do |
... | ... | @@ -37,4 +38,10 @@ class GoogleMapsTest < Test::Unit::TestCase |
37 | 38 | assert_equal 4, GoogleMaps.initial_zoom |
38 | 39 | end |
39 | 40 | |
41 | + should 'have different keys to different domains' do | |
42 | + other_domain = fast_create(Domain, :name => 'different-domain', :google_maps_key => 'DIFFERENT_DOMAIN_KEY') | |
43 | + | |
44 | + assert_equal 'http://maps.google.com/maps?file=api&v=2&key=DOMAIN_KEY', GoogleMaps.api_url(domain.name) | |
45 | + assert_equal 'http://maps.google.com/maps?file=api&v=2&key=DIFFERENT_DOMAIN_KEY', GoogleMaps.api_url(other_domain.name) | |
46 | + end | |
40 | 47 | end | ... | ... |