google_static_maps_helper 1.3.5 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.3.5
@@ -1,62 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
-
4
- describe GoogleStaticMapsHelper do
5
- describe "Friendly DSL API" do
6
- describe "url_for" do
7
- before do
8
- GoogleStaticMapsHelper.size = '300x500'
9
- GoogleStaticMapsHelper.sensor = false
10
- end
11
-
12
- it "should have a responding method" do
13
- GoogleStaticMapsHelper.respond_to?(:url_for).should be_true
14
- end
15
-
16
- it "should be possible to add markers to map through a b block" do
17
- out = GoogleStaticMapsHelper.url_for do
18
- marker :lat => 1, :lng => 2
19
- end
20
-
21
- out.should include('markers=color:red|size:mid|1,2')
22
- end
23
-
24
- it "should be possible to override the default map construction values" do
25
- out = GoogleStaticMapsHelper.url_for(:size => '600x400') do
26
- marker :lat => 1, :lng => 2
27
- end
28
-
29
- out.should include('size=600x400')
30
- end
31
-
32
- it "should be able to add paths" do
33
- point = {:lat => 1, :lng => 2}
34
- point2 = {:lat => 3, :lng => 4}
35
-
36
- out = GoogleStaticMapsHelper.url_for do
37
- path point, point2, :color => :red, :encode_points => false
38
- end
39
-
40
- out.should include('path=color:red|1,2|3,4')
41
- end
42
-
43
- it "should be possible to use inside a class, using attributes of that class" do
44
- class TestingClass
45
- attr_reader :location
46
-
47
- def initialize
48
- @location = {:lat => 1, :lng => 5}
49
- end
50
-
51
- def url
52
- GoogleStaticMapsHelper.url_for do |map|
53
- map.marker location
54
- end
55
- end
56
- end
57
-
58
- TestingClass.new.url.should include('markers=color:red|size:mid|1,5')
59
- end
60
- end
61
- end
62
- end
@@ -1,142 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
-
4
- describe GoogleStaticMapsHelper::Location do
5
- before :each do
6
- @location_hash = {:lat => 10, :lng => 20}
7
- @location_object = mock(:location, @location_hash)
8
- end
9
-
10
- describe "initialize" do
11
- it "should raise ArgumentError if no arguments are given" do
12
- lambda {GoogleStaticMapsHelper::Location.new}.should raise_error(ArgumentError)
13
- end
14
-
15
- describe "get location as object" do
16
- [:lat, :lng].each do |location_property|
17
- it "should extract #{location_property} from first argument if that is object" do
18
- marker = GoogleStaticMapsHelper::Location.new(@location_object)
19
- marker.send(location_property).should == @location_object.send(location_property)
20
- end
21
- end
22
-
23
- it "should raise NoLngMethod if object doesn't respond to lng" do
24
- lambda {GoogleStaticMapsHelper::Location.new(mock(:location, :lat => 10))}.should raise_error(GoogleStaticMapsHelper::Location::NoLngMethod)
25
- end
26
-
27
- it "should raise NoLatMethod if object doesn't respond to lat" do
28
- lambda {GoogleStaticMapsHelper::Location.new(mock(:location, :lng => 20))}.should raise_error(GoogleStaticMapsHelper::Location::NoLatMethod)
29
- end
30
- end
31
-
32
- describe "get location from hash" do
33
- [:lat, :lng].each do |location_property|
34
- it "should extract #{location_property} from hash" do
35
- marker = GoogleStaticMapsHelper::Location.new(@location_hash)
36
- marker.send(location_property).should == @location_object.send(location_property)
37
- end
38
- end
39
-
40
- it "should raise NoLngKey if hash doesn't have key lng" do
41
- lambda {GoogleStaticMapsHelper::Location.new(:lat => 10)}.should raise_error(GoogleStaticMapsHelper::Location::NoLngKey)
42
- end
43
-
44
- it "should raise NoLatKey if hash doesn't have key lat" do
45
- lambda {GoogleStaticMapsHelper::Location.new(:lng => 20)}.should raise_error(GoogleStaticMapsHelper::Location::NoLatKey)
46
- end
47
- end
48
- end
49
-
50
- it "should return to_url with its lat and lng value" do
51
- GoogleStaticMapsHelper::Location.new(@location_hash).to_url.should == '10,20'
52
- end
53
-
54
- describe "reduce and round off lng and lat" do
55
- before do
56
- @location = GoogleStaticMapsHelper::Location.new(:lng => 0, :lat => 1)
57
- end
58
-
59
- [:lng, :lat].each do |attribute|
60
- it "should not round #{attribute} when it is a number with a precision less than 6" do
61
- @location.send("#{attribute}=", 12.000014)
62
- @location.send(attribute).should == 12.000014
63
- end
64
-
65
- it "should round #{attribute} when it is a number with a precision above 6" do
66
- @location.send("#{attribute}=", 12.0000051)
67
- @location.send(attribute).should == 12.000005
68
- end
69
-
70
- it "should round and reduce #{attribute} when it's value is a float which can be represented with a descrete value" do
71
- @location.send("#{attribute}=", 12.00000000001)
72
- @location.send(attribute).to_s.should == "12"
73
- end
74
- end
75
- end
76
-
77
- describe "helper methods" do
78
- [
79
- [{:lat => 60, :lng => 0}, 0],
80
- [{:lat => 60, :lng => 1}, 55597],
81
- [{:lat => 61, :lng => 0}, 111195],
82
- [{:lat => 60, :lng => 0.01}, 556]
83
- ].each do |point_distance|
84
- it "should calculate correct distance to another location" do
85
- another_point, expected_distance = point_distance
86
- base = GoogleStaticMapsHelper::Location.new(:lat => 60, :lng => 0)
87
- another_point = GoogleStaticMapsHelper::Location.new(another_point)
88
- base.distance_to(another_point).should == expected_distance
89
- end
90
- end
91
-
92
-
93
- [
94
- [1000, 360, {:lat => 59.841958, :lng => 10.439303}],
95
- [1000, 324, {:lat => 59.84024, :lng => 10.428782}],
96
- [1000, 114, {:lat => 59.829306, :lng=> 10.45565}],
97
- [1000, 18, {:lat => 59.841518, :lng => 10.444835}]
98
- ].each do |distance_heading_new_point|
99
- it "should calculate new end point with given distance and heading" do
100
- distance, heading, excpexted_point = distance_heading_new_point
101
- base = GoogleStaticMapsHelper::Location.new(:lat => 59.832964751405214, :lng => 10.439303436108082)
102
- new_point = base.endpoint(distance, heading)
103
-
104
- new_point.lat.should == excpexted_point[:lat]
105
- new_point.lng.should == excpexted_point[:lng]
106
- end
107
- end
108
-
109
- describe "endpoints_for_circle_with_radius" do
110
- it "should 30 + 1 end points for circle as default" do
111
- base = GoogleStaticMapsHelper::Location.new(:lat => 59.832964751405214, :lng => 10.439303436108082)
112
- endpoints = base.endpoints_for_circle_with_radius(1000)
113
- endpoints.length.should == 31
114
- end
115
-
116
- it "should have the same point as start and end (to make a closed circle)" do
117
- base = GoogleStaticMapsHelper::Location.new(:lat => 59.832964751405214, :lng => 10.439303436108082)
118
- endpoints = base.endpoints_for_circle_with_radius(1000)
119
- endpoints.first.should == endpoints.last
120
- end
121
-
122
- it "should reley on endpoint method to calculate new endpoints when creating circle points" do
123
- base = GoogleStaticMapsHelper::Location.new(:lat => 59.832964751405214, :lng => 10.439303436108082)
124
- base.should_receive(:endpoint).with(1000, 0 * 360 / 4)
125
- base.should_receive(:endpoint).with(1000, 1 * 360 / 4)
126
- base.should_receive(:endpoint).with(1000, 2 * 360 / 4)
127
- base.should_receive(:endpoint).with(1000, 3 * 360 / 4)
128
- endpoints = base.endpoints_for_circle_with_radius(1000, 4)
129
- end
130
-
131
- it "should raise argument error if number of points asked to returned when creating a circle is above 360" do
132
- base = GoogleStaticMapsHelper::Location.new(:lat => 59, :lng => 10)
133
- lambda {base.endpoints_for_circle_with_radius(1000, 361)}.should raise_error(ArgumentError)
134
- end
135
-
136
- it "should raise argument error if number of points asked to returned when creating a circle is less than 1" do
137
- base = GoogleStaticMapsHelper::Location.new(:lat => 59, :lng => 10)
138
- lambda {base.endpoints_for_circle_with_radius(1000, 0)}.should raise_error(ArgumentError)
139
- end
140
- end
141
- end
142
- end
data/spec/map_spec.rb DELETED
@@ -1,406 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
-
4
- describe GoogleStaticMapsHelper::Map do
5
- reguire_options = {
6
- :size => '600x400',
7
- :sensor => false
8
- }
9
-
10
- describe "initialize" do
11
- before do
12
- reguire_options.each_key {|k| GoogleStaticMapsHelper.send("#{k}=", nil)}
13
- end
14
-
15
- reguire_options.each_key do |key|
16
- it "should raise OptionMissing if #{key} is not given" do
17
- option_with_missing_option = reguire_options.dup
18
- option_with_missing_option.delete(key)
19
- lambda {GoogleStaticMapsHelper::Map.new(option_with_missing_option)}.should raise_error(GoogleStaticMapsHelper::OptionMissing)
20
- end
21
- end
22
-
23
- it "should raise OptionNotExist if incomming option doesn't exists" do
24
- lambda {GoogleStaticMapsHelper::Map.new(reguire_options.merge(:invalid_option => 'error?'))}.should raise_error(GoogleStaticMapsHelper::OptionNotExist)
25
- end
26
-
27
- it "should be able to read initialized key option from object" do
28
- GoogleStaticMapsHelper::Map.new(reguire_options).key.should == reguire_options[:key]
29
- end
30
-
31
- reguire_options.each_key do |key|
32
- it "should use #{key} from GoogleStaticMapsHelper class attribute if set" do
33
- option_with_missing_option = reguire_options.dup
34
- GoogleStaticMapsHelper.send("#{key}=", option_with_missing_option.delete(key))
35
- map = GoogleStaticMapsHelper::Map.new(option_with_missing_option)
36
- map.send(key).should == GoogleStaticMapsHelper.send(key)
37
- end
38
- end
39
-
40
- it "should be able to call new with no arguments if GoogleStaticMapsHelper class attributes are set" do
41
- reguire_options.each_pair {|key, value| GoogleStaticMapsHelper.send("#{key}=", value)}
42
- lambda {GoogleStaticMapsHelper::Map.new}.should_not raise_error
43
- end
44
- end
45
-
46
- describe "markers" do
47
- before :each do
48
- @marker = GoogleStaticMapsHelper::Marker.new(:lat => 1, :lng => 2)
49
- @map = GoogleStaticMapsHelper::Map.new(reguire_options)
50
- end
51
-
52
- it "should be empty as default" do
53
- @map.should be_empty
54
- end
55
-
56
- it "should be able to push markers onto map" do
57
- @map << @marker
58
- end
59
-
60
- it "should not be possible to push the same marker twice" do
61
- @map << @marker
62
- @map << @marker
63
- @map.length.should == 1
64
- end
65
-
66
- it "should be able to push map << marker << marker" do
67
- @map << @marker << GoogleStaticMapsHelper::Marker.new(:lat => 3, :lng => 5)
68
- @map.length.should == 2
69
- end
70
-
71
- it "should return it's markers via markers" do
72
- @map << @marker
73
- @map << GoogleStaticMapsHelper::Path.new
74
- @map.markers.should == [@marker]
75
- end
76
- end
77
-
78
-
79
- describe "Grouped markers" do
80
- before :each do
81
- @marker1 = GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2)
82
- @marker11 = GoogleStaticMapsHelper::Marker.new(:lng => 3, :lat => 4)
83
-
84
- @marker2 = GoogleStaticMapsHelper::Marker.new(:lng => 5, :lat => 6, :color => 'green')
85
- @marker22 = GoogleStaticMapsHelper::Marker.new(:lng => 7, :lat => 8, :color => 'green')
86
- @map = GoogleStaticMapsHelper::Map.new(:size => @size, :sensor => @sensor)
87
- end
88
-
89
- it "should return options_to_url_params as key, array with markers as value" do
90
- @map << @marker1
91
- @map << @marker11
92
- @map << @marker2
93
- @map << @marker22
94
- @map.grouped_markers.should == {
95
- @marker1.options_to_url_params => [@marker1, @marker11],
96
- @marker2.options_to_url_params => [@marker2, @marker22]
97
- }
98
- end
99
- end
100
-
101
- describe "paths" do
102
- before do
103
- @path = GoogleStaticMapsHelper::Path.new
104
- @point = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
105
- @point2 = GoogleStaticMapsHelper::Location.new(:lat => 3, :lng => 4)
106
- @path << @point << @point2
107
-
108
- @map = GoogleStaticMapsHelper::Map.new(reguire_options)
109
- end
110
-
111
- it "should be able to push paths on to map" do
112
- @map << @path
113
- @map.first.should == @path
114
- end
115
-
116
- it "should be able to paths via paths" do
117
- @marker = GoogleStaticMapsHelper::Marker.new(:lat => 1, :lng => 2)
118
- @map << @path
119
- @map << @marker
120
- @map.paths.should == [@path]
121
- end
122
- end
123
-
124
-
125
- describe "size" do
126
- before do
127
- @map = GoogleStaticMapsHelper::Map.new(reguire_options)
128
- @map.size = '300x400'
129
- end
130
-
131
- it "should return map's width" do
132
- @map.width.should == 300
133
- end
134
-
135
- it "should return map's height" do
136
- @map.height.should == 400
137
- end
138
-
139
- it "should be able to set width with width :-)" do
140
- @map.width = '300'
141
- @map.width.should == 300
142
- end
143
-
144
- it "should be able to set height" do
145
- @map.height = '300'
146
- @map.height.should == 300
147
- end
148
-
149
- it "should be able to set width and height via size as an array" do
150
- @map.size = [200, 300]
151
- @map.size.should == '200x300'
152
- end
153
-
154
- it "should be able to set width and height via size as a hash" do
155
- @map.size = {:width => 100, :height => 500}
156
- @map.size.should == '100x500'
157
- end
158
-
159
- it "should be possible to only set height via size as a hash" do
160
- @map.size = {:height => 500}
161
- @map.size.should == '300x500'
162
- end
163
-
164
- it "should be possible to only set width via size as a hash" do
165
- @map.size = {:width => 500}
166
- @map.size.should == '500x400'
167
- end
168
-
169
- it "should raise an error if width is above 640px as it is not supported by Google Maps" do
170
- lambda {@map.width = 641}.should raise_error
171
- end
172
-
173
- it "should raise an error if height is above 640px as it is not supported by Google Maps" do
174
- lambda {@map.height = 641}.should raise_error
175
- end
176
- end
177
-
178
- describe "format" do
179
- before do
180
- @map = GoogleStaticMapsHelper::Map.new(reguire_options)
181
- end
182
-
183
- %w{png png8 png32 gif jpg jpg-basedline}.each do |format|
184
- it "should be possible to set a format to #{format}" do
185
- @map.format = format
186
- @map.format.should == format
187
- end
188
- end
189
-
190
- it "should be able to set format as symbol" do
191
- @map.format = :jpg
192
- @map.format.should == 'jpg'
193
- end
194
-
195
- it "should raise an error if format is not supported" do
196
- lambda {@map.format = :not_supported}.should raise_error(GoogleStaticMapsHelper::UnsupportedFormat)
197
- end
198
- end
199
-
200
- describe "map type" do
201
- before do
202
- @map = GoogleStaticMapsHelper::Map.new(reguire_options)
203
- end
204
-
205
- %w{roadmap satellite terrain hybrid}.each do |type|
206
- it "should be possible to set map type to #{type}" do
207
- @map.maptype = type
208
- @map.maptype.should == type
209
- end
210
- end
211
-
212
- it "should be possible to set map type as a symbol" do
213
- @map.maptype = :satellite
214
- @map.maptype.should == 'satellite'
215
- end
216
-
217
- it "should raise error if map type is not supported" do
218
- lambda {@map.maptype = :not_supported}.should raise_error(GoogleStaticMapsHelper::UnsupportedMaptype)
219
- end
220
- end
221
-
222
- describe "URL" do
223
- before :each do
224
- @key =
225
- @size = '400x600'
226
- @sensor = false
227
- @map = GoogleStaticMapsHelper::Map.new(:size => @size, :sensor => @sensor)
228
-
229
- @marker1 = GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2)
230
- @marker11 = GoogleStaticMapsHelper::Marker.new(:lng => 3, :lat => 4)
231
-
232
- @marker2 = GoogleStaticMapsHelper::Marker.new(:lng => 5, :lat => 6, :color => 'green')
233
- @marker22 = GoogleStaticMapsHelper::Marker.new(:lng => 7, :lat => 8, :color => 'green')
234
-
235
- @marker3 = GoogleStaticMapsHelper::Marker.new(:lng => 9, :lat => 10, :icon => 'http://image.com/')
236
- @marker33 = GoogleStaticMapsHelper::Marker.new(:lng => 11, :lat => 12, :icon => 'http://image.com/')
237
- end
238
-
239
- describe "valid state to run URL" do
240
- it "should raise exception if called with no markers nor center and zoom" do
241
- lambda{@map.url}.should raise_error(GoogleStaticMapsHelper::BuildDataMissing)
242
- end
243
-
244
- it "should not raise exception if markers are in map" do
245
- @map << @marker1
246
- lambda{@map.url}.should_not raise_error(GoogleStaticMapsHelper::BuildDataMissing)
247
- end
248
-
249
- it "should not raise exception if center and zoom is set" do
250
- @map.zoom = 1
251
- @map.center = '1,1'
252
- lambda{@map.url}.should_not raise_error(GoogleStaticMapsHelper::BuildDataMissing)
253
- end
254
- end
255
-
256
- describe "required parameters" do
257
- before :each do
258
- @map.zoom = 1
259
- @map.center = '1,1'
260
- end
261
-
262
- it "should start with the URL to the API" do
263
- @map.url.should include(GoogleStaticMapsHelper::API_URL)
264
- end
265
-
266
- it "should include the key" do
267
- @map.key_without_warning = 'MY_GOOGLE_KEY'
268
- @map.url.should include("key=MY_GOOGLE_KEY")
269
- end
270
-
271
- it "should not include key if it's nil" do
272
- @map.key_without_warning = nil
273
- @map.url.should_not include("key=")
274
- end
275
-
276
- it "should include the size" do
277
- @map.url.should include("size=#{@size}")
278
- end
279
-
280
- it "should include the sensor" do
281
- @map.url.should include("sensor=#{@sensor}")
282
- end
283
-
284
- it "should not include format as default" do
285
- @map.url.should_not include("format=")
286
- end
287
-
288
- it "should include format if it has been set" do
289
- @map.format = :jpg
290
- @map.url.should include("format=jpg")
291
- end
292
-
293
- it "should not include map type as default" do
294
- @map.url.should_not include("maptype=")
295
- end
296
-
297
- it "should include map type if it has been set" do
298
- @map.maptype = :satellite
299
- @map.url.should include("maptype=satellite")
300
- end
301
- end
302
-
303
- describe "with no markers in map" do
304
- before :each do
305
- @map.zoom = 1
306
- @map.center = '1,1'
307
- end
308
-
309
- it "should contain center=2,3" do
310
- @map.url.should include("center=1,1")
311
- end
312
-
313
- it "should contain zoom=1" do
314
- @map.url.should include("zoom=1")
315
- end
316
-
317
- it "should not include markers param" do
318
- @map.url.should_not include("markers=")
319
- end
320
- end
321
-
322
-
323
- describe "with markers, no one grouped" do
324
- before :each do
325
- @map << @marker1
326
- @map << @marker2
327
- @map << @marker3
328
- end
329
-
330
- [
331
- ['sensor', 'false'],
332
- ['size', '400x600'],
333
- ['markers', 'color:green|size:mid|6,5'],
334
- ['markers', 'color:red|size:mid|2,1'],
335
- ['markers', 'icon:http://image.com/|10,9']
336
- ].each do |(key, value)|
337
- it "should have key: #{key} and value: #{value}" do
338
- @map.url.should include("#{key}=#{value}")
339
- end
340
- end
341
- end
342
-
343
- describe "with markers grouped together" do
344
- before :each do
345
- @map.sensor = true
346
- @map << @marker1
347
- @map << @marker11
348
- @map << @marker2
349
- @map << @marker22
350
- @map << @marker3
351
- @map << @marker33
352
- end
353
-
354
- [
355
- ['sensor', 'true'],
356
- ['size', '400x600'],
357
- ['markers', 'color:green|size:mid|6,5|8,7'],
358
- ['markers', 'color:red|size:mid|2,1|4,3'],
359
- ['markers', 'icon:http://image.com/|10,9|12,11']
360
- ].each do |(key, value)|
361
- it "should have key: #{key} and value: #{value}" do
362
- @map.url.should include("#{key}=#{value}")
363
- end
364
- end
365
- end
366
-
367
- describe "paths" do
368
- before do
369
- @path = GoogleStaticMapsHelper::Path.new :encode_points => false
370
- @point = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
371
- @point2 = GoogleStaticMapsHelper::Location.new(:lat => 3, :lng => 4)
372
- @path << @point << @point2
373
- end
374
-
375
- it "should not include path in url if no paths are represented in the map" do
376
- @map.center = '1,2'
377
- @map.zoom = 11
378
- @map.url.should_not include("path=")
379
- end
380
-
381
- it "should include path in url if paths are represented in the map" do
382
- @map << @path
383
- @map.url.should include("path=")
384
- end
385
-
386
- [
387
- ['sensor', 'false'],
388
- ['size', '400x600'],
389
- ['path', 'weight:5|1,2|3,4'],
390
- ].each do |pair|
391
- key, value = pair
392
- it "should have key: #{key} and value: #{value}" do
393
- @path.weight = 5
394
- @map << @path
395
- @map.url.should include("#{key}=#{value}")
396
- end
397
- end
398
- end
399
- end
400
-
401
- it "should provide a helper method named marker which will create a new marker and add it to the map" do
402
- map = GoogleStaticMapsHelper::Map.new(reguire_options)
403
- map.marker(:lat => 1, :lng => 2)
404
- map.length.should eql(1)
405
- end
406
- end