gmaps4rails 2.0.0.pre → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/.travis.yml +2 -4
  2. data/Gemfile +5 -1
  3. data/Gemfile.lock +31 -113
  4. data/README.rdoc +53 -70
  5. data/Rakefile +21 -1
  6. data/gmaps4rails.gemspec +4 -19
  7. data/js_compilation/gmaps_google.js +961 -0
  8. data/lib/generators/gmaps4rails/copy_coffee_generator.rb +14 -0
  9. data/lib/generators/gmaps4rails/copy_js_generator.rb +15 -0
  10. data/lib/gmaps4rails.rb +12 -22
  11. data/lib/gmaps4rails/markers_builder.rb +74 -0
  12. data/lib/gmaps4rails/rails/engine.rb +6 -0
  13. data/lib/gmaps4rails/rails/railtie.rb +6 -0
  14. data/lib/gmaps4rails/version.rb +2 -2
  15. data/script/compile_coffee_files.rb +19 -0
  16. data/script/gmaps4rails.rake +7 -0
  17. data/spec/javascripts/google/builders/marker_spec.js +96 -0
  18. data/spec/javascripts/helpers/SpecHelper.js +101 -0
  19. data/spec/javascripts/helpers/matchers.js +12 -0
  20. data/spec/javascripts/helpers/underscore.js +6 -0
  21. data/spec/javascripts/objects/handler_spec.js +320 -0
  22. data/spec/javascripts/support/jasmine.yml +86 -0
  23. data/spec/javascripts/support/jasmine_helper.rb +11 -0
  24. data/spec/lib/base_spec.rb +10 -52
  25. data/spec/lib/markers_builder_spec.rb +49 -0
  26. data/spec/spec_helper.rb +1 -25
  27. data/vendor/assets/javascripts/gmaps/base.coffee +16 -0
  28. data/vendor/assets/javascripts/gmaps/base/base.coffee +17 -0
  29. data/vendor/assets/javascripts/gmaps/google.coffee +3 -0
  30. data/vendor/assets/javascripts/gmaps/google/builders/bound.coffee +6 -0
  31. data/vendor/assets/javascripts/gmaps/google/builders/circle.coffee +21 -0
  32. data/vendor/assets/javascripts/gmaps/google/builders/clusterer.coffee +6 -0
  33. data/vendor/assets/javascripts/gmaps/google/builders/kml.coffee +17 -0
  34. data/vendor/assets/javascripts/gmaps/google/builders/map.coffee +27 -0
  35. data/vendor/assets/javascripts/gmaps/google/builders/marker.coffee +100 -0
  36. data/vendor/assets/javascripts/gmaps/google/builders/polygon.coffee +24 -0
  37. data/vendor/assets/javascripts/gmaps/google/builders/polyline.coffee +24 -0
  38. data/vendor/assets/javascripts/gmaps/google/objects/bound.coffee +13 -0
  39. data/vendor/assets/javascripts/gmaps/google/objects/circle.coffee +9 -0
  40. data/vendor/assets/javascripts/gmaps/google/objects/clusterer.coffee +13 -0
  41. data/vendor/assets/javascripts/gmaps/google/objects/common.coffee +23 -0
  42. data/vendor/assets/javascripts/gmaps/google/objects/kml.coffee +15 -0
  43. data/vendor/assets/javascripts/gmaps/google/objects/map.coffee +19 -0
  44. data/vendor/assets/javascripts/gmaps/google/objects/marker.coffee +11 -0
  45. data/vendor/assets/javascripts/gmaps/google/objects/polygon.coffee +8 -0
  46. data/vendor/assets/javascripts/gmaps/google/objects/polyline.coffee +8 -0
  47. data/vendor/assets/javascripts/gmaps/google/primitives.coffee +43 -0
  48. data/vendor/assets/javascripts/gmaps/objects/base_builder.coffee +20 -0
  49. data/vendor/assets/javascripts/gmaps/objects/builder.coffee +12 -0
  50. data/vendor/assets/javascripts/gmaps/objects/handler.coffee +153 -0
  51. data/vendor/assets/javascripts/gmaps/objects/null_clusterer.coffee +4 -0
  52. metadata +66 -299
  53. data/Guardfile.old +0 -24
  54. data/app/views/gmaps4rails/_gmaps4rails.html.erb +0 -20
  55. data/lib/generators/gmaps4rails/install_generator.rb +0 -43
  56. data/lib/generators/templates/README +0 -2
  57. data/lib/gmaps4rails/acts_as_gmappable.rb +0 -54
  58. data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +0 -40
  59. data/lib/gmaps4rails/api_wrappers/direction.rb +0 -87
  60. data/lib/gmaps4rails/api_wrappers/geocoder.rb +0 -54
  61. data/lib/gmaps4rails/api_wrappers/places.rb +0 -74
  62. data/lib/gmaps4rails/base.rb +0 -126
  63. data/lib/gmaps4rails/extensions/enumerable.rb +0 -14
  64. data/lib/gmaps4rails/extensions/hash.rb +0 -9
  65. data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +0 -33
  66. data/lib/gmaps4rails/js_builder.rb +0 -154
  67. data/lib/gmaps4rails/json_builder.rb +0 -140
  68. data/lib/gmaps4rails/model_handler.rb +0 -101
  69. data/lib/gmaps4rails/view_helper.rb +0 -172
  70. data/lib/tasks/jasmine.rake +0 -8
  71. data/public/javascripts/gmaps4rails/all.js +0 -2144
  72. data/public/javascripts/gmaps4rails/base.js +0 -792
  73. data/public/javascripts/gmaps4rails/google.js +0 -556
  74. data/public/javascripts/gmaps4rails/openlayers.js +0 -377
  75. data/public/stylesheets/gmaps4rails.css +0 -24
  76. data/spec/dummy/.gitignore +0 -3
  77. data/spec/dummy/.rspec +0 -1
  78. data/spec/dummy/README.rdoc +0 -261
  79. data/spec/dummy/Rakefile +0 -7
  80. data/spec/dummy/app/assets/javascripts/application.js +0 -18
  81. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  82. data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +0 -24
  83. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  84. data/spec/dummy/app/controllers/users_controller.rb +0 -105
  85. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  86. data/spec/dummy/app/mailers/.gitkeep +0 -0
  87. data/spec/dummy/app/models/.gitkeep +0 -0
  88. data/spec/dummy/app/models/place.rb +0 -16
  89. data/spec/dummy/app/models/user.rb +0 -12
  90. data/spec/dummy/app/views/layouts/application.html.erb +0 -17
  91. data/spec/dummy/app/views/users/_form.html.erb +0 -37
  92. data/spec/dummy/app/views/users/edit.html.erb +0 -6
  93. data/spec/dummy/app/views/users/index.html.erb +0 -268
  94. data/spec/dummy/app/views/users/new.html.erb +0 -5
  95. data/spec/dummy/app/views/users/show.html.erb +0 -30
  96. data/spec/dummy/config.ru +0 -4
  97. data/spec/dummy/config/application.rb +0 -62
  98. data/spec/dummy/config/boot.rb +0 -10
  99. data/spec/dummy/config/database.yml +0 -25
  100. data/spec/dummy/config/environment.rb +0 -5
  101. data/spec/dummy/config/environments/development.rb +0 -37
  102. data/spec/dummy/config/environments/production.rb +0 -67
  103. data/spec/dummy/config/environments/test.rb +0 -37
  104. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  105. data/spec/dummy/config/initializers/gmaps4rails.rb +0 -1
  106. data/spec/dummy/config/initializers/inflections.rb +0 -15
  107. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  108. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  109. data/spec/dummy/config/initializers/session_store.rb +0 -8
  110. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  111. data/spec/dummy/config/locales/en.yml +0 -5
  112. data/spec/dummy/config/routes.rb +0 -60
  113. data/spec/dummy/db/migrate/20120408170155_create_users.rb +0 -16
  114. data/spec/dummy/db/schema.rb +0 -29
  115. data/spec/dummy/lib/assets/.gitkeep +0 -0
  116. data/spec/dummy/log/.gitkeep +0 -0
  117. data/spec/dummy/public/404.html +0 -26
  118. data/spec/dummy/public/422.html +0 -26
  119. data/spec/dummy/public/500.html +0 -25
  120. data/spec/dummy/public/favicon.ico +0 -0
  121. data/spec/dummy/public/javascripts/Player.js +0 -22
  122. data/spec/dummy/public/javascripts/Song.js +0 -7
  123. data/spec/dummy/public/logo.png +0 -0
  124. data/spec/dummy/script/rails +0 -6
  125. data/spec/factories/place_factory.rb +0 -16
  126. data/spec/factories/user_factory.rb +0 -23
  127. data/spec/fixtures/google_direction_valid.json +0 -65
  128. data/spec/fixtures/google_geocoding_toulon_france.json +0 -58
  129. data/spec/fixtures/google_places_valid.json +0 -45
  130. data/spec/fixtures/google_wrong_geocoding.json +0 -4
  131. data/spec/launchers/all_but_requests.rb +0 -0
  132. data/spec/launchers/all_specs.rb +0 -0
  133. data/spec/launchers/requests.rb +0 -0
  134. data/spec/lib/direction_spec.rb +0 -53
  135. data/spec/lib/geocoder_spec.rb +0 -46
  136. data/spec/lib/js_builder_spec.rb +0 -134
  137. data/spec/lib/json_builder_spec.rb +0 -232
  138. data/spec/lib/places_spec.rb +0 -25
  139. data/spec/models/place_spec.rb +0 -39
  140. data/spec/models/user_spec.rb +0 -187
  141. data/spec/support/geocoding.rb +0 -40
  142. data/spec/support/matchers.rb +0 -73
  143. data/todo +0 -0
  144. data/vendor/assets/javascripts/gmaps4rails/all.js +0 -1
  145. data/vendor/assets/javascripts/gmaps4rails/base.coffee +0 -1
  146. data/vendor/assets/javascripts/gmaps4rails/base/common.coffee +0 -43
  147. data/vendor/assets/javascripts/gmaps4rails/base/configuration.coffee +0 -7
  148. data/vendor/assets/javascripts/gmaps4rails/base/gmaps.coffee +0 -13
  149. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/basic_interface.coffee +0 -15
  150. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/controller_interface.coffee +0 -15
  151. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/map_interface.coffee +0 -27
  152. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/marker_interface.coffee +0 -15
  153. data/vendor/assets/javascripts/gmaps4rails/base/main.coffee +0 -124
  154. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/circle_controller.coffee +0 -29
  155. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/kml_controller.coffee +0 -5
  156. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/marker_controller.coffee +0 -76
  157. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polygon_controller.coffee +0 -29
  158. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polyline_controller.coffee +0 -29
  159. data/vendor/assets/javascripts/gmaps4rails/base/objects/circle.coffee +0 -12
  160. data/vendor/assets/javascripts/gmaps4rails/base/objects/kml.coffee +0 -8
  161. data/vendor/assets/javascripts/gmaps4rails/base/objects/map.coffee +0 -62
  162. data/vendor/assets/javascripts/gmaps4rails/base/objects/marker.coffee +0 -24
  163. data/vendor/assets/javascripts/gmaps4rails/base/objects/polygon.coffee +0 -11
  164. data/vendor/assets/javascripts/gmaps4rails/base/objects/polyline.coffee +0 -11
  165. data/vendor/assets/javascripts/gmaps4rails/bing.coffee +0 -1
  166. data/vendor/assets/javascripts/gmaps4rails/bing/main.coffee +0 -29
  167. data/vendor/assets/javascripts/gmaps4rails/bing/objects/map.coffee +0 -63
  168. data/vendor/assets/javascripts/gmaps4rails/bing/objects/marker.coffee +0 -78
  169. data/vendor/assets/javascripts/gmaps4rails/bing/shared.coffee +0 -20
  170. data/vendor/assets/javascripts/gmaps4rails/google.coffee +0 -1
  171. data/vendor/assets/javascripts/gmaps4rails/google/main.coffee +0 -47
  172. data/vendor/assets/javascripts/gmaps4rails/google/objects/circle.coffee +0 -38
  173. data/vendor/assets/javascripts/gmaps4rails/google/objects/kml.coffee +0 -16
  174. data/vendor/assets/javascripts/gmaps4rails/google/objects/map.coffee +0 -71
  175. data/vendor/assets/javascripts/gmaps4rails/google/objects/marker.coffee +0 -114
  176. data/vendor/assets/javascripts/gmaps4rails/google/objects/polygon.coffee +0 -38
  177. data/vendor/assets/javascripts/gmaps4rails/google/objects/polyline.coffee +0 -49
  178. data/vendor/assets/javascripts/gmaps4rails/google/shared.coffee +0 -27
  179. data/vendor/assets/javascripts/gmaps4rails/openlayers.coffee +0 -1
  180. data/vendor/assets/javascripts/gmaps4rails/openlayers/main.coffee +0 -138
  181. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/map.coffee +0 -49
  182. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/marker.coffee +0 -68
  183. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/polyline.coffee +0 -39
  184. data/vendor/assets/javascripts/gmaps4rails/openlayers/shared.coffee +0 -19
@@ -1,46 +0,0 @@
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
-
@@ -1,134 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "to_gmaps4rails for hash" do
4
- it "should accept hashes with indifferent access" do
5
- hash1 = {:markers => {:data => @json, :options => {:do_clustering => true, :draggable => true } }}
6
- hash2 = {"markers" => {"data" => @json, "options" => {"do_clustering" => true, "draggable" => true } }}
7
- hash1.to_gmaps4rails.should eq hash2.to_gmaps4rails
8
- end
9
-
10
- context "rendered js" do
11
- it "should format polygons" do
12
- expected_polygons = '[[
13
- {"longitude": -80.190262, "latitude": 25.774252},
14
- {"longitude": -66.118292, "latitude": 18.466465},
15
- {"longitude": -64.75737, "latitude": 32.321384}
16
- ]]'
17
- options_hash = {
18
- :polygons => { :data => expected_polygons }
19
- }
20
- result = options_hash.to_gmaps4rails
21
- actual_polygons = result.scan(/Gmaps\.map\.addPolygons\((.*?)\);/m).first.first
22
-
23
- actual_polygons.should be_same_json_as expected_polygons
24
- end
25
-
26
- it "should format polylines" do
27
- expected_polylines = '[[
28
- {"longitude": -122.214897, "latitude": 37.772323},
29
- {"longitude": -157.821856, "latitude": 21.291982},
30
- {"longitude": 178.431, "latitude": -18.142599},
31
- {"longitude": 153.027892, "latitude": -27.46758}
32
- ],
33
- [
34
- {"longitude": -120.214897, "latitude": 30.772323, "strokeColor": "#000", "strokeWeight" : 2 },
35
- {"longitude": -10.821856, "latitude": 50.291982}
36
- ]]'
37
- options_hash = {
38
- :polylines => { :data => expected_polylines }
39
- }
40
- result = options_hash.to_gmaps4rails
41
- actual_polylines = result.scan(/Gmaps\.map\.addPolylines\((.*?)\);/m).first.first
42
-
43
- actual_polylines.should be_same_json_as expected_polylines
44
- end
45
-
46
- it "should format circles" do
47
- expected_circles = '[
48
- {"longitude": -122.214897, "latitude": 37.772323, "radius": 1000000},
49
- {"longitude": 122.214897, "latitude": 37.772323, "radius": 1000000, "strokeColor": "#FF0000"}
50
- ]'
51
- options_hash = {
52
- :circles => { :data => expected_circles }
53
- }
54
- result = options_hash.to_gmaps4rails
55
- actual_circles = result.scan(/Gmaps\.map\.addCircles\((.*?)\);/m).first.first
56
-
57
- actual_circles.should be_same_json_as expected_circles
58
- end
59
-
60
- it "should format markers" do
61
- expected_markers = '[{ "description": "", "title": "", "longitude": "5.9311119", "latitude": "43.1251606", "picture": "", "width": "", "height": "" } ,{ "description": "", "title": "", "longitude": "2.3509871", "latitude": "48.8566667", "picture": "", "width": "", "height": "" } ]'
62
- options_hash = {
63
- :markers => { :data => expected_markers }
64
- }
65
- result = options_hash.to_gmaps4rails
66
- actual_markers = result.scan(/Gmaps\.map\.addMarkers\((.*?)\);/m).first.first
67
-
68
- actual_markers.should be_same_json_as expected_markers
69
- end
70
-
71
- it "should format map" do
72
- options_hash = {
73
- :map_options => { :type => "SATELLITE", :center_longitude => 180, "zoom" => 3, :raw => '{ok: true}'}
74
- }
75
- result = options_hash.to_gmaps4rails
76
-
77
- result.should include "Gmaps.map = new Gmaps4RailsGoogle();"
78
- result.should include "Gmaps.map.map_options.center_longitude = 180;"
79
- result.should include "Gmaps.map.map_options.type = \"SATELLITE\""
80
- result.should include "Gmaps.map.map_options.raw = {ok: true};"
81
- result.should include "Gmaps.map.map_options.zoom = 3;"
82
- result.should include "Gmaps.map.initialize();"
83
- end
84
-
85
- it "should invoke callback" do
86
- result = {}.to_gmaps4rails
87
- result.should include "Gmaps.map.callback();"
88
- end
89
-
90
- it "should format kml" do
91
- expected_kml = '[{ url: "http://www.searcharoo.net/SearchKml/newyork.kml"}, { url: "http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml", options: {clickable: false } }]'
92
- options_hash = {
93
- :kml => {:data => expected_kml }
94
- }
95
- result = options_hash.to_gmaps4rails
96
- actual_kml = result.scan(/Gmaps\.map\.addKml\((.*?)\);/m).first.first
97
-
98
- actual_kml.should eq expected_kml
99
- end
100
-
101
- it "should format directions" do
102
- options_hash = {
103
- "direction" => {
104
- "data" => { "from" => "toulon, france", "to" => "paris, france"} ,
105
- "options" => {"waypoints" => ["toulouse, france", "brest, france"], "travelMode" => "DRIVING", "display_panel" => true, "panel_id" => "instructions"}
106
- }
107
- }
108
- result = options_hash.to_gmaps4rails
109
- result.should include "Gmaps.map.direction_conf.origin = 'toulon, france';\nGmaps.map.direction_conf.destination = 'paris, france';"
110
- result.should include "Gmaps.map.direction_conf.display_panel = true;"
111
- result.should include "Gmaps.map.direction_conf.panel_id = \"instructions\";"
112
- result.should include "Gmaps.map.direction_conf.travelMode = \"DRIVING\";"
113
- result.should include "Gmaps.map.create_direction();"
114
-
115
- actual_directions = result.scan(/Gmaps\.map\.direction_conf\.waypoints = (.*?);/m).first.first
116
- actual_directions.should be_same_json_as "[{\"stopover\":true,\"location\":\"toulouse, france\"},{\"stopover\":true,\"location\":\"brest, france\"}]"
117
- end
118
-
119
- it "should not call map builder if not last_map" do
120
- hash = {:last_map => false}
121
- hash.to_gmaps4rails.should_not include "window.onload"
122
- end
123
-
124
- it "should call map builder if last_map" do
125
- trigger_script = "Gmaps.oldOnload = window.onload;\n window.onload = function() { Gmaps.triggerOldOnload(); Gmaps.loadMaps(); };"
126
- hash = {:last_map => true}
127
- hash.to_gmaps4rails.should include trigger_script
128
- hash = {}
129
- hash.to_gmaps4rails.should include trigger_script
130
- end
131
-
132
- end
133
-
134
- end
@@ -1,232 +0,0 @@
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
@@ -1,25 +0,0 @@
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
@@ -1,39 +0,0 @@
1
- if RUBY_VERSION == "1.9.3"
2
-
3
- require 'spec_helper'
4
-
5
- include Geocoding
6
-
7
- set_gmaps4rails_options!
8
-
9
- # Mongoid 3.x only
10
- require 'mongoid'
11
- require 'moped'
12
-
13
- Mongoid.configure do |config|
14
- config.connect_to('mongoid_geo_test')
15
- end
16
-
17
- describe Gmaps4rails::ActsAsGmappable do
18
-
19
- let(:place) { Factory(:place) }
20
- let(:invalid_place) { Factory.build(:invalid_place) }
21
-
22
- before(:each) do
23
- Geocoding.stub_geocoding
24
- end
25
-
26
- context "standard configuration, valid place" do
27
- after(:each) do
28
- set_gmaps4rails_options!({})
29
- end
30
-
31
- it "should save longitude and latitude to the customized position array" do
32
- set_gmaps4rails_options!(:position => 'pos')
33
- place.pos.should_not be_nil
34
- place.should have_same_position_as TOULON
35
- end
36
- end
37
- end
38
-
39
- end