google_static_maps_helper 1.3.5 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/marker_spec.rb DELETED
@@ -1,191 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
-
4
- describe GoogleStaticMapsHelper::Marker 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::Marker.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::Marker.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::Marker.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::Marker.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::Marker.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::Marker.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::Marker.new(:lng => 20)}.should raise_error(GoogleStaticMapsHelper::Location::NoLatKey)
46
- end
47
- end
48
-
49
-
50
- describe "options" do
51
- describe "defaults" do
52
- before do
53
- @marker = GoogleStaticMapsHelper::Marker.new(@location_object)
54
- end
55
-
56
- it "should have a predefined color which location should use" do
57
- @marker.color.should == 'red'
58
- end
59
-
60
- it "should have a predefined size" do
61
- @marker.size.should == 'mid'
62
- end
63
-
64
- it "should have a predefined label which should be nil" do
65
- @marker.label.should be_nil
66
- end
67
-
68
- it "should have an icon predefined to nil" do
69
- @marker.icon.should be_nil
70
- end
71
-
72
- it "should have an shadow predefined to nil" do
73
- @marker.shadow.should be_nil
74
- end
75
- end
76
-
77
- describe "override options as second parameters, location given as object as first param" do
78
- {
79
- :color => 'blue',
80
- :size => 'small',
81
- :label => 'A',
82
- :icon => 'http://www.url.to/img.png',
83
- :shadow => 'true'
84
- }.each_pair do |key, value|
85
- it "should be possible to override #{key} to #{value}" do
86
- marker = GoogleStaticMapsHelper::Marker.new(@location_object, {key => value})
87
- marker.send(key).should == value
88
- end
89
- end
90
- end
91
-
92
- describe "override options as first parameter, location mixed into the same hash" do
93
- {
94
- :color => 'blue',
95
- :size => 'small',
96
- :label => 'A',
97
- :icon => 'http://www.url.to/img.png',
98
- :shadow => 'true'
99
- }.each_pair do |key, value|
100
- it "should be possible to override #{key} to #{value}" do
101
- marker = GoogleStaticMapsHelper::Marker.new(@location_hash.merge({key => value}))
102
- marker.send(key).should == value
103
- end
104
- end
105
- end
106
- end
107
-
108
- it "should raise OptionNotExist if incomming option doesn't exists" do
109
- lambda {GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2, :invalid_option => 'error?')}.should raise_error(GoogleStaticMapsHelper::OptionNotExist)
110
- end
111
- end
112
-
113
-
114
-
115
- it "should upcase the label" do
116
- GoogleStaticMapsHelper::Marker.new(@location_hash.merge(:label => 'a')).label.should == 'A'
117
- end
118
-
119
- it "should downcase the color" do
120
- GoogleStaticMapsHelper::Marker.new(@location_hash.merge(:color => 'Green')).color.should == 'green'
121
- end
122
-
123
- it "should answer false when asked if it has an icon when it doesn't" do
124
- GoogleStaticMapsHelper::Marker.new(@location_hash).should_not have_icon
125
- end
126
-
127
- it "should answer true when asked if it has an icon when it does" do
128
- GoogleStaticMapsHelper::Marker.new(@location_hash.merge(:icon => 'http://icon.com/')).should have_icon
129
- end
130
-
131
-
132
- describe "generating url parameters" do
133
- before :each do
134
- @options = {:lat => 1, :lng => 2, :color => 'Green', :label => :a, :size => 'small'}
135
- @marker = GoogleStaticMapsHelper::Marker.new(@options)
136
- end
137
-
138
- it "should contain color param" do
139
- @marker.options_to_url_params.should include('color:green')
140
- end
141
-
142
- it "should contain label param" do
143
- @marker.options_to_url_params.should include('label:A')
144
- end
145
-
146
- it "should contain size param" do
147
- @marker.options_to_url_params.should include('size:small')
148
- end
149
-
150
- it "should not contain label param if it is nil" do
151
- marker = GoogleStaticMapsHelper::Marker.new(:lat => 1, :lng => 1)
152
- marker.options_to_url_params.should_not include('label')
153
- end
154
-
155
- it "should build location_to_url" do
156
- @marker.location_to_url.should == '1,2'
157
- end
158
-
159
- describe "icon and shadow" do
160
- before do
161
- @marker.icon = 'http://www.icon.com/'
162
- @marker.shadow = false
163
- end
164
-
165
- it "should contain the icon param" do
166
- @marker.options_to_url_params.should include('icon:http://www.icon.com/')
167
- end
168
-
169
- it "should URL encode the URL" do
170
- @marker.icon = 'http://www.icon.com/foo bar/'
171
- @marker.options_to_url_params.should include('icon:http://www.icon.com/foo%20bar/')
172
- end
173
-
174
- it "should contain the shadow param" do
175
- @marker.options_to_url_params.should include('shadow:false')
176
- end
177
-
178
- [:color, :label, :size].each do |property|
179
- it "should not contain #{property} when icon is set" do
180
- @marker.options_to_url_params.should_not include(property.to_s)
181
- end
182
- end
183
-
184
- it "should not include shadow if it hasn't an icon" do
185
- @marker.shadow = true
186
- @marker.icon = nil
187
- @marker.options_to_url_params.should_not include('shadow:true')
188
- end
189
- end
190
- end
191
- end
data/spec/path_spec.rb DELETED
@@ -1,189 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
-
4
- describe GoogleStaticMapsHelper::Path do
5
- options = {
6
- :weight => 5,
7
- :color => "0x0000ff",
8
- :fillcolor => "0x110000ff"
9
- }
10
-
11
- describe "initialize" do
12
- options.each_key do |attribute|
13
- it "should be able to set and retreive #{attribute} via initializer" do
14
- GoogleStaticMapsHelper::Path.new(options).send(attribute).should == options.fetch(attribute)
15
- end
16
-
17
- it "should be able to set and retreive #{attribute} via accessor method" do
18
- path = GoogleStaticMapsHelper::Path.new
19
- path.send("#{attribute}=", options.fetch(attribute))
20
- path.send(attribute).should == options.fetch(attribute)
21
- end
22
- end
23
-
24
- describe "encoding points flag" do
25
- it "should be able to set to false" do
26
- path = GoogleStaticMapsHelper::Path.new(:encode_points => false)
27
- path.should_not be_encoding_points
28
- end
29
-
30
- it "should be able to set to true" do
31
- path = GoogleStaticMapsHelper::Path.new(:encode_points => true)
32
- path.should be_encoding_points
33
- end
34
-
35
- it "should be true as default" do
36
- path = GoogleStaticMapsHelper::Path.new
37
- path.should be_encoding_points
38
- end
39
- end
40
-
41
- describe "points" do
42
- before do
43
- @point = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
44
- @point2 = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
45
- end
46
-
47
- it "should be able to add points via options during initialization" do
48
- path = GoogleStaticMapsHelper::Path.new(options.merge(:points => [@point, @point2]))
49
- path.points.should == [@point, @point2]
50
- end
51
-
52
- it "should be able to add points before option hash" do
53
- path = GoogleStaticMapsHelper::Path.new(@point, @point2, options)
54
- path.points.should == [@point, @point2]
55
- end
56
- end
57
- end
58
-
59
- describe "points" do
60
- before do
61
- @path = GoogleStaticMapsHelper::Path.new
62
- @point = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
63
- @point2 = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
64
- end
65
-
66
- it "should be an empty array of points after initialize" do
67
- @path.points.should == []
68
- end
69
-
70
- it "should be possible to clear points" do
71
- @path << @point << @point2
72
- @path.clear
73
- @path.length.should == 0
74
- end
75
-
76
- it "should be able to push points on to a path" do
77
- @path << @point
78
- @path.points.length.should == 1
79
- @path.points.first.should == @point
80
- end
81
-
82
- it "should not be able to push the same point twice" do
83
- @path << @point
84
- @path << @point
85
- @path.points.should == [@point]
86
- end
87
-
88
- it "should be able to chain push operator" do
89
- @path << @point << @point2
90
- @path.points.should == [@point, @point2]
91
- end
92
-
93
- it "should respond do each" do
94
- @path.should respond_to(:each)
95
- end
96
-
97
- it "should be able to tell it's length" do
98
- @path << @point << @point2
99
- @path.length.should == 2
100
- end
101
-
102
- it "should be able to answer empty?" do
103
- @path.should be_empty
104
- end
105
-
106
- it "should wrap a hash which contains lat and lng into a Location object when pushed" do
107
- @path << {:lat => 1, :lng => 2}
108
- @path.first.should be_an_instance_of(GoogleStaticMapsHelper::Location)
109
- end
110
-
111
- it "should fetch lat and lng values from any object which responds to it" do
112
- @path << mock(:point, :lat => 1, :lng => 2)
113
- @path.first.should be_an_instance_of(GoogleStaticMapsHelper::Location)
114
- end
115
-
116
- it "should raise an error if points setter doesn't receive an array" do
117
- lambda {@path.points = nil}.should raise_error(ArgumentError)
118
- end
119
-
120
- it "should make sure points-setter ensures that hash-values are wraped into a Location object" do
121
- @path.points = []
122
- end
123
- end
124
-
125
-
126
- describe "url_params" do
127
- before do
128
- @path = GoogleStaticMapsHelper::Path.new :encode_points => false
129
- @point = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
130
- @point2 = GoogleStaticMapsHelper::Location.new(:lat => 3, :lng => 4)
131
- @path << @point << @point2
132
- end
133
-
134
- it "should respond to url_params" do
135
- @path.should respond_to(:url_params)
136
- end
137
-
138
- it "should raise an error if a path doesn't include any points" do
139
- @path.points = []
140
- lambda {@path.url_params}.should raise_error(GoogleStaticMapsHelper::BuildDataMissing)
141
- end
142
-
143
- it "should not raise an error if path have points" do
144
- lambda {@path.url_params}.should_not raise_error(GoogleStaticMapsHelper::BuildDataMissing)
145
- end
146
-
147
- it "should begin with path=" do
148
- @path.url_params.should match(/^path=/)
149
- end
150
-
151
- it "should include points' locations" do
152
- @path.url_params.should include('1,2')
153
- end
154
-
155
- options.each do |attribute, value|
156
- it "should not include #{attribute} as default in url" do
157
- @path.url_params.should_not include("#{attribute}=")
158
- end
159
-
160
- it "should include #{attribute} when set on path" do
161
- @path.send("#{attribute}=", value)
162
- @path.url_params.should include("#{attribute}:#{value}")
163
- end
164
- end
165
-
166
- it "should concat path options and point locations correctly together" do
167
- @path.weight = 3
168
- @path.url_params.should == 'path=weight:3|1,2|3,4'
169
- end
170
-
171
- it "should concat point locations without any path options" do
172
- @path.url_params.should == 'path=1,2|3,4'
173
- end
174
-
175
- describe "encoded poly lines" do
176
- before do
177
- @path.encode_points = true
178
- end
179
-
180
- it "should include 'enc:'" do
181
- @path.url_params.should include('enc:')
182
- end
183
-
184
- it "should include encoded version of lng and lat" do
185
- @path.url_params.should include('_ibE_seK_seK_seK')
186
- end
187
- end
188
- end
189
- end
data/spec/spec_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- require 'google_static_maps_helper'
5
- require 'spec'
6
- require 'spec/autorun'
7
-
8
- Spec::Runner.configure do |config|
9
-
10
- end