gmaps4rails 0.8.8 → 0.9.0
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/lib/{array.rb → extensions/array.rb} +3 -0
- data/lib/{hash.rb → extensions/hash.rb} +5 -1
- data/lib/gmaps4rails.rb +6 -7
- data/lib/gmaps4rails/acts_as_gmappable.rb +85 -0
- data/lib/gmaps4rails/base.rb +170 -0
- data/lib/{gmaps4rails_helper.rb → helper/gmaps4rails_helper.rb} +4 -0
- data/public/javascripts/gmaps4rails.js +201 -164
- data/test/dummy/app/controllers/users_controller.rb +4 -0
- data/test/dummy/app/models/user.rb +2 -1
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/spec/base/base_spec.rb +2 -2
- data/test/dummy/spec/javascripts/support/jasmine_config.rb +23 -0
- data/test/dummy/spec/javascripts/support/jasmine_runner.rb +20 -0
- data/test/dummy/spec/models/user_spec.rb +198 -313
- data/test/dummy/spec/{factories.rb → support/factories.rb} +0 -5
- data/test/dummy/spec/support/matchers.rb +7 -0
- metadata +18 -13
- data/lib/acts_as_gmappable/base.rb +0 -209
- data/test/dummy/spec/controllers/users_controller_spec.rb +0 -57
data/test/dummy/config/routes.rb
CHANGED
@@ -45,7 +45,7 @@ describe "JS creation from hash" do
|
|
45
45
|
"options" => {"waypoints" => ["toulouse, france", "brest, france"], "travelMode" => "DRIVING", "display_panel" => true, "panel_id" => "instructions"}
|
46
46
|
}
|
47
47
|
}
|
48
|
-
options_hash.to_gmaps4rails.should == "Gmaps4Rails.polylines = [[\n{\"longitude\": -122.214897, \"latitude\": 37.772323},\n{\"longitude\": -157.821856, \"latitude\": 21.291982},\n{\"longitude\": 178.431, \"latitude\": -18.142599},\n{\"longitude\": 153.027892, \"latitude\": -27.46758}\n],\n[\n{\"longitude\": -120.214897, \"latitude\": 30.772323, \"strokeColor\": \"#000\", \"strokeWeight\" : 2 },\n{\"longitude\": -10.821856, \"latitude\": 50.291982}\n]];\nGmaps4Rails.create_polylines();\nGmaps4Rails.circles = [\n{\"longitude\": -122.214897, \"latitude\": 37.772323, \"radius\": 1000000},\n{\"longitude\": 122.214897, \"latitude\": 37.772323, \"radius\": 1000000, \"strokeColor\": \"#FF0000\"}\n];\nGmaps4Rails.create_circles();\nGmaps4Rails.polygons = [[\n{\"longitude\": -80.190262, \"latitude\": 25.774252},\n{\"longitude\": -66.118292, \"latitude\": 18.466465},\n{\"longitude\": -64.75737, \"latitude\": 32.321384}\n]];\nGmaps4Rails.create_polygons();\nGmaps4Rails.markers = [{ \"description\": \"\", \"title\": \"\", \"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\" } ,{ \"description\": \"\", \"title\": \"\", \"longitude\": \"2.3509871\", \"latitude\": \"48.8566667\", \"picture\": \"\", \"width\": \"\", \"height\": \"\" } ];\nGmaps4Rails.create_markers();\nGmaps4Rails.direction_conf.origin = 'toulon, france';\nGmaps4Rails.direction_conf.destination = 'paris, france';\nGmaps4Rails.direction_conf.display_panel = true;\nGmaps4Rails.direction_conf.panel_id = 'instructions';\nGmaps4Rails.direction_conf.travelMode = 'DRIVING';\nGmaps4Rails.direction_conf.waypoints = [{\"stopover\":true,\"location\":\"toulouse, france\"},{\"stopover\":true,\"location\":\"brest, france\"}];\nGmaps4Rails.create_direction();\
|
48
|
+
options_hash.to_gmaps4rails.should == "Gmaps4Rails.polylines = [[\n{\"longitude\": -122.214897, \"latitude\": 37.772323},\n{\"longitude\": -157.821856, \"latitude\": 21.291982},\n{\"longitude\": 178.431, \"latitude\": -18.142599},\n{\"longitude\": 153.027892, \"latitude\": -27.46758}\n],\n[\n{\"longitude\": -120.214897, \"latitude\": 30.772323, \"strokeColor\": \"#000\", \"strokeWeight\" : 2 },\n{\"longitude\": -10.821856, \"latitude\": 50.291982}\n]];\nGmaps4Rails.create_polylines();\nGmaps4Rails.circles = [\n{\"longitude\": -122.214897, \"latitude\": 37.772323, \"radius\": 1000000},\n{\"longitude\": 122.214897, \"latitude\": 37.772323, \"radius\": 1000000, \"strokeColor\": \"#FF0000\"}\n];\nGmaps4Rails.create_circles();\nGmaps4Rails.polygons = [[\n{\"longitude\": -80.190262, \"latitude\": 25.774252},\n{\"longitude\": -66.118292, \"latitude\": 18.466465},\n{\"longitude\": -64.75737, \"latitude\": 32.321384}\n]];\nGmaps4Rails.create_polygons();\nGmaps4Rails.markers = [{ \"description\": \"\", \"title\": \"\", \"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\" } ,{ \"description\": \"\", \"title\": \"\", \"longitude\": \"2.3509871\", \"latitude\": \"48.8566667\", \"picture\": \"\", \"width\": \"\", \"height\": \"\" } ];\nGmaps4Rails.create_markers();\nGmaps4Rails.direction_conf.origin = 'toulon, france';\nGmaps4Rails.direction_conf.destination = 'paris, france';\nGmaps4Rails.direction_conf.display_panel = true;\nGmaps4Rails.direction_conf.panel_id = 'instructions';\nGmaps4Rails.direction_conf.travelMode = 'DRIVING';\nGmaps4Rails.direction_conf.waypoints = [{\"stopover\":true,\"location\":\"toulouse, france\"},{\"stopover\":true,\"location\":\"brest, france\"}];\nGmaps4Rails.create_direction();\nGmaps4Rails.callback();"
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should add map settings when 'true' passed" do
|
@@ -77,7 +77,7 @@ describe "JS creation from hash" do
|
|
77
77
|
"options" => {"waypoints" => ["toulouse, france", "brest, france"], "travelMode" => "DRIVING", "display_panel" => true, "panel_id" => "instructions"}
|
78
78
|
}
|
79
79
|
}
|
80
|
-
options_hash.to_gmaps4rails(true).should == "Gmaps4Rails.map_options.center_longitude = 180;\nGmaps4Rails.map_options.type = 'SATELLITE';\nGmaps4Rails.map_options.zoom = 3;\nGmaps4Rails.initialize();\nGmaps4Rails.polylines = [[\n{\"longitude\": -122.214897, \"latitude\": 37.772323},\n{\"longitude\": -157.821856, \"latitude\": 21.291982},\n{\"longitude\": 178.431, \"latitude\": -18.142599},\n{\"longitude\": 153.027892, \"latitude\": -27.46758}\n],\n[\n{\"longitude\": -120.214897, \"latitude\": 30.772323, \"strokeColor\": \"#000\", \"strokeWeight\" : 2 },\n{\"longitude\": -10.821856, \"latitude\": 50.291982}\n]];\nGmaps4Rails.create_polylines();\nGmaps4Rails.circles = [\n{\"longitude\": -122.214897, \"latitude\": 37.772323, \"radius\": 1000000},\n{\"longitude\": 122.214897, \"latitude\": 37.772323, \"radius\": 1000000, \"strokeColor\": \"#FF0000\"}\n];\nGmaps4Rails.create_circles();\nGmaps4Rails.polygons = [[\n{\"longitude\": -80.190262, \"latitude\": 25.774252},\n{\"longitude\": -66.118292, \"latitude\": 18.466465},\n{\"longitude\": -64.75737, \"latitude\": 32.321384}\n]];\nGmaps4Rails.create_polygons();\nGmaps4Rails.markers = [{ \"description\": \"\", \"title\": \"\", \"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\" } ,{ \"description\": \"\", \"title\": \"\", \"longitude\": \"2.3509871\", \"latitude\": \"48.8566667\", \"picture\": \"\", \"width\": \"\", \"height\": \"\" } ];\nGmaps4Rails.create_markers();\nGmaps4Rails.direction_conf.origin = 'toulon, france';\nGmaps4Rails.direction_conf.destination = 'paris, france';\nGmaps4Rails.direction_conf.display_panel = true;\nGmaps4Rails.direction_conf.panel_id = 'instructions';\nGmaps4Rails.direction_conf.travelMode = 'DRIVING';\nGmaps4Rails.direction_conf.waypoints = [{\"stopover\":true,\"location\":\"toulouse, france\"},{\"stopover\":true,\"location\":\"brest, france\"}];\nGmaps4Rails.create_direction();\
|
80
|
+
options_hash.to_gmaps4rails(true).should == "Gmaps4Rails.map_options.center_longitude = 180;\nGmaps4Rails.map_options.type = 'SATELLITE';\nGmaps4Rails.map_options.zoom = 3;\nGmaps4Rails.initialize();\nGmaps4Rails.polylines = [[\n{\"longitude\": -122.214897, \"latitude\": 37.772323},\n{\"longitude\": -157.821856, \"latitude\": 21.291982},\n{\"longitude\": 178.431, \"latitude\": -18.142599},\n{\"longitude\": 153.027892, \"latitude\": -27.46758}\n],\n[\n{\"longitude\": -120.214897, \"latitude\": 30.772323, \"strokeColor\": \"#000\", \"strokeWeight\" : 2 },\n{\"longitude\": -10.821856, \"latitude\": 50.291982}\n]];\nGmaps4Rails.create_polylines();\nGmaps4Rails.circles = [\n{\"longitude\": -122.214897, \"latitude\": 37.772323, \"radius\": 1000000},\n{\"longitude\": 122.214897, \"latitude\": 37.772323, \"radius\": 1000000, \"strokeColor\": \"#FF0000\"}\n];\nGmaps4Rails.create_circles();\nGmaps4Rails.polygons = [[\n{\"longitude\": -80.190262, \"latitude\": 25.774252},\n{\"longitude\": -66.118292, \"latitude\": 18.466465},\n{\"longitude\": -64.75737, \"latitude\": 32.321384}\n]];\nGmaps4Rails.create_polygons();\nGmaps4Rails.markers = [{ \"description\": \"\", \"title\": \"\", \"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\" } ,{ \"description\": \"\", \"title\": \"\", \"longitude\": \"2.3509871\", \"latitude\": \"48.8566667\", \"picture\": \"\", \"width\": \"\", \"height\": \"\" } ];\nGmaps4Rails.create_markers();\nGmaps4Rails.direction_conf.origin = 'toulon, france';\nGmaps4Rails.direction_conf.destination = 'paris, france';\nGmaps4Rails.direction_conf.display_panel = true;\nGmaps4Rails.direction_conf.panel_id = 'instructions';\nGmaps4Rails.direction_conf.travelMode = 'DRIVING';\nGmaps4Rails.direction_conf.waypoints = [{\"stopover\":true,\"location\":\"toulouse, france\"},{\"stopover\":true,\"location\":\"brest, france\"}];\nGmaps4Rails.create_direction();\nGmaps4Rails.callback();"
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Jasmine
|
2
|
+
class Config
|
3
|
+
|
4
|
+
# Add your overrides or custom config code here
|
5
|
+
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
# Note - this is necessary for rspec2, which has removed the backtrace
|
11
|
+
module Jasmine
|
12
|
+
class SpecBuilder
|
13
|
+
def declare_spec(parent, spec)
|
14
|
+
me = self
|
15
|
+
example_name = spec["name"]
|
16
|
+
@spec_ids << spec["id"]
|
17
|
+
backtrace = @example_locations[parent.description + " " + example_name]
|
18
|
+
parent.it example_name, {} do
|
19
|
+
me.report_spec(spec["id"])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'jasmine'
|
5
|
+
require 'rspec'
|
6
|
+
jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
|
7
|
+
require jasmine_config_overrides if File.exists?(jasmine_config_overrides)
|
8
|
+
|
9
|
+
jasmine_config = Jasmine::Config.new
|
10
|
+
spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
|
11
|
+
|
12
|
+
should_stop = false
|
13
|
+
|
14
|
+
RSpec.configuration.after(:suite) do
|
15
|
+
spec_builder.stop if should_stop
|
16
|
+
end
|
17
|
+
|
18
|
+
spec_builder.start
|
19
|
+
should_stop = true
|
20
|
+
spec_builder.declare_suites
|
@@ -1,384 +1,269 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
DEFAULT_CONFIG_HASH = {
|
4
|
+
:lat_column => "latitude",
|
5
|
+
:lng_column => "longitude",
|
6
|
+
:check_process => true,
|
7
|
+
:checker => "gmaps",
|
8
|
+
:msg => "Address invalid",
|
9
|
+
:validation => true,
|
10
|
+
:address => "gmaps4rails_address",
|
11
|
+
:language => "en"
|
12
|
+
}
|
13
|
+
|
14
|
+
PARIS = { :latitude => 48.856614, :longitude => 2.3522219 }
|
15
|
+
TOULON = { :latitude => 43.124228, :longitude => 5.928 }
|
16
|
+
|
17
|
+
#set model configuration
|
18
|
+
def set_gmaps4rails_options!(change_conf = {})
|
19
|
+
User.class_eval do
|
20
|
+
define_method "gmaps4rails_options" do
|
21
|
+
DEFAULT_CONFIG_HASH.merge(change_conf)
|
20
22
|
end
|
21
|
-
@toulon = { :latitude => 43.124228, :longitude => 5.928}
|
22
|
-
@paris = { :latitude => 48.856614, :longitude => 2.3522219}
|
23
23
|
end
|
24
|
+
end
|
25
|
+
|
26
|
+
set_gmaps4rails_options!
|
27
|
+
|
28
|
+
describe Gmaps4rails::ActsAsGmappable do
|
29
|
+
|
30
|
+
let(:user) { Factory(:user) }
|
31
|
+
let(:invalid_user) { Factory.build(:invalid_user) }
|
24
32
|
|
25
|
-
|
26
|
-
before(:each) do
|
27
|
-
@user = Factory(:user)
|
28
|
-
end
|
33
|
+
context "standard configuration, valid user" do
|
29
34
|
|
30
35
|
it "should have a geocoded position" do
|
31
|
-
|
32
|
-
@user.longitude.should == @toulon[:longitude]
|
36
|
+
user.should have_same_position_as TOULON
|
33
37
|
end
|
34
38
|
|
35
39
|
it "should set boolean to true once user is created" do
|
36
|
-
|
40
|
+
user.gmaps.should be_true
|
37
41
|
end
|
38
42
|
|
39
43
|
it "should render a valid json from an array of ojects" do
|
40
|
-
|
41
|
-
|
44
|
+
user #needed trigger the object from the let statement
|
45
|
+
Factory(:user_paris)
|
46
|
+
User.all.to_gmaps4rails.should == "[{\"longitude\": \"" + TOULON[:longitude].to_s + "\", \"latitude\": \"" + TOULON[:latitude].to_s + "\"},\n{\"longitude\": \"" + PARIS[:longitude].to_s + "\", \"latitude\": \"" + PARIS[:latitude].to_s + "\"}]"
|
42
47
|
end
|
43
48
|
|
44
49
|
it "should render a valid json from a single object" do
|
45
|
-
|
50
|
+
user.to_gmaps4rails.should == "[{\"longitude\": \"" + TOULON[:longitude].to_s + "\", \"latitude\": \"" + TOULON[:latitude].to_s + "\"}]"
|
46
51
|
end
|
47
52
|
|
48
53
|
it "should not geocode again after address changes if checker is true" do
|
49
|
-
|
50
|
-
|
51
|
-
@user.latitude.should == @toulon[:latitude]
|
52
|
-
@user.longitude.should == @toulon[:longitude]
|
54
|
+
user.update_attributes({ :sec_address => "PARIS, France" })
|
55
|
+
user.should have_same_position_as TOULON
|
53
56
|
end
|
54
57
|
|
55
58
|
it "should geocode after address changes if checker is false" do
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
@user.latitude.should == @paris[:latitude]
|
60
|
-
@user.longitude.should == @paris[:longitude]
|
59
|
+
user.update_attributes({ :sec_address => "PARIS, France",
|
60
|
+
:gmaps => false})
|
61
|
+
user.should have_same_position_as PARIS
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
64
65
|
|
65
|
-
|
66
|
-
before(:each) do
|
67
|
-
@user = Factory.build(:invalid_user)
|
68
|
-
end
|
66
|
+
context "standard configuration, invalid address" do
|
69
67
|
|
70
68
|
it "should raise an error if validation option is turned on and address incorrect" do
|
71
|
-
|
69
|
+
invalid_user.should_not be_valid, "Address invalid"
|
72
70
|
end
|
73
71
|
|
74
72
|
it "should not set boolean to true when address update fails" do
|
75
|
-
|
73
|
+
invalid_user.gmaps.should_not be_true
|
76
74
|
end
|
77
75
|
end
|
78
76
|
|
79
77
|
|
80
|
-
|
81
|
-
|
78
|
+
context "model customization" do
|
79
|
+
|
82
80
|
it "should render a valid json even if there is no instance in the db" do
|
83
81
|
User.all.to_gmaps4rails.should == "[]"
|
84
82
|
end
|
85
83
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
:lng_column => "longitude",
|
92
|
-
:check_process => true,
|
93
|
-
:checker => "gmaps",
|
94
|
-
:msg => "Address invalid",
|
95
|
-
:validation => true,
|
96
|
-
:address => "sec_address",
|
97
|
-
:language => "en"
|
98
|
-
}
|
99
|
-
end
|
84
|
+
context "acts_as_gmappable options" do
|
85
|
+
|
86
|
+
after(:all) do
|
87
|
+
#reset all configuration to default
|
88
|
+
set_gmaps4rails_options!
|
100
89
|
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
it "should save the normalized address if requested" do
|
107
|
-
User.class_eval do
|
108
|
-
def gmaps4rails_options
|
109
|
-
{
|
110
|
-
:lat_column => "latitude",
|
111
|
-
:lng_column => "longitude",
|
112
|
-
:check_process => true,
|
113
|
-
:checker => "gmaps",
|
114
|
-
:msg => "Address invalid",
|
115
|
-
:validation => true,
|
116
|
-
:normalized_address => "norm_address",
|
117
|
-
:address => "gmaps4rails_address",
|
118
|
-
:language => "en"
|
119
|
-
}
|
120
|
-
end
|
90
|
+
|
91
|
+
it "should use indifferently a db column for address if passed in config" do
|
92
|
+
set_gmaps4rails_options!({:address => "sec_address"})
|
93
|
+
user.should have_same_position_as TOULON
|
121
94
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
it "should override user's address with normalized address if requested" do
|
127
|
-
User.class_eval do
|
128
|
-
def gmaps4rails_options
|
129
|
-
{
|
130
|
-
:lat_column => "latitude",
|
131
|
-
:lng_column => "longitude",
|
132
|
-
:check_process => true,
|
133
|
-
:checker => "gmaps",
|
134
|
-
:msg => "Custom Address invalid",
|
135
|
-
:validation => true,
|
136
|
-
:normalized_address => "sec_address",
|
137
|
-
:address => "gmaps4rails_address",
|
138
|
-
:language => "en"
|
139
|
-
}
|
140
|
-
end
|
95
|
+
|
96
|
+
it "should save the normalized address if requested" do
|
97
|
+
set_gmaps4rails_options!({ :normalized_address => "norm_address" })
|
98
|
+
user.norm_address.should == "Toulon, France"
|
141
99
|
end
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
User.class_eval do
|
148
|
-
def gmaps4rails_options
|
149
|
-
{
|
150
|
-
:lat_column => "latitude",
|
151
|
-
:lng_column => "longitude",
|
152
|
-
:check_process => true,
|
153
|
-
:checker => "gmaps",
|
154
|
-
:msg => "Custom Address invalid",
|
155
|
-
:validation => true,
|
156
|
-
:address => "gmaps4rails_address",
|
157
|
-
:language => "en"
|
158
|
-
}
|
159
|
-
end
|
100
|
+
|
101
|
+
it "should override user's address with normalized address if requested" do
|
102
|
+
set_gmaps4rails_options!({ :normalized_address => "sec_address" })
|
103
|
+
user = Factory(:user, :sec_address => "ToUlOn, FrAnCe")
|
104
|
+
user.sec_address.should == "Toulon, France"
|
160
105
|
end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
User.class_eval do
|
167
|
-
def gmaps4rails_options
|
168
|
-
{
|
169
|
-
:lat_column => "latitude",
|
170
|
-
:lng_column => "longitude",
|
171
|
-
:check_process => true,
|
172
|
-
:checker => "gmaps",
|
173
|
-
:msg => "Address invalid",
|
174
|
-
:validation => false,
|
175
|
-
:address => "gmaps4rails_address",
|
176
|
-
:language => "en"
|
177
|
-
}
|
178
|
-
end
|
106
|
+
|
107
|
+
it "should display the proper error message when address is invalid" do
|
108
|
+
set_gmaps4rails_options!({ :msg => "Custom Address invalid"})
|
109
|
+
invalid_user.should_not be_valid
|
110
|
+
invalid_user.errors[:gmaps4rails_address].should include("Custom Address invalid")
|
179
111
|
end
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
it "should save longitude and latitude to the customized columns" do
|
185
|
-
User.class_eval do
|
186
|
-
def gmaps4rails_options
|
187
|
-
{
|
188
|
-
:lat_column => "lat_test",
|
189
|
-
:lng_column => "long_test",
|
190
|
-
:check_process => true,
|
191
|
-
:checker => "gmaps",
|
192
|
-
:msg => "Address invalid",
|
193
|
-
:validation => true,
|
194
|
-
:address => "gmaps4rails_address",
|
195
|
-
:language => "en"
|
196
|
-
}
|
197
|
-
end
|
112
|
+
|
113
|
+
it "should not raise an error if validation option is turned off" do
|
114
|
+
set_gmaps4rails_options!({ :validation => false })
|
115
|
+
invalid_user.should be_valid
|
198
116
|
end
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
User.class_eval do
|
208
|
-
def gmaps4rails_options
|
209
|
-
{
|
210
|
-
:lat_column => "lat_test",
|
211
|
-
:lng_column => "long_test",
|
212
|
-
:check_process => false,
|
213
|
-
:checker => "gmaps",
|
214
|
-
:msg => "Address invalid",
|
215
|
-
:validation => true,
|
216
|
-
:address => "gmaps4rails_address",
|
217
|
-
:language => "en"
|
218
|
-
}
|
219
|
-
end
|
117
|
+
|
118
|
+
it "should save longitude and latitude to the customized columns" do
|
119
|
+
set_gmaps4rails_options!({
|
120
|
+
:lat_column => "lat_test",
|
121
|
+
:lng_column => "long_test"
|
122
|
+
})
|
123
|
+
user.latitude.should be_nil
|
124
|
+
user.should have_same_position_as TOULON
|
220
125
|
end
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
it "should geocode after each save if 'check_process' is false" do
|
226
|
-
User.class_eval do
|
227
|
-
def gmaps4rails_options
|
228
|
-
{
|
229
|
-
:lat_column => "latitude",
|
230
|
-
:lng_column => "longitude",
|
231
|
-
:check_process => false,
|
232
|
-
:checker => "gmaps",
|
233
|
-
:msg => "Address invalid",
|
234
|
-
:validation => true,
|
235
|
-
:address => "gmaps4rails_address",
|
236
|
-
:language => "en"
|
237
|
-
}
|
238
|
-
end
|
126
|
+
|
127
|
+
it "should not save the boolean if check_process is false" do
|
128
|
+
set_gmaps4rails_options!({ :check_process => false })
|
129
|
+
user.gmaps.should be_nil
|
239
130
|
end
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
:
|
257
|
-
|
258
|
-
|
259
|
-
|
131
|
+
|
132
|
+
it "should geocode after each save if 'check_process' is false" do
|
133
|
+
set_gmaps4rails_options!({ :check_process => false })
|
134
|
+
user = Factory(:user, :sec_address => "PARIS, France")
|
135
|
+
user.should have_same_position_as PARIS
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should save to the proper boolean checker set in checker" do
|
139
|
+
set_gmaps4rails_options!({ :checker => "bool_test" })
|
140
|
+
user.gmaps.should be_nil
|
141
|
+
user.bool_test.should be_true
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should call a callback in the model if asked to" do
|
145
|
+
User.class_eval do
|
146
|
+
def gmaps4rails_options
|
147
|
+
DEFAULT_CONFIG_HASH.merge({ :callback => "save_callback" })
|
148
|
+
end
|
149
|
+
|
150
|
+
def save_callback(data)
|
151
|
+
self.called_back = true
|
152
|
+
end
|
153
|
+
|
154
|
+
attr_accessor :called_back
|
260
155
|
end
|
156
|
+
user.called_back.should be_true
|
261
157
|
end
|
262
|
-
|
263
|
-
|
264
|
-
|
158
|
+
|
159
|
+
it "should return results in the specified language" do
|
160
|
+
set_gmaps4rails_options!({
|
161
|
+
:language => "de",
|
162
|
+
:normalized_address => "norm_address"
|
163
|
+
})
|
164
|
+
user.norm_address.should == "Toulon, Frankreich"
|
165
|
+
end
|
166
|
+
|
265
167
|
end
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
168
|
+
|
169
|
+
context "instance methods" do
|
170
|
+
let(:user_with_pic) { Factory(:user_with_pic) }
|
171
|
+
|
172
|
+
it "should take into account the description provided in the model" do
|
173
|
+
user_with_pic.instance_eval do
|
174
|
+
def gmaps4rails_infowindow
|
175
|
+
"My Beautiful Picture: #{picture}"
|
176
|
+
end
|
272
177
|
end
|
178
|
+
user_with_pic.to_gmaps4rails.should include "\"description\": \"My Beautiful Picture: http://www.blankdots.com/img/github-32x32.png\""
|
273
179
|
end
|
274
|
-
@user.to_gmaps4rails.should == "[{\"description\": \"My Beautiful Picture: http://www.blankdots.com/img/github-32x32.png\", \"longitude\": \"" + @toulon[:longitude].to_s + "\", \"latitude\": \"" + @toulon[:latitude].to_s + "\"}]"
|
275
|
-
end
|
276
180
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
181
|
+
it "should take into account the picture provided in the model" do
|
182
|
+
user.instance_eval do
|
183
|
+
def gmaps4rails_marker_picture
|
184
|
+
{
|
185
|
+
"picture" => "http://www.blankdots.com/img/github-32x32.png",
|
186
|
+
"width" => "32",
|
187
|
+
"height" => "32"
|
188
|
+
}
|
189
|
+
end
|
286
190
|
end
|
191
|
+
result = user.to_gmaps4rails
|
192
|
+
result.should include "\"picture\": \"http://www.blankdots.com/img/github-32x32.png\""
|
193
|
+
result.should include "\"width\": \"32\""
|
194
|
+
result.should include "\"height\": \"32\""
|
287
195
|
end
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
196
|
+
|
197
|
+
it "should take into account the picture and shadow provided in the model" do
|
198
|
+
user.instance_eval do
|
199
|
+
def gmaps4rails_marker_picture
|
200
|
+
{
|
201
|
+
"picture" => "http://www.blankdots.com/img/github-32x32.png",
|
202
|
+
"width" => "32",
|
203
|
+
"height" => "32",
|
204
|
+
"marker_anchor" => [10, 20],
|
205
|
+
"shadow_picture" => "http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png" ,
|
206
|
+
"shadow_width" => "40",
|
207
|
+
"shadow_height" => "40",
|
208
|
+
"shadow_anchor" => [5, 10]
|
209
|
+
}
|
210
|
+
end
|
296
211
|
end
|
212
|
+
result = user.to_gmaps4rails
|
213
|
+
result.should include "\"shadow_width\": \"40\""
|
214
|
+
result.should include "\"shadow_height\": \"40\""
|
215
|
+
result.should include "\"shadow_picture\": \"http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png\""
|
216
|
+
result.should include "\"shadow_anchor\": [5, 10]"
|
217
|
+
result.should include "\"marker_anchor\": [10, 20]"
|
297
218
|
end
|
298
|
-
@user.to_gmaps4rails.should == "[{\"title\": \"Sweet Title\", \"longitude\": \"" + @toulon[:longitude].to_s + "\", \"latitude\": \"" + @toulon[:latitude].to_s + "\"}]"
|
299
|
-
end
|
300
219
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
220
|
+
it "should take into account the title provided in the model" do
|
221
|
+
user.instance_eval do
|
222
|
+
def gmaps4rails_title
|
223
|
+
"Sweet Title"
|
224
|
+
end
|
306
225
|
end
|
226
|
+
user.to_gmaps4rails.should == "[{\"title\": \"Sweet Title\", \"longitude\": \"" + TOULON[:longitude].to_s + "\", \"latitude\": \"" + TOULON[:latitude].to_s + "\"}]"
|
307
227
|
end
|
308
|
-
@user.to_gmaps4rails.should == "[{\"sidebar\": \"sidebar content\",\"longitude\": \"" + @toulon[:longitude].to_s + "\", \"latitude\": \"" + @toulon[:latitude].to_s + "\"}]"
|
309
|
-
end
|
310
228
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
"My Beautiful Picture: #{picture}"
|
317
|
-
end
|
318
|
-
|
319
|
-
def gmaps4rails_marker_picture
|
320
|
-
{
|
321
|
-
"picture" => "http://www.blankdots.com/img/github-32x32.png",
|
322
|
-
"width" => "32",
|
323
|
-
"height" => "32"
|
324
|
-
}
|
325
|
-
end
|
326
|
-
|
327
|
-
def gmaps4rails_title
|
328
|
-
"Sweet Title"
|
329
|
-
end
|
330
|
-
|
331
|
-
def gmaps4rails_sidebar
|
332
|
-
"sidebar content"
|
229
|
+
it "should take into account the sidebar content provided in the model" do
|
230
|
+
user.instance_eval do
|
231
|
+
def gmaps4rails_sidebar
|
232
|
+
"sidebar content"
|
233
|
+
end
|
333
234
|
end
|
235
|
+
user.to_gmaps4rails.should include "\"sidebar\": \"sidebar content\""
|
334
236
|
end
|
335
|
-
@user.to_gmaps4rails.should == "[{\"description\": \"My Beautiful Picture: \", \"title\": \"Sweet Title\", \"sidebar\": \"sidebar content\",\"longitude\": \"" + @toulon[:longitude].to_s + "\", \"latitude\": \"" + @toulon[:latitude].to_s + "\", \"picture\": \"http://www.blankdots.com/img/github-32x32.png\", \"width\": \"32\", \"height\": \"32\"}]"
|
336
|
-
end
|
337
237
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
:lng_column => "longitude",
|
344
|
-
:check_process => true,
|
345
|
-
:checker => "gmaps",
|
346
|
-
:msg => "Address invalid",
|
347
|
-
:validation => true,
|
348
|
-
:address => "gmaps4rails_address",
|
349
|
-
:language => "en",
|
350
|
-
:callback => "save_callback"
|
351
|
-
}
|
352
|
-
end
|
238
|
+
it "should take into account all additional data provided in the model" do
|
239
|
+
user.instance_eval do
|
240
|
+
def gmaps4rails_infowindow
|
241
|
+
"My Beautiful Picture: #{picture}"
|
242
|
+
end
|
353
243
|
|
354
|
-
|
355
|
-
|
356
|
-
|
244
|
+
def gmaps4rails_marker_picture
|
245
|
+
{
|
246
|
+
"picture" => "http://www.blankdots.com/img/github-32x32.png",
|
247
|
+
"width" => "32",
|
248
|
+
"height" => "32"
|
249
|
+
}
|
250
|
+
end
|
357
251
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
User.class_eval do
|
366
|
-
def gmaps4rails_options
|
367
|
-
{
|
368
|
-
:lat_column => "latitude",
|
369
|
-
:lng_column => "longitude",
|
370
|
-
:check_process => true,
|
371
|
-
:checker => "gmaps",
|
372
|
-
:msg => "Address invalid",
|
373
|
-
:validation => true,
|
374
|
-
:address => "gmaps4rails_address",
|
375
|
-
:language => "de",
|
376
|
-
:normalized_address => "norm_address"
|
377
|
-
}
|
252
|
+
def gmaps4rails_title
|
253
|
+
"Sweet Title"
|
254
|
+
end
|
255
|
+
|
256
|
+
def gmaps4rails_sidebar
|
257
|
+
"sidebar content"
|
258
|
+
end
|
378
259
|
end
|
260
|
+
result = user.to_gmaps4rails
|
261
|
+
result.should include "\"description\": \"My Beautiful Picture: \""
|
262
|
+
result.should include "\"title\": \"Sweet Title\""
|
263
|
+
result.should include "\"sidebar\": \"sidebar content\""
|
264
|
+
result.should include "\"picture\": \"http://www.blankdots.com/img/github-32x32.png\""
|
379
265
|
end
|
380
|
-
|
381
|
-
@user.norm_address.should == "Toulon, Frankreich"
|
266
|
+
|
382
267
|
end
|
383
268
|
end
|
384
269
|
|