google_static_maps_helper 1.3.2 → 1.3.7

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.
@@ -1,129 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe GoogleStaticMapsHelper::Marker do
4
- before :each do
5
- @location_hash = {:lat => 10, :lng => 20}
6
- @location_object = mock(:location, @location_hash)
7
- end
8
-
9
- describe "initialize" do
10
- it "should raise ArgumentError if no arguments are given" do
11
- lambda {GoogleStaticMapsHelper::Marker.new}.should raise_error(ArgumentError)
12
- end
13
-
14
- describe "get location as object" do
15
- [:lat, :lng].each do |location_property|
16
- it "should extract #{location_property} from first argument if that is object" do
17
- marker = GoogleStaticMapsHelper::Marker.new(@location_object)
18
- marker.send(location_property).should == @location_object.send(location_property)
19
- end
20
- end
21
-
22
- it "should raise NoLngMethod if object doesn't respond to lng" do
23
- lambda {GoogleStaticMapsHelper::Marker.new(mock(:location, :lat => 10))}.should raise_error(GoogleStaticMapsHelper::Location::NoLngMethod)
24
- end
25
-
26
- it "should raise NoLatMethod if object doesn't respond to lat" do
27
- lambda {GoogleStaticMapsHelper::Marker.new(mock(:location, :lng => 20))}.should raise_error(GoogleStaticMapsHelper::Location::NoLatMethod)
28
- end
29
- end
30
-
31
- describe "get location from hash" do
32
- [:lat, :lng].each do |location_property|
33
- it "should extract #{location_property} from hash" do
34
- marker = GoogleStaticMapsHelper::Marker.new(@location_hash)
35
- marker.send(location_property).should == @location_object.send(location_property)
36
- end
37
- end
38
-
39
- it "should raise NoLngKey if hash doesn't have key lng" do
40
- lambda {GoogleStaticMapsHelper::Marker.new(:lat => 10)}.should raise_error(GoogleStaticMapsHelper::Location::NoLngKey)
41
- end
42
-
43
- it "should raise NoLatKey if hash doesn't have key lat" do
44
- lambda {GoogleStaticMapsHelper::Marker.new(:lng => 20)}.should raise_error(GoogleStaticMapsHelper::Location::NoLatKey)
45
- end
46
- end
47
-
48
-
49
- describe "options" do
50
- describe "defaults" do
51
- it "should have a predefined color which location should use" do
52
- marker = GoogleStaticMapsHelper::Marker.new(@location_object)
53
- marker.color.should == 'red'
54
- end
55
-
56
- it "should have a predefined size" do
57
- marker = GoogleStaticMapsHelper::Marker.new(@location_object)
58
- marker.size.should == 'mid'
59
- end
60
-
61
- it "should have a predefined label which should be nil" do
62
- marker = GoogleStaticMapsHelper::Marker.new(@location_object)
63
- marker.label.should be_nil
64
- end
65
- end
66
-
67
- describe "override options as second parameters, location given as object as first param" do
68
- {:color => 'blue', :size => 'small', :label => 'A'}.each_pair do |key, value|
69
- it "should be possible to override #{key} to #{value}" do
70
- marker = GoogleStaticMapsHelper::Marker.new(@location_object, {key => value})
71
- marker.send(key).should == value
72
- end
73
- end
74
- end
75
-
76
- describe "override options as first parameter, location mixed into the same hash" do
77
- {:color => 'blue', :size => 'small', :label => 'A'}.each_pair do |key, value|
78
- it "should be possible to override #{key} to #{value}" do
79
- marker = GoogleStaticMapsHelper::Marker.new(@location_hash.merge({key => value}))
80
- marker.send(key).should == value
81
- end
82
- end
83
- end
84
- end
85
-
86
- it "should raise OptionNotExist if incomming option doesn't exists" do
87
- lambda {GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2, :invalid_option => 'error?')}.should raise_error(GoogleStaticMapsHelper::OptionNotExist)
88
- end
89
- end
90
-
91
-
92
-
93
- it "should upcase the label" do
94
- GoogleStaticMapsHelper::Marker.new(@location_hash.merge(:label => 'a')).label.should == 'A'
95
- end
96
-
97
- it "should downcase the color" do
98
- GoogleStaticMapsHelper::Marker.new(@location_hash.merge(:color => 'Green')).color.should == 'green'
99
- end
100
-
101
-
102
- describe "generating url parameters" do
103
- before :each do
104
- @options = {:lat => 1, :lng => 2, :color => 'Green', :label => :a, :size => 'small'}
105
- @marker = GoogleStaticMapsHelper::Marker.new(@options)
106
- end
107
-
108
- it "should contain color param" do
109
- @marker.options_to_url_params.should include('color:green')
110
- end
111
-
112
- it "should contain label param" do
113
- @marker.options_to_url_params.should include('label:A')
114
- end
115
-
116
- it "should contain size param" do
117
- @marker.options_to_url_params.should include('size:small')
118
- end
119
-
120
- it "should not contain label param if it is nil" do
121
- marker = GoogleStaticMapsHelper::Marker.new(:lat => 1, :lng => 1)
122
- marker.options_to_url_params.should_not include('label')
123
- end
124
-
125
- it "should build location_to_url" do
126
- @marker.location_to_url.should == '1,2'
127
- end
128
- end
129
- end
@@ -1,151 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe GoogleStaticMapsHelper::Path do
4
- describe "initialize" do
5
- @@options = {
6
- :weight => 5,
7
- :color => "0x0000ff",
8
- :fillcolor => "0x110000ff"
9
- }
10
-
11
- @@options.each_key do |attribute|
12
- it "should be able to set and retreive #{attribute} via initializer" do
13
- GoogleStaticMapsHelper::Path.new(@@options).send(attribute).should == @@options.fetch(attribute)
14
- end
15
-
16
- it "should be able to set and retreive #{attribute} via accessor method" do
17
- path = GoogleStaticMapsHelper::Path.new
18
- path.send("#{attribute}=", @@options.fetch(attribute))
19
- path.send(attribute).should == @@options.fetch(attribute)
20
- end
21
- end
22
-
23
- describe "points" do
24
- before do
25
- @point = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
26
- @point2 = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
27
- end
28
-
29
- it "should be able to add points via options during initialization" do
30
- path = GoogleStaticMapsHelper::Path.new(@@options.merge(:points => [@point, @point2]))
31
- path.points.should == [@point, @point2]
32
- end
33
-
34
- it "should be able to add points before option hash" do
35
- path = GoogleStaticMapsHelper::Path.new(@point, @point2, @@options)
36
- path.points.should == [@point, @point2]
37
- end
38
- end
39
- end
40
-
41
- describe "points" do
42
- before do
43
- @path = GoogleStaticMapsHelper::Path.new
44
- @point = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
45
- @point2 = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
46
- end
47
-
48
- it "should be an empty array of points after initialize" do
49
- @path.points.should == []
50
- end
51
-
52
- it "should be able to push points on to a path" do
53
- @path << @point
54
- @path.points.length.should == 1
55
- @path.points.first.should == @point
56
- end
57
-
58
- it "should not be able to push the same point twice" do
59
- @path << @point
60
- @path << @point
61
- @path.points.should == [@point]
62
- end
63
-
64
- it "should be able to chain push operator" do
65
- @path << @point << @point2
66
- @path.points.should == [@point, @point2]
67
- end
68
-
69
- it "should respond do each" do
70
- @path.should respond_to(:each)
71
- end
72
-
73
- it "should be able to tell it's length" do
74
- @path << @point << @point2
75
- @path.length.should == 2
76
- end
77
-
78
- it "should be able to answer empty?" do
79
- @path.should be_empty
80
- end
81
-
82
- it "should wrap a hash which contains lat and lng into a Location object when pushed" do
83
- @path << {:lat => 1, :lng => 2}
84
- @path.first.should be_an_instance_of(GoogleStaticMapsHelper::Location)
85
- end
86
-
87
- it "should fetch lat and lng values from any object which responds to it" do
88
- @path << mock(:point, :lat => 1, :lng => 2)
89
- @path.first.should be_an_instance_of(GoogleStaticMapsHelper::Location)
90
- end
91
-
92
- it "should raise an error if points setter doesn't receive an array" do
93
- lambda {@path.points = nil}.should raise_error(ArgumentError)
94
- end
95
-
96
- it "should make sure points-setter ensures that hash-values are wraped into a Location object" do
97
- @path.points = []
98
- end
99
- end
100
-
101
-
102
- describe "url_params" do
103
- before do
104
- @path = GoogleStaticMapsHelper::Path.new
105
- @point = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
106
- @point2 = GoogleStaticMapsHelper::Location.new(:lat => 3, :lng => 4)
107
- @path << @point << @point2
108
- end
109
-
110
- it "should respond to url_params" do
111
- @path.should respond_to(:url_params)
112
- end
113
-
114
- it "should raise an error if a path doesn't include any points" do
115
- @path.points = []
116
- lambda {@path.url_params}.should raise_error(GoogleStaticMapsHelper::BuildDataMissing)
117
- end
118
-
119
- it "should not raise an error if path have points" do
120
- lambda {@path.url_params}.should_not raise_error(GoogleStaticMapsHelper::BuildDataMissing)
121
- end
122
-
123
- it "should begin with path=" do
124
- @path.url_params.should match(/^path=/)
125
- end
126
-
127
- it "should include points' locations" do
128
- @path.url_params.should include('1,2')
129
- end
130
-
131
- @@options.each do |attribute, value|
132
- it "should not include #{attribute} as default in url" do
133
- @path.url_params.should_not include("#{attribute}=")
134
- end
135
-
136
- it "should include #{attribute} when set on path" do
137
- @path.send("#{attribute}=", value)
138
- @path.url_params.should include("#{attribute}:#{value}")
139
- end
140
- end
141
-
142
- it "should concat path options and point locations correctly together" do
143
- @path.weight = 3
144
- @path.url_params.should == 'path=weight:3|1,2|3,4'
145
- end
146
-
147
- it "should concat point locations without any path options" do
148
- @path.url_params.should == 'path=1,2|3,4'
149
- end
150
- end
151
- end
@@ -1,9 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'google_static_maps_helper'
4
- require 'spec'
5
- require 'spec/autorun'
6
-
7
- Spec::Runner.configure do |config|
8
-
9
- end