gmaps4rails 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile.lock +7 -1
  3. data/README.rdoc +2 -2
  4. data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +37 -96
  5. data/app/assets/javascripts/gmaps4rails/gmaps4rails.bing.js.coffee +11 -0
  6. data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +85 -9
  7. data/app/assets/javascripts/gmaps4rails/gmaps4rails.mapquest.js.coffee +13 -2
  8. data/app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee +54 -2
  9. data/app/views/gmaps4rails/_gmaps4rails.html.erb +1 -1
  10. data/gmaps4rails.gemspec +1 -0
  11. data/lib/generators/gmaps4rails/install_generator.rb +28 -12
  12. data/lib/gmaps4rails/acts_as_gmappable.rb +3 -46
  13. data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +40 -0
  14. data/lib/gmaps4rails/api_wrappers/direction.rb +87 -0
  15. data/lib/gmaps4rails/api_wrappers/geocoder.rb +54 -0
  16. data/lib/gmaps4rails/api_wrappers/places.rb +74 -0
  17. data/lib/gmaps4rails/base.rb +80 -22
  18. data/lib/gmaps4rails/extensions/{array.rb → enumerable.rb} +1 -1
  19. data/lib/gmaps4rails/js_builder.rb +9 -17
  20. data/lib/gmaps4rails/json_builder.rb +1 -7
  21. data/lib/gmaps4rails/model_handler.rb +79 -0
  22. data/lib/gmaps4rails/version.rb +1 -1
  23. data/lib/gmaps4rails/view_helper.rb +4 -6
  24. data/public/javascripts/gmaps4rails/gmaps4rails.base.js +35 -112
  25. data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +12 -0
  26. data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +123 -7
  27. data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +12 -0
  28. data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +53 -2
  29. data/spec/dummy/app/views/users/index.html.erb +88 -85
  30. data/spec/fixtures/google_direction_valid.json +65 -0
  31. data/spec/fixtures/google_geocoding_toulon_france.json +58 -0
  32. data/spec/fixtures/google_places_valid.json +45 -0
  33. data/spec/fixtures/google_wrong_geocoding.json +4 -0
  34. data/spec/lib/base_spec.rb +59 -0
  35. data/spec/lib/direction_spec.rb +53 -0
  36. data/spec/lib/geocoder_spec.rb +46 -0
  37. data/spec/{base/base_spec.rb → lib/js_builder_spec.rb} +0 -6
  38. data/spec/lib/json_builder_spec.rb +232 -0
  39. data/spec/lib/places_spec.rb +25 -0
  40. data/spec/models/user_spec.rb +75 -357
  41. data/spec/spec_helper.rb +1 -0
  42. data/spec/support/geocoding.rb +27 -1
  43. metadata +47 -12
  44. data/lib/gmaps4rails/geocoding.rb +0 -113
  45. data/lib/gmaps4rails/google_places.rb +0 -76
  46. data/spec/base/geocoding_spec.rb +0 -17
@@ -0,0 +1,65 @@
1
+ {
2
+ "status": "OK",
3
+ "routes": [ {
4
+ "summary": "I-40 W",
5
+ "legs": [ {
6
+ "steps": [ {
7
+ "travel_mode": "DRIVING",
8
+ "start_location": {
9
+ "lat": 41.8507300,
10
+ "lng": -87.6512600
11
+ },
12
+ "end_location": {
13
+ "lat": 41.8525800,
14
+ "lng": -87.6514100
15
+ },
16
+ "polyline": {
17
+ "points": "a~l~Fjk~uOwHJy@P"
18
+ },
19
+ "duration": {
20
+ "value": 19,
21
+ "text": "1 min"
22
+ },
23
+ "html_instructions": "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eS Morgan St\u003c/b\u003e toward \u003cb\u003eW Cermak Rd\u003c/b\u003e",
24
+ "distance": {
25
+ "value": 207,
26
+ "text": "0.1 mi"
27
+ }
28
+ }],
29
+ "duration": {
30
+ "value": 74384,
31
+ "text": "20 hours 40 mins"
32
+ },
33
+ "distance": {
34
+ "value": 2137146,
35
+ "text": "1,328 mi"
36
+ },
37
+ "start_location": {
38
+ "lat": 35.4675602,
39
+ "lng": -97.5164276
40
+ },
41
+ "end_location": {
42
+ "lat": 34.0522342,
43
+ "lng": -118.2436849
44
+ },
45
+ "start_address": "Oklahoma City, OK, USA",
46
+ "end_address": "Los Angeles, CA, USA"
47
+ } ],
48
+ "copyrights": "Map data ©2010 Google, Sanborn",
49
+ "overview_polyline": {
50
+ "points": "a~l~Fjk~uOnzh@vlbBtc~@tsE`vnApw{A`dw@~w\\|tNtqf@l{Yd_Fblh@rxo@b}@xxSfytAblk@xxaBeJxlcBb~t@zbh@jc|Bx}C`rv@rw|@rlhA~dVzeo@vrSnc}Axf]fjz@xfFbw~@dz{A~d{A|zOxbrBbdUvpo@`cFp~xBc`Hk@nurDznmFfwMbwz@bbl@lq~@loPpxq@bw_@v|{CbtY~jGqeMb{iF|n\\~mbDzeVh_Wr|Efc\\x`Ij{kE}mAb~uF{cNd}xBjp]fulBiwJpgg@|kHntyArpb@bijCk_Kv~eGyqTj_|@`uV`k|DcsNdwxAott@r}q@_gc@nu`CnvHx`k@dse@j|p@zpiAp|gEicy@`omFvaErfo@igQxnlApqGze~AsyRzrjAb__@ftyB}pIlo_BflmA~yQftNboWzoAlzp@mz`@|}_@fda@jakEitAn{fB_a]lexClshBtmqAdmY_hLxiZd~XtaBndgC"
51
+ },
52
+ "warnings": [ ],
53
+ "waypoint_order": [ 0, 1 ],
54
+ "bounds": {
55
+ "southwest": {
56
+ "lat": 34.0523600,
57
+ "lng": -118.2435600
58
+ },
59
+ "northeast": {
60
+ "lat": 41.8781100,
61
+ "lng": -87.6297900
62
+ }
63
+ }
64
+ } ]
65
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "results" : [
3
+ {
4
+ "address_components" : [
5
+ {
6
+ "long_name" : "Toulon",
7
+ "short_name" : "Toulon",
8
+ "types" : [ "locality", "political" ]
9
+ },
10
+ {
11
+ "long_name" : "Département Var",
12
+ "short_name" : "83",
13
+ "types" : [ "administrative_area_level_2", "political" ]
14
+ },
15
+ {
16
+ "long_name" : "Provence-Alpes-Côte d'Azur",
17
+ "short_name" : "PACA",
18
+ "types" : [ "administrative_area_level_1", "political" ]
19
+ },
20
+ {
21
+ "long_name" : "France",
22
+ "short_name" : "FR",
23
+ "types" : [ "country", "political" ]
24
+ }
25
+ ],
26
+ "formatted_address" : "Toulon, France",
27
+ "geometry" : {
28
+ "bounds" : {
29
+ "northeast" : {
30
+ "lat" : 43.1716730,
31
+ "lng" : 5.987382999999999
32
+ },
33
+ "southwest" : {
34
+ "lat" : 43.1010490,
35
+ "lng" : 5.8794790
36
+ }
37
+ },
38
+ "location" : {
39
+ "lat" : 43.1242280,
40
+ "lng" : 5.9280
41
+ },
42
+ "location_type" : "APPROXIMATE",
43
+ "viewport" : {
44
+ "northeast" : {
45
+ "lat" : 43.1567950,
46
+ "lng" : 5.99202970
47
+ },
48
+ "southwest" : {
49
+ "lat" : 43.09164370,
50
+ "lng" : 5.86397030
51
+ }
52
+ }
53
+ },
54
+ "types" : [ "locality", "political" ]
55
+ }
56
+ ],
57
+ "status" : "OK"
58
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "html_attributions" : [
3
+ "Listings by \u003ca href=\"http://www.yellowpages.com.au/\"\u003eYellow Pages\u003c/a\u003e"
4
+ ],
5
+ "results" : [
6
+ {
7
+ "geometry" : {
8
+ "location" : {
9
+ "lat" : -33.8719830,
10
+ "lng" : 151.1990860
11
+ }
12
+ },
13
+ "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
14
+ "id" : "677679492a58049a7eae079e0890897eb953d79b",
15
+ "name" : "Zaaffran Restaurant - BBQ and GRILL, Darling Harbour",
16
+ "rating" : 3.90,
17
+ "reference" : "CpQBjAAAAHDHuimUQATR6gfoWNmZlk5dKUKq_n46BpSzPQCjk1m9glTKkiAHH_Gs4xGttdOSj35WJJDAV90dAPnNnZK2OaxMgogdeHKQhIedh6UduFrW53wtwXigUfpAzsCgIzYNI0UQtCj38cr_DE56RH4Wi9d2bWbbIuRyDX6tx2Fmk2EQzO_lVJ-oq4ZY5uI6I75RnxIQJ6smWUVVIHup9Jvc517DKhoUidfNPyQZZIgGiXS_SwGQ1wg0gtc",
18
+ "types" : [ "restaurant", "food", "establishment" ],
19
+ "vicinity" : "Harbourside Centre 10 Darling Drive, Darling Harbour, Sydney"
20
+ },
21
+ {
22
+ "geometry" : {
23
+ "location" : {
24
+ "lat" : -33.8722580,
25
+ "lng" : 151.1986550
26
+ }
27
+ },
28
+ "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
29
+ "id" : "27ea39c8fed1c0437069066b8dccf958a2d06f19",
30
+ "name" : "Criniti's Darling Harbour",
31
+ "rating" : 3.60,
32
+ "reference" : "CnRwAAAA-5kh5WZ3m1CMTO3LslvhRtAYsrOcQP7wB9AE1bV5R6Bd46NN5wB16MtImXWQ9eS1nWVbV_j-8iXYXRpU13Efp1t_d-Dp4WfEsFcYj-_g6db1SC1vAukyeCyotjS5xrwhzqWWAhgmA4qIliWeev2u1BIQprWzxl_hkj_w3QdTiUBYKxoUDVTjF4RugJdaJWkC4n6w6pSajKw",
33
+ "types" : [ "restaurant", "food", "establishment" ],
34
+ "vicinity" : "Shop 461, 2-10 Darling Drive, Harbourside Shopping Centre, DARLING HARBOUR",
35
+ "events" : [
36
+ {
37
+ "event_id" : "7lH_gK1GphU",
38
+ "summary" : "Google Maps Developer Meetup: Rockin' out with the Places API",
39
+ "url" : "https://developers.google.com/maps/documentation/places"
40
+ }
41
+ ]
42
+ }
43
+ ],
44
+ "status" : "OK"
45
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "results" : [],
3
+ "status" : "ZERO_RESULTS"
4
+ }
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ include Geocoding
4
+
5
+ set_gmaps4rails_options!
6
+
7
+ describe "condition_eval" do
8
+
9
+ let(:user) { Factory(:user) }
10
+
11
+ before(:each) do
12
+ Geocoding.stub_geocoding
13
+ end
14
+
15
+ it "should trigger method if symbol passed" do
16
+ User.class_eval do
17
+ def gmaps4rails_options
18
+ DEFAULT_CONFIG_HASH.merge({ :validation => :published? })
19
+ end
20
+
21
+ def published?; true; end
22
+ end
23
+ user.should_receive :published?
24
+ Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation])
25
+ end
26
+
27
+ it "should evaluate lambda if provided" do
28
+ user.instance_eval do
29
+ def gmaps4rails_options
30
+ DEFAULT_CONFIG_HASH.merge({ :validation => lambda { |object| object.test_me(:foo, :bar) } })
31
+ end
32
+
33
+ def test_me(a,b)
34
+ "#{a}, #{b}"
35
+ end
36
+ end
37
+ user.should_receive(:test_me).with(:foo, :bar)
38
+ Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation])
39
+ end
40
+
41
+ it "should simply accept a true value" do
42
+ user.instance_eval do
43
+ def gmaps4rails_options
44
+ DEFAULT_CONFIG_HASH.merge({ :validation => true })
45
+ end
46
+ end
47
+ Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation]).should be_true
48
+ end
49
+
50
+ it "should simply accept a false value" do
51
+ user.instance_eval do
52
+ def gmaps4rails_options
53
+ DEFAULT_CONFIG_HASH.merge({ :validation => false })
54
+ end
55
+ end
56
+ Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation]).should be_false
57
+ end
58
+ end
59
+
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Direction" do
4
+
5
+ let(:geocoding) { File.read "spec/fixtures/google_direction_valid.json" }
6
+
7
+ context "valid request" do
8
+ before(:each) do
9
+ stub_request(:get, "http://maps.googleapis.com/maps/api/directions/json?destination=stubbed&language=en&origin=stubbed&sensor=false").
10
+ to_return(:status => 200, :body => geocoding, :headers => {})
11
+ end
12
+
13
+ it "should render info from only start_end args" do
14
+ result = Gmaps4rails.destination( {:from => "stubbed", :to => "stubbed"})
15
+ result.should eq([
16
+ {
17
+ "duration" => { "text" => "20 hours 40 mins", "value" => 74384.0 },
18
+ "distance" => { "text" => "1,328 mi", "value" => 2137146.0 },
19
+ "steps" => [
20
+ { "travel_mode" => "DRIVING",
21
+ "start_location" => { "lat" => 41.85073, "lng" => -87.65126 },
22
+ "end_location" => { "lat" => 41.85258, "lng" => -87.65141 },
23
+ "duration" => { "value" => 19, "text" => "1 min" },
24
+ "html_instructions" => "Head <b>north</b> on <b>S Morgan St</b> toward <b>W Cermak Rd</b>",
25
+ "distance" => { "value" => 207, "text" => "0.1 mi" }
26
+ }
27
+ ],
28
+ "polylines" =>"[{\"coded_array\":\"a~l~Fjk~uOwHJy@P\"}]"
29
+ }
30
+ ])
31
+ end
32
+
33
+ it "should clean output" do
34
+ result = Gmaps4rails.destination( {:from => "stubbed", :to => "stubbed"}, {}, "clean")
35
+ result.should eq([
36
+ {
37
+ "duration" => { "text" => "20 hours 40 mins", "value" => 74384.0 },
38
+ "distance" => { "text" => "1,328 mi", "value" => 2137146.0 },
39
+ "steps" => [
40
+ { "travel_mode" => "DRIVING",
41
+ "start_location" => { "lat" => 41.85073, "lng" => -87.65126 },
42
+ "end_location" => { "lat" => 41.85258, "lng" => -87.65141 },
43
+ "duration" => { "value" => 19, "text" => "1 min" },
44
+ "html_instructions" => "Head <b>north</b> on <b>S Morgan St</b> toward <b>W Cermak Rd</b>",
45
+ "distance" => { "value" => 207, "text" => "0.1 mi" }
46
+ }
47
+ ]
48
+ }
49
+ ])
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Geocode" do
4
+
5
+ context "data extraction from google's json" do
6
+
7
+ let(:result) { Gmaps4rails.geocode("stubbed").first }
8
+ let(:geocoding) { File.read "spec/fixtures/google_geocoding_toulon_france.json" }
9
+
10
+ before(:each) do
11
+ stub_request(:get, "http://maps.googleapis.com/maps/api/geocode/json?address=stubbed&language=en&sensor=false").
12
+ to_return(:status => 200, :body => geocoding, :headers => {})
13
+ end
14
+
15
+ it "should extract lat and lng" do
16
+ result[:lat].should eq 43.1242280
17
+ result[:lng].should eq 5.9280
18
+ end
19
+
20
+ it "should extract matched address" do
21
+ result[:matched_address].should eq "Toulon, France"
22
+ end
23
+
24
+ end
25
+
26
+ context "expected errors" do
27
+
28
+ it "should raise an error when geocoding has no answer" do
29
+ wrong_geocoding = File.read "spec/fixtures/google_wrong_geocoding.json"
30
+ stub_request(:get, "http://maps.googleapis.com/maps/api/geocode/json?address=stubbed&language=en&sensor=false").
31
+ to_return(:status => 200, :body => wrong_geocoding, :headers => {})
32
+
33
+ lambda { Gmaps4rails.geocode("stubbed")}.should raise_error Gmaps4rails::GeocodeStatus
34
+ end
35
+
36
+ it "should raise an error when google server fails" do
37
+ stub_request(:get, "http://maps.googleapis.com/maps/api/geocode/json?address=stubbed&language=en&sensor=false").
38
+ to_return(:status => 404, :body => "", :headers => {})
39
+
40
+ lambda { Gmaps4rails.geocode("stubbed")}.should raise_error Gmaps4rails::GeocodeNetStatus
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
@@ -137,9 +137,3 @@ describe "to_gmaps4rails for hash" do
137
137
  end
138
138
 
139
139
  end
140
-
141
- describe "Destination" do
142
- it "should render info from only start_end args"
143
- it "should accept all options properly"
144
- it "should format output in accordance with 'output' variable"
145
- end
@@ -0,0 +1,232 @@
1
+ require 'spec_helper'
2
+
3
+ include Geocoding
4
+
5
+ set_gmaps4rails_options!
6
+
7
+ describe "Json Builder" do
8
+
9
+ before(:each) do
10
+ Geocoding.stub_geocoding
11
+ end
12
+
13
+ it "should render a valid json even if there is no instance in the db" do
14
+ User.all.to_gmaps4rails.should == "[]"
15
+ end
16
+
17
+ context "standard configuration, valid user" do
18
+ let!(:user) { Factory(:user) }
19
+
20
+ it "should render a valid json from an array of objects" do
21
+ Factory(:user_paris)
22
+ JSON.parse(User.all.to_gmaps4rails).should == [{ "lng" => TOULON[:longitude], "lat" => TOULON[:latitude] },{"lng" => PARIS[:longitude], "lat" => PARIS[:latitude] } ]
23
+ end
24
+
25
+ it "should render a valid json from a single object" do
26
+ JSON.parse(user.to_gmaps4rails).should == [{"lng" => TOULON[:longitude], "lat" => TOULON[:latitude] }]
27
+ end
28
+
29
+ describe "to_gmaps4rails block" do
30
+ it "should extend json string for Arrays" do
31
+ Factory(:user_paris)
32
+ JSON.parse(User.all.to_gmaps4rails do |u, marker|
33
+ '"model":"' + u.class.to_s + '"'
34
+ end).should == [{"model" => "User", "lng" => TOULON[:longitude], "lat" => TOULON[:latitude]},{"model" => "User", "lng" => PARIS[:longitude], "lat" => PARIS[:latitude] }]
35
+ end
36
+
37
+ it "should extend json string for Arrays and custom hash" do
38
+ Factory(:user_paris)
39
+ JSON.parse(User.all.to_gmaps4rails do |u, marker|
40
+ marker.json({ :model => u.class.to_s })
41
+ end).should == [{"model" => "User", "lng" => TOULON[:longitude], "lat" => TOULON[:latitude]},{"model" => "User", "lng" => PARIS[:longitude], "lat" => PARIS[:latitude] }]
42
+ end
43
+
44
+ it "should extend json string for a single object" do
45
+ JSON.parse(user.to_gmaps4rails do |u, marker|
46
+ "\"model\":\"" + u.class.to_s + "\""
47
+ end).should == [{ "model" => "User", "lng" =>TOULON[:longitude], "lat" => TOULON[:latitude] }]
48
+ end
49
+
50
+ it "json method should produce same result as raw string" do
51
+ from_method = JSON.parse(user.to_gmaps4rails do |u, marker|
52
+ marker.json({ :model => u.class.to_s })
53
+ end)
54
+
55
+ from_string = JSON.parse(user.to_gmaps4rails do |u, marker|
56
+ "\"model\":\"" + u.class.to_s + "\""
57
+ end)
58
+
59
+ from_string.should eq from_method
60
+ end
61
+
62
+ it "infowindow content should be included in json" do
63
+ user.to_gmaps4rails do |u, marker|
64
+ marker.infowindow "in infowindow"
65
+ end.should include "\"description\":\"in infowindow\""
66
+ end
67
+
68
+ it "marker_picture should be included in json" do
69
+ user.to_gmaps4rails do |u, marker|
70
+ marker.picture({
71
+ :picture => "http://www.blankdots.com/img/github-32x32.png",
72
+ :width => "32",
73
+ :height => "32"
74
+ })
75
+ end.should include "\"picture\":\"http://www.blankdots.com/img/github-32x32.png\""
76
+ end
77
+
78
+ it "title content should be included in json" do
79
+ user.to_gmaps4rails do |u, marker|
80
+ marker.title "i'm the title"
81
+ end.should include "\"title\":\"i'm the title\""
82
+ end
83
+
84
+ it "sidebar content should be included in json" do
85
+ user.to_gmaps4rails do |u, marker|
86
+ marker.sidebar "i'm the sidebar"
87
+ end.should include "\"sidebar\":\"i'm the sidebar\""
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ context "model customization" do
94
+ let(:user) { Factory(:user) }
95
+
96
+ context "instance methods" do
97
+ let(:user_with_pic) { Factory(:user_with_pic) }
98
+
99
+ it "should take into account the description provided in the model" do
100
+ user_with_pic.instance_eval do
101
+ def gmaps4rails_infowindow
102
+ "My Beautiful Picture: #{picture}"
103
+ end
104
+ end
105
+ user_with_pic.to_gmaps4rails.should include "\"description\":\"My Beautiful Picture: http://www.blankdots.com/img/github-32x32.png\""
106
+ end
107
+
108
+ it "should take into account the picture provided in the model" do
109
+ user.instance_eval do
110
+ def gmaps4rails_marker_picture
111
+ {
112
+ "picture" => "http://www.blankdots.com/img/github-32x32.png",
113
+ "width" => "32",
114
+ "height" => "32"
115
+ }
116
+ end
117
+ end
118
+ result = user.to_gmaps4rails
119
+ result.should include "\"picture\":\"http://www.blankdots.com/img/github-32x32.png\""
120
+ result.should include "\"width\":\"32\""
121
+ result.should include "\"height\":\"32\""
122
+ end
123
+
124
+ it "should take into account the picture and shadow provided in the model" do
125
+ user.instance_eval do
126
+ def gmaps4rails_marker_picture
127
+ {
128
+ "picture" => "http://www.blankdots.com/img/github-32x32.png",
129
+ "width" => "32",
130
+ "height" => "32",
131
+ "marker_anchor" => [10, 20],
132
+ "shadow_picture" => "http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png" ,
133
+ "shadow_width" => "40",
134
+ "shadow_height" => "40",
135
+ "shadow_anchor" => [5, 10]
136
+ }
137
+ end
138
+ end
139
+ result = user.to_gmaps4rails
140
+ result.should include "\"shadow_width\":\"40\""
141
+ result.should include "\"shadow_height\":\"40\""
142
+ result.should include "\"shadow_picture\":\"http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png\""
143
+ result.should include "\"shadow_anchor\":[5,10]"
144
+ result.should include "\"marker_anchor\":[10,20]"
145
+ end
146
+
147
+ it "should take into account the title provided in the model" do
148
+ user.instance_eval do
149
+ def gmaps4rails_title
150
+ "Sweet Title"
151
+ end
152
+ end
153
+ JSON.parse(user.to_gmaps4rails).should == [{"title" => "Sweet Title", "lng" => TOULON[:longitude], "lat" => TOULON[:latitude]}]
154
+ end
155
+
156
+ it "should take into account the sidebar content provided in the model" do
157
+ user.instance_eval do
158
+ def gmaps4rails_sidebar
159
+ "sidebar content"
160
+ end
161
+ end
162
+ user.to_gmaps4rails.should include "\"sidebar\":\"sidebar content\""
163
+ end
164
+
165
+ it "should take into account all additional data provided in the model" do
166
+ user.instance_eval do
167
+ def gmaps4rails_infowindow
168
+ "My Beautiful Picture: #{picture}"
169
+ end
170
+
171
+ def gmaps4rails_marker_picture
172
+ {
173
+ "picture" => "http://www.blankdots.com/img/github-32x32.png",
174
+ "width" => "32",
175
+ "height" => "32"
176
+ }
177
+ end
178
+
179
+ def gmaps4rails_title
180
+ "Sweet Title"
181
+ end
182
+
183
+ def gmaps4rails_sidebar
184
+ "sidebar content"
185
+ end
186
+ end
187
+ result = user.to_gmaps4rails
188
+ result.should include "\"description\":\"My Beautiful Picture: \""
189
+ result.should include "\"title\":\"Sweet Title\""
190
+ result.should include "\"sidebar\":\"sidebar content\""
191
+ result.should include "\"picture\":\"http://www.blankdots.com/img/github-32x32.png\""
192
+ end
193
+
194
+ end
195
+
196
+ it "block info should take precedence over model methods" do
197
+ user.instance_eval do
198
+ def gmaps4rails_infowindow
199
+ "defined in model"
200
+ end
201
+ end
202
+ user.to_gmaps4rails.should include "defined in model"
203
+ result = user.to_gmaps4rails do |u, marker|
204
+ marker.infowindow "defined in block"
205
+ end
206
+ result.should include "defined in block"
207
+ result.should_not include "defined in model"
208
+ end
209
+
210
+ it "block info should take precedence over model methods, particular case: picture" do
211
+ user.instance_eval do
212
+ def gmaps4rails_marker_picture
213
+ {
214
+ "picture" => "/model.png",
215
+ "width" => 32,
216
+ "height" => 32}
217
+ end
218
+ end
219
+ user.to_gmaps4rails.should include "model.png"
220
+ result = user.to_gmaps4rails do |u, marker|
221
+ marker.picture({
222
+ "picture" => "/block.png",
223
+ "width" => 32,
224
+ "height" => 32})
225
+ end
226
+ result.should include "block.png"
227
+ result.should_not include "model.png"
228
+ end
229
+
230
+ end
231
+
232
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Places" do
4
+
5
+ let(:places) { File.read "spec/fixtures/google_places_valid.json" }
6
+
7
+ context "valid request" do
8
+ before(:each) do
9
+ stub_request(:get, "https://maps.googleapis.com/maps/api/place/search/json?key=key&language=en&location=0,0&radius=7500&sensor=false").
10
+ to_return(:status => 200, :body => places, :headers => {})
11
+ end
12
+
13
+ it "does something" do
14
+ results = Gmaps4rails.places(0, 0, "key")
15
+ result = OpenStruct.new results.first
16
+
17
+ result.lat.should eq -33.871983
18
+ result.lng.should eq 151.199086
19
+ result.name.should eq "Zaaffran Restaurant - BBQ and GRILL, Darling Harbour"
20
+ result.reference.should =~ /^CpQBjAAAAHDHuimUQATR6gfoWNm.*/
21
+ result.vicinity.should eq "Harbourside Centre 10 Darling Drive, Darling Harbour, Sydney"
22
+ end
23
+
24
+ end
25
+ end