google_maps_test.rb
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require File.dirname(__FILE__) + '/../test_helper'
class GoogleMapsTest < Test::Unit::TestCase
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
File.expects(:exists?).with(CONFIG_FILE).returns(true)
YAML.expects(:load_file).with(CONFIG_FILE).returns({'googlemaps' => { 'key' => 'MYKEY' }})
assert_equal 'MYKEY', GoogleMaps.key
end
should 'enable when key is defined' do
File.expects(:exists?).with(CONFIG_FILE).returns(true)
YAML.expects(:load_file).with(CONFIG_FILE).returns({'googlemaps' => { 'key' => 'MYKEY' }})
assert GoogleMaps.enabled?
end
should 'disable if config file not present' do
File.expects(:exists?).with(CONFIG_FILE).returns(false)
assert !GoogleMaps.enabled?
end
should 'disable if key not defined' do
File.expects(:exists?).with(CONFIG_FILE).returns(true)
YAML.expects(:load_file).with(CONFIG_FILE).returns({})
assert !GoogleMaps.enabled?
end
should 'not crash if config not informed' do
File.expects(:exists?).with(CONFIG_FILE).returns(true)
YAML.expects(:load_file).with(CONFIG_FILE).returns({})
assert_nil GoogleMaps.key
end
should 'not crash if config file not found' do
GoogleMaps.expects(:config_file).returns('/not/present.yml')
assert_nil GoogleMaps.key
end
should 'point correctly to google maps' do
GoogleMaps.expects(:key).returns('MY_FUCKING_KEY')
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