gmaps4rails 1.5.2 → 1.5.3
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/.gitignore +1 -0
- data/Gemfile.lock +7 -1
- data/README.rdoc +2 -2
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +37 -96
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.bing.js.coffee +11 -0
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +85 -9
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.mapquest.js.coffee +13 -2
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee +54 -2
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +1 -1
- data/gmaps4rails.gemspec +1 -0
- data/lib/generators/gmaps4rails/install_generator.rb +28 -12
- data/lib/gmaps4rails/acts_as_gmappable.rb +3 -46
- data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +40 -0
- data/lib/gmaps4rails/api_wrappers/direction.rb +87 -0
- data/lib/gmaps4rails/api_wrappers/geocoder.rb +54 -0
- data/lib/gmaps4rails/api_wrappers/places.rb +74 -0
- data/lib/gmaps4rails/base.rb +80 -22
- data/lib/gmaps4rails/extensions/{array.rb → enumerable.rb} +1 -1
- data/lib/gmaps4rails/js_builder.rb +9 -17
- data/lib/gmaps4rails/json_builder.rb +1 -7
- data/lib/gmaps4rails/model_handler.rb +79 -0
- data/lib/gmaps4rails/version.rb +1 -1
- data/lib/gmaps4rails/view_helper.rb +4 -6
- data/public/javascripts/gmaps4rails/gmaps4rails.base.js +35 -112
- data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +12 -0
- data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +123 -7
- data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +12 -0
- data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +53 -2
- data/spec/dummy/app/views/users/index.html.erb +88 -85
- data/spec/fixtures/google_direction_valid.json +65 -0
- data/spec/fixtures/google_geocoding_toulon_france.json +58 -0
- data/spec/fixtures/google_places_valid.json +45 -0
- data/spec/fixtures/google_wrong_geocoding.json +4 -0
- data/spec/lib/base_spec.rb +59 -0
- data/spec/lib/direction_spec.rb +53 -0
- data/spec/lib/geocoder_spec.rb +46 -0
- data/spec/{base/base_spec.rb → lib/js_builder_spec.rb} +0 -6
- data/spec/lib/json_builder_spec.rb +232 -0
- data/spec/lib/places_spec.rb +25 -0
- data/spec/models/user_spec.rb +75 -357
- data/spec/spec_helper.rb +1 -0
- data/spec/support/geocoding.rb +27 -1
- metadata +47 -12
- data/lib/gmaps4rails/geocoding.rb +0 -113
- data/lib/gmaps4rails/google_places.rb +0 -76
- data/spec/base/geocoding_spec.rb +0 -17
data/spec/models/user_spec.rb
CHANGED
@@ -2,58 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Geocoding
|
4
4
|
|
5
|
-
DEFAULT_CONFIG_HASH = {
|
6
|
-
:lat_column => "latitude",
|
7
|
-
:lng_column => "longitude",
|
8
|
-
:check_process => true,
|
9
|
-
:checker => "gmaps",
|
10
|
-
:msg => "Address invalid",
|
11
|
-
:validation => true,
|
12
|
-
:address => "address",
|
13
|
-
:language => "en",
|
14
|
-
:protocol => "http",
|
15
|
-
:process_geocoding => true
|
16
|
-
}
|
17
|
-
|
18
|
-
PARIS = { :latitude => 48.856614, :longitude => 2.3522219 }
|
19
|
-
TOULON = { :latitude => 43.124228, :longitude => 5.928 }
|
20
|
-
|
21
|
-
#set model configuration
|
22
|
-
def set_gmaps4rails_options!(change_conf = {})
|
23
|
-
User.class_eval do
|
24
|
-
define_method "gmaps4rails_options" do
|
25
|
-
DEFAULT_CONFIG_HASH.merge(change_conf)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
5
|
set_gmaps4rails_options!
|
31
6
|
|
32
7
|
describe Gmaps4rails::ActsAsGmappable do
|
33
8
|
|
34
9
|
let(:user) { Factory(:user) }
|
35
|
-
let(:invalid_user) {
|
10
|
+
let(:invalid_user) { FactoryGirl.build(:invalid_user) }
|
36
11
|
|
37
12
|
before(:each) do
|
38
|
-
Geocoding.
|
13
|
+
Geocoding.stub_geocoding
|
39
14
|
end
|
40
15
|
|
41
16
|
context "standard configuration, valid user" do
|
42
17
|
|
43
|
-
it "should call google api with http by default" do
|
44
|
-
address = "toulon, france"
|
45
|
-
Gmaps4rails.should_receive(:geocode).with(address, "en", false, "http").and_return [TOULON]
|
46
|
-
User.create(:address => address)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should call google api with https if passed in settings" do
|
50
|
-
set_gmaps4rails_options!({ :protocol => "https" })
|
51
|
-
address = "toulon, france"
|
52
|
-
Gmaps4rails.should_receive(:geocode).with(address, "en", false, "https").and_return [TOULON]
|
53
|
-
User.create(:address => address)
|
54
|
-
set_gmaps4rails_options!({ :protocol => "http" })
|
55
|
-
end
|
56
|
-
|
57
18
|
it "should have a geocoded position" do
|
58
19
|
user.should have_same_position_as TOULON
|
59
20
|
end
|
@@ -61,76 +22,6 @@ describe Gmaps4rails::ActsAsGmappable do
|
|
61
22
|
it "should set boolean to true once user is created" do
|
62
23
|
user.gmaps.should be_true
|
63
24
|
end
|
64
|
-
|
65
|
-
it "should render a valid json from an array of objects" do
|
66
|
-
user #needed trigger the object from the let statement
|
67
|
-
Factory(:user_paris)
|
68
|
-
JSON.parse(User.all.to_gmaps4rails).should == [{ "lng" => TOULON[:longitude], "lat" => TOULON[:latitude] },{"lng" => PARIS[:longitude], "lat" => PARIS[:latitude] } ]
|
69
|
-
end
|
70
|
-
|
71
|
-
context "to_gmaps4rails block" do
|
72
|
-
it "should extend json string for Arrays" do
|
73
|
-
user #needed trigger the object from the let statement
|
74
|
-
Factory(:user_paris)
|
75
|
-
JSON.parse(User.all.to_gmaps4rails do |u, marker|
|
76
|
-
'"model":"' + u.class.to_s + '"'
|
77
|
-
end).should == [{"model" => "User", "lng" => TOULON[:longitude], "lat" => TOULON[:latitude]},{"model" => "User", "lng" => PARIS[:longitude], "lat" => PARIS[:latitude] }]
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should extend json string for Arrays and custom hash" do
|
81
|
-
user #needed trigger the object from the let statement
|
82
|
-
Factory(:user_paris)
|
83
|
-
JSON.parse(User.all.to_gmaps4rails do |u, marker|
|
84
|
-
marker.json({ :model => u.class.to_s })
|
85
|
-
end).should == [{"model" => "User", "lng" => TOULON[:longitude], "lat" => TOULON[:latitude]},{"model" => "User", "lng" => PARIS[:longitude], "lat" => PARIS[:latitude] }]
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should extend json string for a single object" do
|
89
|
-
JSON.parse(user.to_gmaps4rails do |u, marker|
|
90
|
-
"\"model\":\"" + u.class.to_s + "\""
|
91
|
-
end).should == [{ "model" => "User", "lng" =>TOULON[:longitude], "lat" => TOULON[:latitude] }]
|
92
|
-
end
|
93
|
-
|
94
|
-
it "json method should produce same result as raw string" do
|
95
|
-
from_method = JSON.parse(user.to_gmaps4rails do |u, marker|
|
96
|
-
marker.json({ :model => u.class.to_s })
|
97
|
-
end)
|
98
|
-
|
99
|
-
from_string = JSON.parse(user.to_gmaps4rails do |u, marker|
|
100
|
-
"\"model\":\"" + u.class.to_s + "\""
|
101
|
-
end)
|
102
|
-
|
103
|
-
from_string.should eq from_method
|
104
|
-
end
|
105
|
-
|
106
|
-
it "infowindow content should be included in json" do
|
107
|
-
user.to_gmaps4rails do |u, marker|
|
108
|
-
marker.infowindow "in infowindow"
|
109
|
-
end.should include "\"description\":\"in infowindow\""
|
110
|
-
end
|
111
|
-
|
112
|
-
it "marker_picture should be included in json" do
|
113
|
-
user.to_gmaps4rails do |u, marker|
|
114
|
-
marker.picture({
|
115
|
-
:picture => "http://www.blankdots.com/img/github-32x32.png",
|
116
|
-
:width => "32",
|
117
|
-
:height => "32"
|
118
|
-
})
|
119
|
-
end.should include "\"picture\":\"http://www.blankdots.com/img/github-32x32.png\""
|
120
|
-
end
|
121
|
-
|
122
|
-
it "title content should be included in json" do
|
123
|
-
user.to_gmaps4rails do |u, marker|
|
124
|
-
marker.title "i'm the title"
|
125
|
-
end.should include "\"title\":\"i'm the title\""
|
126
|
-
end
|
127
|
-
|
128
|
-
it "sidebar content should be included in json" do
|
129
|
-
user.to_gmaps4rails do |u, marker|
|
130
|
-
marker.sidebar "i'm the sidebar"
|
131
|
-
end.should include "\"sidebar\":\"i'm the sidebar\""
|
132
|
-
end
|
133
|
-
end
|
134
25
|
|
135
26
|
context "process_geocoding" do
|
136
27
|
context "Proc" do
|
@@ -151,7 +42,7 @@ describe Gmaps4rails::ActsAsGmappable do
|
|
151
42
|
DEFAULT_CONFIG_HASH.merge({ :process_geocoding => lambda {|user| true } })
|
152
43
|
end
|
153
44
|
end
|
154
|
-
|
45
|
+
Gmaps4rails.should_receive(:geocode)
|
155
46
|
user.update_attributes(:address => "Strasbourg, france")
|
156
47
|
end
|
157
48
|
|
@@ -171,9 +62,7 @@ describe Gmaps4rails::ActsAsGmappable do
|
|
171
62
|
end
|
172
63
|
end
|
173
64
|
end
|
174
|
-
|
175
|
-
JSON.parse(user.to_gmaps4rails).should == [{"lng" => TOULON[:longitude], "lat" => TOULON[:latitude] }]
|
176
|
-
end
|
65
|
+
|
177
66
|
|
178
67
|
it "should not geocode again after address changes if checker is true" do
|
179
68
|
user.update_attributes({ :address => "Paris, France" })
|
@@ -198,270 +87,99 @@ describe Gmaps4rails::ActsAsGmappable do
|
|
198
87
|
end
|
199
88
|
end
|
200
89
|
|
201
|
-
context "model customization" do
|
202
90
|
|
203
|
-
|
204
|
-
|
91
|
+
context "acts_as_gmappable options" do
|
92
|
+
|
93
|
+
after(:all) do
|
94
|
+
#reset all configuration to default
|
95
|
+
set_gmaps4rails_options!
|
205
96
|
end
|
206
97
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
set_gmaps4rails_options!({ :normalized_address => "sec_address" })
|
227
|
-
user = Factory(:user, :sec_address => "ToUlOn, FrAnCe")
|
228
|
-
user.sec_address.should == "Toulon, France"
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should display the proper error message when address is invalid" do
|
232
|
-
set_gmaps4rails_options!({ :msg => "Custom Address invalid"})
|
233
|
-
invalid_user.should_not be_valid
|
234
|
-
invalid_user.errors[:address].should include("Custom Address invalid")
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should not raise an error if validation option is turned off" do
|
238
|
-
set_gmaps4rails_options!({ :validation => false })
|
239
|
-
invalid_user.should be_valid
|
240
|
-
end
|
241
|
-
|
242
|
-
it "should save longitude and latitude to the customized columns" do
|
243
|
-
set_gmaps4rails_options!({
|
244
|
-
:lat_column => "lat_test",
|
245
|
-
:lng_column => "long_test"
|
246
|
-
})
|
247
|
-
user.latitude.should be_nil
|
248
|
-
user.should have_same_position_as TOULON
|
249
|
-
end
|
250
|
-
|
251
|
-
it "should not save the boolean if check_process is false" do
|
252
|
-
set_gmaps4rails_options!({ :check_process => false })
|
253
|
-
user.gmaps.should be_nil
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should geocode after each save if 'check_process' is false" do
|
257
|
-
set_gmaps4rails_options!({ :check_process => false })
|
258
|
-
user = Factory(:user, :address => "Paris, France")
|
259
|
-
user.should have_same_position_as PARIS
|
260
|
-
end
|
98
|
+
it "should call google api with http by default" do
|
99
|
+
address = "toulon, france"
|
100
|
+
Gmaps4rails.should_receive(:geocode).with(address, "en", false, "http").and_return [TOULON]
|
101
|
+
User.create(:address => address)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should call google api with https if passed in settings" do
|
105
|
+
set_gmaps4rails_options!({ :protocol => "https" })
|
106
|
+
address = "toulon, france"
|
107
|
+
Gmaps4rails.should_receive(:geocode).with(address, "en", false, "https").and_return [TOULON]
|
108
|
+
User.create(:address => address)
|
109
|
+
set_gmaps4rails_options!({ :protocol => "http" })
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should use indifferently a db column for address if passed in config" do
|
113
|
+
set_gmaps4rails_options!({:address => "sec_address"})
|
114
|
+
user = Factory(:user, :sec_address => "Toulon, France")
|
115
|
+
user.should have_same_position_as TOULON
|
116
|
+
end
|
261
117
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
end
|
267
|
-
|
268
|
-
it "should call a callback in the model if asked to" do
|
269
|
-
User.class_eval do
|
270
|
-
def gmaps4rails_options
|
271
|
-
DEFAULT_CONFIG_HASH.merge({ :callback => "save_callback" })
|
272
|
-
end
|
118
|
+
it "should save the normalized address if requested" do
|
119
|
+
set_gmaps4rails_options!({ :normalized_address => "norm_address" })
|
120
|
+
user.norm_address.should == "Toulon, France"
|
121
|
+
end
|
273
122
|
|
274
|
-
|
275
|
-
|
276
|
-
|
123
|
+
it "should override user's address with normalized address if requested" do
|
124
|
+
set_gmaps4rails_options!({ :normalized_address => "sec_address" })
|
125
|
+
user = Factory(:user, :sec_address => "ToUlOn, FrAnCe")
|
126
|
+
user.sec_address.should == "Toulon, France"
|
127
|
+
end
|
277
128
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
129
|
+
it "should display the proper error message when address is invalid" do
|
130
|
+
set_gmaps4rails_options!({ :msg => "Custom Address invalid"})
|
131
|
+
invalid_user.should_not be_valid
|
132
|
+
invalid_user.errors[:address].should include("Custom Address invalid")
|
283
133
|
end
|
284
134
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
user_with_pic.instance_eval do
|
290
|
-
def gmaps4rails_infowindow
|
291
|
-
"My Beautiful Picture: #{picture}"
|
292
|
-
end
|
293
|
-
end
|
294
|
-
user_with_pic.to_gmaps4rails.should include "\"description\":\"My Beautiful Picture: http://www.blankdots.com/img/github-32x32.png\""
|
295
|
-
end
|
296
|
-
|
297
|
-
it "should take into account the picture provided in the model" do
|
298
|
-
user.instance_eval do
|
299
|
-
def gmaps4rails_marker_picture
|
300
|
-
{
|
301
|
-
"picture" => "http://www.blankdots.com/img/github-32x32.png",
|
302
|
-
"width" => "32",
|
303
|
-
"height" => "32"
|
304
|
-
}
|
305
|
-
end
|
306
|
-
end
|
307
|
-
result = user.to_gmaps4rails
|
308
|
-
result.should include "\"picture\":\"http://www.blankdots.com/img/github-32x32.png\""
|
309
|
-
result.should include "\"width\":\"32\""
|
310
|
-
result.should include "\"height\":\"32\""
|
311
|
-
end
|
312
|
-
|
313
|
-
it "should take into account the picture and shadow provided in the model" do
|
314
|
-
user.instance_eval do
|
315
|
-
def gmaps4rails_marker_picture
|
316
|
-
{
|
317
|
-
"picture" => "http://www.blankdots.com/img/github-32x32.png",
|
318
|
-
"width" => "32",
|
319
|
-
"height" => "32",
|
320
|
-
"marker_anchor" => [10, 20],
|
321
|
-
"shadow_picture" => "http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png" ,
|
322
|
-
"shadow_width" => "40",
|
323
|
-
"shadow_height" => "40",
|
324
|
-
"shadow_anchor" => [5, 10]
|
325
|
-
}
|
326
|
-
end
|
327
|
-
end
|
328
|
-
result = user.to_gmaps4rails
|
329
|
-
result.should include "\"shadow_width\":\"40\""
|
330
|
-
result.should include "\"shadow_height\":\"40\""
|
331
|
-
result.should include "\"shadow_picture\":\"http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png\""
|
332
|
-
result.should include "\"shadow_anchor\":[5,10]"
|
333
|
-
result.should include "\"marker_anchor\":[10,20]"
|
334
|
-
end
|
335
|
-
|
336
|
-
it "should take into account the title provided in the model" do
|
337
|
-
user.instance_eval do
|
338
|
-
def gmaps4rails_title
|
339
|
-
"Sweet Title"
|
340
|
-
end
|
341
|
-
end
|
342
|
-
JSON.parse(user.to_gmaps4rails).should == [{"title" => "Sweet Title", "lng" => TOULON[:longitude], "lat" => TOULON[:latitude]}]
|
343
|
-
end
|
344
|
-
|
345
|
-
it "should take into account the sidebar content provided in the model" do
|
346
|
-
user.instance_eval do
|
347
|
-
def gmaps4rails_sidebar
|
348
|
-
"sidebar content"
|
349
|
-
end
|
350
|
-
end
|
351
|
-
user.to_gmaps4rails.should include "\"sidebar\":\"sidebar content\""
|
352
|
-
end
|
135
|
+
it "should not raise an error if validation option is turned off" do
|
136
|
+
set_gmaps4rails_options!({ :validation => false })
|
137
|
+
invalid_user.should be_valid
|
138
|
+
end
|
353
139
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
{
|
362
|
-
"picture" => "http://www.blankdots.com/img/github-32x32.png",
|
363
|
-
"width" => "32",
|
364
|
-
"height" => "32"
|
365
|
-
}
|
366
|
-
end
|
367
|
-
|
368
|
-
def gmaps4rails_title
|
369
|
-
"Sweet Title"
|
370
|
-
end
|
371
|
-
|
372
|
-
def gmaps4rails_sidebar
|
373
|
-
"sidebar content"
|
374
|
-
end
|
375
|
-
end
|
376
|
-
result = user.to_gmaps4rails
|
377
|
-
result.should include "\"description\":\"My Beautiful Picture: \""
|
378
|
-
result.should include "\"title\":\"Sweet Title\""
|
379
|
-
result.should include "\"sidebar\":\"sidebar content\""
|
380
|
-
result.should include "\"picture\":\"http://www.blankdots.com/img/github-32x32.png\""
|
381
|
-
end
|
382
|
-
|
140
|
+
it "should save longitude and latitude to the customized columns" do
|
141
|
+
set_gmaps4rails_options!({
|
142
|
+
:lat_column => "lat_test",
|
143
|
+
:lng_column => "long_test"
|
144
|
+
})
|
145
|
+
user.latitude.should be_nil
|
146
|
+
user.should have_same_position_as TOULON
|
383
147
|
end
|
384
148
|
|
385
|
-
it "
|
386
|
-
|
387
|
-
|
388
|
-
"defined in model"
|
389
|
-
end
|
390
|
-
end
|
391
|
-
user.to_gmaps4rails.should include "defined in model"
|
392
|
-
result = user.to_gmaps4rails do |u, marker|
|
393
|
-
marker.infowindow "defined in block"
|
394
|
-
end
|
395
|
-
result.should include "defined in block"
|
396
|
-
result.should_not include "defined in model"
|
149
|
+
it "should not save the boolean if check_process is false" do
|
150
|
+
set_gmaps4rails_options!({ :check_process => false })
|
151
|
+
user.gmaps.should be_nil
|
397
152
|
end
|
398
|
-
|
399
|
-
it "
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
"picture" => "/model.png",
|
404
|
-
"width" => 32,
|
405
|
-
"height" => 32}
|
406
|
-
end
|
407
|
-
end
|
408
|
-
user.to_gmaps4rails.should include "model.png"
|
409
|
-
result = user.to_gmaps4rails do |u, marker|
|
410
|
-
marker.picture({
|
411
|
-
"picture" => "/block.png",
|
412
|
-
"width" => 32,
|
413
|
-
"height" => 32})
|
414
|
-
end
|
415
|
-
result.should include "block.png"
|
416
|
-
result.should_not include "model.png"
|
153
|
+
|
154
|
+
it "should geocode after each save if 'check_process' is false" do
|
155
|
+
set_gmaps4rails_options!({ :check_process => false })
|
156
|
+
user = Factory(:user, :address => "Paris, France")
|
157
|
+
user.should have_same_position_as PARIS
|
417
158
|
end
|
159
|
+
|
160
|
+
it "should save to the proper boolean checker set in checker" do
|
161
|
+
set_gmaps4rails_options!({ :checker => "bool_test" })
|
162
|
+
user.gmaps.should be_nil
|
163
|
+
user.bool_test.should be_true
|
164
|
+
end
|
418
165
|
|
419
|
-
|
420
|
-
|
421
|
-
describe "eval conditions" do
|
422
|
-
it "should trigger method if symbol passed" do
|
166
|
+
it "should call a callback in the model if asked to" do
|
423
167
|
User.class_eval do
|
424
168
|
def gmaps4rails_options
|
425
|
-
DEFAULT_CONFIG_HASH.merge({ :
|
169
|
+
DEFAULT_CONFIG_HASH.merge({ :callback => "save_callback" })
|
426
170
|
end
|
427
171
|
|
428
|
-
def
|
429
|
-
|
430
|
-
user.should_receive :published?
|
431
|
-
Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation])
|
432
|
-
end
|
433
|
-
|
434
|
-
it "should evaluate lambda if provided" do
|
435
|
-
user.instance_eval do
|
436
|
-
def gmaps4rails_options
|
437
|
-
DEFAULT_CONFIG_HASH.merge({ :validation => lambda { |object| object.test_me(:foo, :bar) } })
|
438
|
-
end
|
439
|
-
|
440
|
-
def test_me(a,b)
|
441
|
-
"#{a}, #{b}"
|
442
|
-
end
|
443
|
-
end
|
444
|
-
user.should_receive(:test_me).with(:foo, :bar)
|
445
|
-
Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation])
|
446
|
-
end
|
447
|
-
|
448
|
-
it "should simply accept a true value" do
|
449
|
-
user.instance_eval do
|
450
|
-
def gmaps4rails_options
|
451
|
-
DEFAULT_CONFIG_HASH.merge({ :validation => true })
|
172
|
+
def save_callback(data)
|
173
|
+
self.called_back = true
|
452
174
|
end
|
175
|
+
|
176
|
+
attr_accessor :called_back
|
453
177
|
end
|
454
|
-
|
178
|
+
user.called_back.should be_true
|
455
179
|
end
|
456
180
|
|
457
|
-
it "should simply accept a false value" do
|
458
|
-
user.instance_eval do
|
459
|
-
def gmaps4rails_options
|
460
|
-
DEFAULT_CONFIG_HASH.merge({ :validation => false })
|
461
|
-
end
|
462
|
-
end
|
463
|
-
Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation]).should be_false
|
464
|
-
end
|
465
181
|
end
|
466
182
|
|
183
|
+
|
184
|
+
|
467
185
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,6 +10,7 @@ Spork.prefork do
|
|
10
10
|
require 'factory_girl_rails'
|
11
11
|
require 'database_cleaner'
|
12
12
|
require "jasmine"
|
13
|
+
require 'webmock/rspec'
|
13
14
|
|
14
15
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f }
|
15
16
|
FactoryGirl.definition_file_paths = [ File.join(Rails.root, '../factories') ]
|
data/spec/support/geocoding.rb
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
module Geocoding
|
2
|
-
|
2
|
+
|
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 => "address",
|
11
|
+
:language => "en",
|
12
|
+
:protocol => "http",
|
13
|
+
:process_geocoding => true
|
14
|
+
}
|
15
|
+
|
16
|
+
PARIS = { :latitude => 48.856614, :longitude => 2.3522219 }
|
17
|
+
TOULON = { :latitude => 43.124228, :longitude => 5.928 }
|
18
|
+
|
19
|
+
#set model configuration
|
20
|
+
def set_gmaps4rails_options!(change_conf = {})
|
21
|
+
User.class_eval do
|
22
|
+
define_method "gmaps4rails_options" do
|
23
|
+
DEFAULT_CONFIG_HASH.merge(change_conf)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.stub_geocoding
|
3
29
|
Gmaps4rails.stub(:geocode) do |*args|
|
4
30
|
case args[0]
|
5
31
|
when "Paris, France"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmaps4rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-08-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -204,6 +204,22 @@ dependencies:
|
|
204
204
|
- - ! '>='
|
205
205
|
- !ruby/object:Gem::Version
|
206
206
|
version: '0'
|
207
|
+
- !ruby/object:Gem::Dependency
|
208
|
+
name: webmock
|
209
|
+
requirement: !ruby/object:Gem::Requirement
|
210
|
+
none: false
|
211
|
+
requirements:
|
212
|
+
- - ! '>='
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '0'
|
215
|
+
type: :development
|
216
|
+
prerelease: false
|
217
|
+
version_requirements: !ruby/object:Gem::Requirement
|
218
|
+
none: false
|
219
|
+
requirements:
|
220
|
+
- - ! '>='
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
207
223
|
- !ruby/object:Gem::Dependency
|
208
224
|
name: pry
|
209
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -248,14 +264,17 @@ files:
|
|
248
264
|
- lib/generators/templates/README
|
249
265
|
- lib/gmaps4rails.rb
|
250
266
|
- lib/gmaps4rails/acts_as_gmappable.rb
|
267
|
+
- lib/gmaps4rails/api_wrappers/base_net_methods.rb
|
268
|
+
- lib/gmaps4rails/api_wrappers/direction.rb
|
269
|
+
- lib/gmaps4rails/api_wrappers/geocoder.rb
|
270
|
+
- lib/gmaps4rails/api_wrappers/places.rb
|
251
271
|
- lib/gmaps4rails/base.rb
|
252
|
-
- lib/gmaps4rails/extensions/
|
272
|
+
- lib/gmaps4rails/extensions/enumerable.rb
|
253
273
|
- lib/gmaps4rails/extensions/hash.rb
|
254
|
-
- lib/gmaps4rails/geocoding.rb
|
255
|
-
- lib/gmaps4rails/google_places.rb
|
256
274
|
- lib/gmaps4rails/helper/gmaps4rails_helper.rb
|
257
275
|
- lib/gmaps4rails/js_builder.rb
|
258
276
|
- lib/gmaps4rails/json_builder.rb
|
277
|
+
- lib/gmaps4rails/model_handler.rb
|
259
278
|
- lib/gmaps4rails/version.rb
|
260
279
|
- lib/gmaps4rails/view_helper.rb
|
261
280
|
- lib/tasks/gmaps4rails_tasks.rake
|
@@ -266,8 +285,6 @@ files:
|
|
266
285
|
- public/javascripts/gmaps4rails/gmaps4rails.mapquest.js
|
267
286
|
- public/javascripts/gmaps4rails/gmaps4rails.openlayers.js
|
268
287
|
- public/stylesheets/gmaps4rails.css
|
269
|
-
- spec/base/base_spec.rb
|
270
|
-
- spec/base/geocoding_spec.rb
|
271
288
|
- spec/dummy/.gitignore
|
272
289
|
- spec/dummy/.rspec
|
273
290
|
- spec/dummy/README.rdoc
|
@@ -316,6 +333,10 @@ files:
|
|
316
333
|
- spec/dummy/public/logo.png
|
317
334
|
- spec/dummy/script/rails
|
318
335
|
- spec/factories/user_factory.rb
|
336
|
+
- spec/fixtures/google_direction_valid.json
|
337
|
+
- spec/fixtures/google_geocoding_toulon_france.json
|
338
|
+
- spec/fixtures/google_places_valid.json
|
339
|
+
- spec/fixtures/google_wrong_geocoding.json
|
319
340
|
- spec/javascripts/basic_methods_spec.js
|
320
341
|
- spec/javascripts/helpers/.gitkeep
|
321
342
|
- spec/javascripts/helpers/SpecHelper.js
|
@@ -328,6 +349,12 @@ files:
|
|
328
349
|
- spec/launchers/all_but_requests.rb
|
329
350
|
- spec/launchers/all_specs.rb
|
330
351
|
- spec/launchers/requests.rb
|
352
|
+
- spec/lib/base_spec.rb
|
353
|
+
- spec/lib/direction_spec.rb
|
354
|
+
- spec/lib/geocoder_spec.rb
|
355
|
+
- spec/lib/js_builder_spec.rb
|
356
|
+
- spec/lib/json_builder_spec.rb
|
357
|
+
- spec/lib/places_spec.rb
|
331
358
|
- spec/models/user_spec.rb
|
332
359
|
- spec/spec_helper.rb
|
333
360
|
- spec/support/geocoding.rb
|
@@ -346,7 +373,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
346
373
|
version: '0'
|
347
374
|
segments:
|
348
375
|
- 0
|
349
|
-
hash:
|
376
|
+
hash: 1278605755338962365
|
350
377
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
351
378
|
none: false
|
352
379
|
requirements:
|
@@ -355,16 +382,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
355
382
|
version: '0'
|
356
383
|
segments:
|
357
384
|
- 0
|
358
|
-
hash:
|
385
|
+
hash: 1278605755338962365
|
359
386
|
requirements: []
|
360
387
|
rubyforge_project:
|
361
|
-
rubygems_version: 1.8.
|
388
|
+
rubygems_version: 1.8.24
|
362
389
|
signing_key:
|
363
390
|
specification_version: 3
|
364
391
|
summary: Maps made easy for Rails 3
|
365
392
|
test_files:
|
366
|
-
- spec/base/base_spec.rb
|
367
|
-
- spec/base/geocoding_spec.rb
|
368
393
|
- spec/dummy/.gitignore
|
369
394
|
- spec/dummy/.rspec
|
370
395
|
- spec/dummy/README.rdoc
|
@@ -413,6 +438,10 @@ test_files:
|
|
413
438
|
- spec/dummy/public/logo.png
|
414
439
|
- spec/dummy/script/rails
|
415
440
|
- spec/factories/user_factory.rb
|
441
|
+
- spec/fixtures/google_direction_valid.json
|
442
|
+
- spec/fixtures/google_geocoding_toulon_france.json
|
443
|
+
- spec/fixtures/google_places_valid.json
|
444
|
+
- spec/fixtures/google_wrong_geocoding.json
|
416
445
|
- spec/javascripts/basic_methods_spec.js
|
417
446
|
- spec/javascripts/helpers/.gitkeep
|
418
447
|
- spec/javascripts/helpers/SpecHelper.js
|
@@ -425,6 +454,12 @@ test_files:
|
|
425
454
|
- spec/launchers/all_but_requests.rb
|
426
455
|
- spec/launchers/all_specs.rb
|
427
456
|
- spec/launchers/requests.rb
|
457
|
+
- spec/lib/base_spec.rb
|
458
|
+
- spec/lib/direction_spec.rb
|
459
|
+
- spec/lib/geocoder_spec.rb
|
460
|
+
- spec/lib/js_builder_spec.rb
|
461
|
+
- spec/lib/json_builder_spec.rb
|
462
|
+
- spec/lib/places_spec.rb
|
428
463
|
- spec/models/user_spec.rb
|
429
464
|
- spec/spec_helper.rb
|
430
465
|
- spec/support/geocoding.rb
|