gmaps4rails 0.6.5 → 0.7.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.
@@ -45,6 +45,8 @@ Done!
45
45
 
46
46
  * Markers with Info window, Custom Picture
47
47
 
48
+ * Automatic sidebar with list of markers
49
+
48
50
  * Circles, Polylines, Polygons
49
51
 
50
52
  * Geocode directly your address and retrieve coordinates.
@@ -6,9 +6,14 @@
6
6
  <% end %>
7
7
 
8
8
  <% content_for :scripts do %>
9
- <script src="http://www.google.com/jsapi"></script>
10
- <script type="text/javascript" src='http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer.js'></script>
11
- <%=javascript_include_tag 'gmaps4rails' %>
9
+ <% if enable_js == true %>
10
+ <script src="http://www.google.com/jsapi"></script>
11
+ <%=javascript_include_tag 'gmaps4rails' %>
12
+ <% debugger %>
13
+ <% unless options["markers"].nil? or (!options["markers"]["options"].nil? and options["markers"]["options"]["do_clustering"] == false) %>
14
+ <script type="text/javascript" src='http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer.js'></script>
15
+ <% end %>
16
+ <% end %>
12
17
  <script type="text/javascript" charset="utf-8">
13
18
 
14
19
  window.onload = function() {
@@ -19,5 +24,5 @@ window.onload = function() {
19
24
  <% end %>
20
25
 
21
26
  <div id="<%= options["map_options"].nil? || options['map_options']['container_id'].nil? ? "map_container" : options['map_options']['container_id'] %>">
22
- <div id="<%= options["map_options"].nil? || options['map_options']['id'].nil? ? "gmaps4rails_map" : options['map_options']['id'] %>"></div>
27
+ <div id="<%= options["map_options"].nil? || options['map_options']['id'].nil? ? "gmaps4rails_map" : options['map_options']['id'] %>"></div>
23
28
  </div>
@@ -15,7 +15,7 @@ module Gmaps4rails
15
15
  def Gmaps4rails.create_json(object)
16
16
  unless object[object.gmaps4rails_options[:lat_column]].blank? && object[object.gmaps4rails_options[:lng_column]].blank?
17
17
  "{
18
- \"description\": \"#{object.gmaps4rails_infowindow}\", \"title\": \"#{object.gmaps4rails_title}\",
18
+ \"description\": \"#{object.gmaps4rails_infowindow}\", \"title\": \"#{object.gmaps4rails_title}\", \"sidebar\": \"#{object.gmaps4rails_sidebar}\",
19
19
  \"longitude\": \"#{object[object.gmaps4rails_options[:lng_column]]}\", \"latitude\": \"#{object[object.gmaps4rails_options[:lat_column]]}\", \"picture\": \"#{object.gmaps4rails_marker_picture['picture']}\", \"width\": \"#{object.gmaps4rails_marker_picture['width']}\", \"height\": \"#{object.gmaps4rails_marker_picture['height']}\"
20
20
  } ,"
21
21
  end
@@ -116,88 +116,95 @@ module Gmaps4rails
116
116
 
117
117
  module ActsAsGmappable
118
118
 
119
- module Base
120
- def self.included(klass)
121
- klass.class_eval do
122
- extend Config
123
- end
119
+ extend ActiveSupport::Concern
120
+
121
+ module InstanceMethods
122
+ def gmaps4rails_infowindow
123
+ end
124
+
125
+ def gmaps4rails_title
124
126
  end
125
127
 
126
- module Config
127
- def acts_as_gmappable args = {}
128
- unless args[:process_geocoding] == false
129
- validate :process_geocoding
130
- end
131
-
132
- #instance method
133
- define_method "gmaps4rails_options" do
134
- {
135
- :lat_column => args[:lat] || "latitude",
136
- :lng_column => args[:lng] || "longitude",
137
- :check_process => args[:check_process].nil? ? true : args[:check_process],
138
- :checker => args[:checker] || "gmaps",
139
- :msg => args[:msg] || "Address invalid",
140
- :validation => args[:validation].nil? ? true : args[:validation]
141
- #TODO: address as a proc?
142
- }
128
+ def gmaps4rails_sidebar
129
+ end
130
+
131
+ def process_geocoding
132
+ #to prevent geocoding each time a save is made
133
+ return true if gmaps4rails_options[:check_process] == true && self[gmaps4rails_options[:checker]] == true
134
+
135
+ begin
136
+ coordinates = Gmaps4rails.geocode(self.gmaps4rails_address)
137
+ rescue GeocodeStatus #adress was invalid, add error to base.
138
+ errors[:base] << gmaps4rails_options[:msg] if gmaps4rails_options[:validation]
139
+ rescue GeocodeNetStatus => e #connection error, No need to prevent save.
140
+ logger.warn(e)
141
+ #TODO add customization here?
142
+ else #if no exception
143
+ self[gmaps4rails_options[:lng_column]] = coordinates.first[:lng]
144
+ self[gmaps4rails_options[:lat_column]] = coordinates.first[:lat]
145
+ if gmaps4rails_options[:check_process] == true
146
+ self[gmaps4rails_options[:checker]] = true
143
147
  end
144
-
145
- include Gmaps4rails::ActsAsGmappable::Base::InstanceMethods
146
148
  end
147
149
  end
148
-
149
- module InstanceMethods
150
150
 
151
- def gmaps4rails_infowindow
152
- end
151
+ def gmaps4rails_marker_picture
152
+ {
153
+ "picture" => "",
154
+ "width" => "",
155
+ "height" => ""
156
+ }
157
+ end
153
158
 
154
- def gmaps4rails_title
155
- end
159
+ def self.gmaps4rails_trusted_scopes
160
+ []
161
+ end
156
162
 
157
- def process_geocoding
158
- #to prevent geocoding each time a save is made
159
- return true if gmaps4rails_options[:check_process] == true && self[gmaps4rails_options[:checker]] == true
160
-
161
- begin
162
- coordinates = Gmaps4rails.geocode(self.gmaps4rails_address)
163
- rescue GeocodeStatus #adress was invalid, add error to base.
164
- errors[:base] << gmaps4rails_options[:msg] if gmaps4rails_options[:validation]
165
- rescue GeocodeNetStatus => e #connection error, No need to prevent save.
166
- logger.warn(e)
167
- #TODO add customization here?
168
- else #if no exception
169
- self[gmaps4rails_options[:lng_column]] = coordinates.first[:lng]
170
- self[gmaps4rails_options[:lat_column]] = coordinates.first[:lat]
171
- if gmaps4rails_options[:check_process] == true
172
- self[gmaps4rails_options[:checker]] = true
173
- end
174
- end
175
- end
163
+ def to_gmaps4rails
164
+ json = "["
165
+ json += Gmaps4rails.create_json(self).to_s.chop #removes the extra comma
166
+ json += "]"
167
+ end
176
168
 
177
- def gmaps4rails_marker_picture
178
- {
179
- "picture" => "",
180
- "width" => "",
181
- "height" => ""
182
- }
169
+ end
170
+
171
+ module ClassMethods
172
+ mattr_accessor :gmaps4rails_options
173
+
174
+ def acts_as_gmappable args = {}
175
+ unless args[:process_geocoding] == false
176
+ validate :process_geocoding
183
177
  end
178
+
179
+ # [:lat, :lng, :check_process, :checker, :msg, :validation].each do |sym|
180
+ # Gmaps4rails::ActsAsGmappable.gmaps4rails_options[sym] = args[sym] unless args[sym].nil?
181
+ # end
184
182
 
185
- def self.gmaps4rails_trusted_scopes
186
- []
187
- end
183
+ Gmaps4rails::ActsAsGmappable::ClassMethods.gmaps4rails_options = args
188
184
 
189
- def to_gmaps4rails
190
- json = "["
191
- json += Gmaps4rails.create_json(self).to_s.chop #removes the extra comma
192
- json += "]"
185
+ #instance method
186
+ define_method "gmaps4rails_options" do
187
+ {
188
+ :lat_column => args[:lat] || "latitude",
189
+ :lng_column => args[:lng] || "longitude",
190
+ :check_process => args[:check_process].nil? ? true : args[:check_process],
191
+ :checker => args[:checker] || "gmaps",
192
+ :msg => args[:msg] || "Address invalid",
193
+ :validation => args[:validation].nil? ? true : args[:validation]
194
+ #TODO: address as a proc?
195
+ }
193
196
  end
194
-
195
- end # InstanceMethods
197
+ end
198
+ include InstanceMethods
196
199
  end
197
- end
200
+
201
+ end #ActsAsGmappable
198
202
  end
199
203
 
200
- ::ActiveRecord::Base.send :include, Gmaps4rails::ActsAsGmappable::Base
204
+ ActiveSupport.on_load(:active_record) do
205
+ ActiveRecord::Base.send(:include, Gmaps4rails::ActsAsGmappable)
206
+ end
207
+ #::ActiveRecord::Base.send :include, Gmaps4rails::ActsAsGmappable
201
208
  # Mongoid::Document::ClassMethods.class_eval do
202
209
  # include Gmaps4rails::ActsAsGmappable::Base
203
210
  # end
@@ -1,15 +1,15 @@
1
1
  module ApplicationHelper
2
2
 
3
- def gmaps4rails(builder, enable_css = true )
3
+ def gmaps4rails(builder, enable_css = true, enable_js = true )
4
4
  options = {
5
5
  "map_options" => { "auto_adjust" => true},
6
6
  "markers" => { "data" => builder }
7
7
  }
8
- render :partial => 'gmaps4rails/gmaps4rails', :locals => { :options => options, :enable_css => enable_css }
8
+ render :partial => 'gmaps4rails/gmaps4rails', :locals => { :options => options, :enable_css => enable_css, :enable_js => enable_js }
9
9
  end
10
10
 
11
- def gmaps(options, enable_css = true )
12
- render :partial => 'gmaps4rails/gmaps4rails', :locals => { :options => options, :enable_css => enable_css }
11
+ def gmaps(options, enable_css = true, enable_js = true )
12
+ render :partial => 'gmaps4rails/gmaps4rails', :locals => { :options => options, :enable_css => enable_css, :enable_js => enable_js }
13
13
  end
14
14
 
15
15
  end
@@ -3,7 +3,8 @@ google.load('maps', '3', { other_params: 'libraries=geometry&sensor=false' });
3
3
  var Gmaps4Rails = {
4
4
  //map config
5
5
  map: null, //contains the map we're working on
6
-
6
+ visibleInfoWindow: null,
7
+
7
8
  //Map settings
8
9
  map_options: {
9
10
  id: 'gmaps4rails_map',
@@ -27,11 +28,12 @@ var Gmaps4Rails = {
27
28
  clusterer_gridSize: 50, //the more the quicker but the less precise
28
29
  clusterer_maxZoom: 5, //removes clusterer at this zoom level
29
30
  randomize: false, //Google maps can't display two markers which have the same coordinates. This randomizer enables to prevent this situation from happening.
30
- max_random_distance: 100 //in meters. Each marker coordinate could be altered by this distance in a random direction
31
+ max_random_distance: 100, //in meters. Each marker coordinate could be altered by this distance in a random direction
32
+ list_container : null //id of the ul that will host links to all markers
31
33
  },
32
34
 
33
35
  //Stored variables
34
- marker_objects: null, //contains markers LatLng
36
+ marker_objects: [], //contains markers LatLng
35
37
  markers : [], //contains raw markers
36
38
  bounds: null, //contains current bounds
37
39
  polygons: null, //contains raw data, array of arrays (first element cold be a hash containing options)
@@ -304,11 +306,11 @@ var Gmaps4Rails = {
304
306
 
305
307
  // clear markers
306
308
  clear_markers: function(){
307
- if (this.marker_objects) {
309
+ if (this.marker_objects.size() > 0) {
308
310
  for (i in this.marker_objects) {
309
311
  this.marker_objects[i].setMap(null);
310
312
  }
311
- this.marker_objects = null;
313
+ this.marker_objects = new Array;
312
314
  }
313
315
  },
314
316
 
@@ -329,10 +331,7 @@ var Gmaps4Rails = {
329
331
  },
330
332
 
331
333
  //Creates Marker from the markers passed + markerClusterer
332
- setup_Markers: function () {
333
- //variable used for Marker Clusterer
334
- var marker_objects = [];
335
-
334
+ setup_Markers: function () {
336
335
  //resets Clusterer if needed
337
336
  if (this.markerClusterer) {
338
337
  this.markerClusterer.clearMarkers();
@@ -368,34 +367,57 @@ var Gmaps4Rails = {
368
367
  }
369
368
  //save object for later use, basically, to get back the text to display when clicking it
370
369
  this.markers[i].marker_object = ThisMarker;
370
+ //add infowindowstuff + list creation if enabled
371
+ this.handle_info_window(this.markers[i]);
371
372
  //save the marker in a list
372
- marker_objects.push(ThisMarker);
373
- //add click listener
374
- google.maps.event.addListener(Gmaps4Rails.markers[i].marker_object, 'click', function() { if (Gmaps4Rails.info_window!=null) {Gmaps4Rails.info_window.close();}; Gmaps4Rails.getInfoWindow(this);});
375
- }
376
- this.setup_Clusterer(marker_objects);
373
+ this.marker_objects.push(ThisMarker);
374
+ }
375
+ this.setup_Clusterer();
377
376
  },
378
377
 
379
- //get info_window content when listener calls it
380
- getInfoWindow: function(which)
381
- {
382
- for ( var m = 0; m < this.markers.length; ++m )
383
- {
384
- var markerInfo = this.markers[m].marker_object;
385
- if ( markerInfo == which && this.markers[m].description != "")
386
- {
387
- this.info_window = new google.maps.InfoWindow({content: this.markers[m].description });
388
- this.info_window.open( this.map, which );
389
- return;
390
- }
391
- }
378
+ handle_info_window: function(marker_container){
379
+ //create the infowindow
380
+ var info_window = new google.maps.InfoWindow({content: marker_container.description });
381
+ //add the listener associated
382
+ google.maps.event.addListener(marker_container.marker_object, 'click', this.openInfoWindow(info_window, marker_container.marker_object));
383
+ if (this.markers_conf.list_container)
384
+ {
385
+ var ul = document.getElementById(this.markers_conf.list_container);
386
+ var li = document.createElement('li');
387
+ var aSel = document.createElement('a');
388
+ aSel.href = 'javascript:void(0);';
389
+ var html = this.exists(marker_container.sidebar) ? marker_container.sidebar : "Marker";
390
+ aSel.innerHTML = html;
391
+ aSel.onclick = this.generateTriggerCallback(marker_container.marker_object, 'click');
392
+ li.appendChild(aSel);
393
+ ul.appendChild(li);
394
+ }
392
395
  },
393
396
 
394
- setup_Clusterer: function(marker_objects)
397
+ openInfoWindow: function(infoWindow, marker) {
398
+ return function() {
399
+ // Close the latest selected marker before opening the current one.
400
+ if (Gmaps4Rails.visibleInfoWindow) {
401
+ Gmaps4Rails.visibleInfoWindow.close();
402
+ }
403
+
404
+ infoWindow.open(Gmaps4Rails.map, marker);
405
+ Gmaps4Rails.visibleInfoWindow = infoWindow;
406
+ };
407
+ },
408
+
409
+ generateTriggerCallback: function(marker, eventType) {
410
+ return function() {
411
+ Gmaps4Rails.map.panTo(marker.position);
412
+ google.maps.event.trigger(marker, eventType);
413
+ };
414
+ },
415
+
416
+ setup_Clusterer: function()
395
417
  {
396
418
  if (this.markers_conf.do_clustering == true)
397
419
  {
398
- this.markerClusterer = new MarkerClusterer(this.map, marker_objects, { maxZoom: this.markers_conf.clusterer_maxZoom,
420
+ this.markerClusterer = new MarkerClusterer(this.map, this.marker_objects, { maxZoom: this.markers_conf.clusterer_maxZoom,
399
421
  gridSize: this.markers_conf.clusterer_gridSize,
400
422
  //styles: styles TODO: offer clusterer customization
401
423
  });
@@ -39,4 +39,8 @@ class UsersController < ApplicationController
39
39
  @user.destroy
40
40
  redirect_to users_url, :notice => "Successfully destroyed user."
41
41
  end
42
+
43
+ def test_list
44
+ @json = User.all.to_gmaps4rails
45
+ end
42
46
  end
@@ -4,5 +4,12 @@ class User < ActiveRecord::Base
4
4
  def gmaps4rails_address
5
5
  address
6
6
  end
7
-
7
+
8
+ # def gmaps4rails_sidebar
9
+ # "<b>#{name}</b>"
10
+ # end
11
+ #
12
+ def gmaps4rails_infowindow
13
+ "je suis l'infowindow"
14
+ end
8
15
  end
@@ -1,4 +1,5 @@
1
1
  Dummy::Application.routes.draw do
2
+ match "users/test_list" => "users#test_list", :as => "test_list"
2
3
  resources :users
3
4
  root :to => "users#index"
4
5
  end
@@ -81,6 +81,46 @@ describe "JS creation from hash" do
81
81
  end
82
82
  end
83
83
 
84
+ describe "Hash extension" do
85
+
86
+ it "should create the proper text (used as js)" do
87
+ @options = {
88
+ "map_options" => { "type" => "SATELLITE", "center_longitude" => 180, "zoom" => 3, "auto_adjust" => true},
89
+ "markers" => { "data" => '[{ "description": "", "title": "", "longitude": "5.9311119", "latitude": "43.1251606", "picture": "", "width": "", "height": "" } ,{ "description": "", "title": "", "longitude": "2.3509871", "latitude": "48.8566667", "picture": "", "width": "", "height": "" } ]',
90
+ "options" => { "do_clustering" => false, "list_container" => "makers_list" }
91
+ },
92
+ "polylines" => { "data" => '[[
93
+ {"longitude": -122.214897, "latitude": 37.772323},
94
+ {"longitude": -157.821856, "latitude": 21.291982},
95
+ {"longitude": 178.431, "latitude": -18.142599},
96
+ {"longitude": 153.027892, "latitude": -27.46758}
97
+ ],
98
+ [
99
+ {"longitude": -120.214897, "latitude": 30.772323, "strokeColor": "#000", "strokeWeight" : 2 },
100
+ {"longitude": -10.821856, "latitude": 50.291982}
101
+ ]]' },
102
+ "polygons" => { "data" => '[[
103
+ {"longitude": -80.190262, "latitude": 25.774252},
104
+ {"longitude": -66.118292, "latitude": 18.466465},
105
+ {"longitude": -64.75737, "latitude": 32.321384}
106
+ ]]' },
107
+ "circles" => { "data" => '[
108
+ {"longitude": -122.214897, "latitude": 37.772323, "radius": 1000000},
109
+ {"longitude": 122.214897, "latitude": 37.772323, "radius": 1000000, "strokeColor": "#FF0000"}
110
+ ]',
111
+ },
112
+ "direction" => {
113
+ "data" => { "from" => "toulon, france", "to" => "paris, france"} ,
114
+ "options" => {"waypoints" => ["toulouse, france", "brest, france"], "travelMode" => "DRIVING", "display_panel" => true, "panel_id" => "instructions"}
115
+ }
116
+ }
117
+
118
+ @options.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.markers_conf.list_container = 'makers_list';\nGmaps4Rails.markers_conf.do_clustering = false;\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();"
119
+ @options.to_gmaps4rails(true).should include "Gmaps4Rails.initialize();"
120
+ end
121
+
122
+ end
123
+
84
124
  describe "Destination" do
85
125
  it "should render info from only start_end args"
86
126
  it "should accept all options properly"
@@ -2,6 +2,43 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe "Acts as gmappable" do
4
4
 
5
+ before(:each) do
6
+ #reset all configuration to default or nil
7
+ User.class_eval do
8
+ def gmaps4rails_options
9
+ {
10
+ :lat_column => "latitude",
11
+ :lng_column => "longitude",
12
+ :check_process => true,
13
+ :checker => "gmaps",
14
+ :msg => "Address invalid",
15
+ :validation => true
16
+ }
17
+ end
18
+
19
+ def gmaps4rails_address
20
+ address
21
+ end
22
+
23
+ def gmaps4rails_sidebar
24
+ end
25
+
26
+ def gmaps4rails_infowindow
27
+ end
28
+
29
+ def gmaps4rails_title
30
+ end
31
+
32
+ def gmaps4rails_marker_picture
33
+ {
34
+ "picture" => "",
35
+ "width" => "",
36
+ "height" => ""
37
+ }
38
+ end
39
+ end
40
+ end
41
+
5
42
  describe "standard configuration, valid user" do
6
43
  before(:each) do
7
44
  @user = Factory(:user)
@@ -18,11 +55,11 @@ describe "Acts as gmappable" do
18
55
 
19
56
  it "should render a valid json from an array of ojects" do
20
57
  @user2 = Factory(:user_paris)
21
- User.all.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ,{\n\"description\": \"\", \"title\": \"\",\n\"longitude\": \"2.3509871\", \"latitude\": \"48.8566667\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
58
+ User.all.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"\", \"sidebar\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ,{\n\"description\": \"\", \"title\": \"\", \"sidebar\": \"\",\n\"longitude\": \"2.3509871\", \"latitude\": \"48.8566667\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
22
59
  end
23
60
 
24
61
  it "should render a valid json from a single object" do
25
- @user.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
62
+ @user.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"\", \"sidebar\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
26
63
  end
27
64
 
28
65
  it "should not geocode again after address changes if checker is true" do
@@ -57,7 +94,8 @@ describe "Acts as gmappable" do
57
94
  end
58
95
 
59
96
 
60
- describe "model customization" do
97
+ describe "model customization" do
98
+
61
99
  it "should render a valid json even if there is no instance in the db" do
62
100
  User.all.to_gmaps4rails.should == "[]"
63
101
  end
@@ -114,7 +152,7 @@ describe "Acts as gmappable" do
114
152
  @user.long_test.should == 5.9311119
115
153
  @user.longitude.should == nil
116
154
  @user.latitude.should == nil
117
- @user.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
155
+ @user.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"\", \"sidebar\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
118
156
  end
119
157
 
120
158
  it "should not save the boolean if check_process is false" do
@@ -179,14 +217,11 @@ describe "Acts as gmappable" do
179
217
  end
180
218
  end
181
219
  @user = Factory(:user_with_pic)
182
- @user.to_gmaps4rails.should == "[{\n\"description\": \"My Beautiful Picture: http://www.blankdots.com/img/github-32x32.png\", \"title\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
220
+ @user.to_gmaps4rails.should == "[{\n\"description\": \"My Beautiful Picture: http://www.blankdots.com/img/github-32x32.png\", \"title\": \"\", \"sidebar\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
183
221
  end
184
222
 
185
223
  it "should take into account the picture provided in the model" do
186
224
  User.class_eval do
187
- def gmaps4rails_infowindow
188
- #to reset the former declaration
189
- end
190
225
  def gmaps4rails_marker_picture
191
226
  {
192
227
  "picture" => "http://www.blankdots.com/img/github-32x32.png",
@@ -196,7 +231,7 @@ describe "Acts as gmappable" do
196
231
  end
197
232
  end
198
233
  @user = Factory(:user)
199
- @user.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"http://www.blankdots.com/img/github-32x32.png\", \"width\": \"32\", \"height\": \"32\"\n} ]"
234
+ @user.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"\", \"sidebar\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"http://www.blankdots.com/img/github-32x32.png\", \"width\": \"32\", \"height\": \"32\"\n} ]"
200
235
  end
201
236
 
202
237
  it "should take into account the title provided in the model" do
@@ -206,7 +241,17 @@ describe "Acts as gmappable" do
206
241
  end
207
242
  end
208
243
  @user = Factory(:user)
209
- @user.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"Sweet Title\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"http://www.blankdots.com/img/github-32x32.png\", \"width\": \"32\", \"height\": \"32\"\n} ]"
244
+ @user.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"Sweet Title\", \"sidebar\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
245
+ end
246
+
247
+ it "should take into account the sidebar content provided in the model" do
248
+ User.class_eval do
249
+ def gmaps4rails_sidebar
250
+ "sidebar content"
251
+ end
252
+ end
253
+ @user = Factory(:user)
254
+ @user.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"\", \"sidebar\": \"sidebar content\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
210
255
  end
211
256
  end
212
257
 
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "list creation", :js => true do
4
+
5
+ it "should create the sidebar with list of users" do
6
+
7
+ #first setup what the list should display
8
+ User.class_eval do
9
+ def gmaps4rails_sidebar
10
+ name
11
+ end
12
+ end
13
+
14
+ Factory(:user, :name => "User1")
15
+ Factory(:user, :name => "User2")
16
+
17
+ visit test_list_path
18
+ page.should have_content("User1")
19
+ page.should have_content("User2")
20
+ end
21
+
22
+ end
23
+
@@ -2,10 +2,12 @@
2
2
  ENV["RAILS_ENV"] ||= 'test'
3
3
  require File.expand_path("../../config/environment", __FILE__)
4
4
  require 'rspec/rails'
5
+ require 'capybara/rspec'
5
6
 
6
7
  # Requires supporting ruby files with custom matchers and macros, etc,
7
8
  # in spec/support/ and its subdirectories.
8
9
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
10
+ Capybara.server_boot_timeout = 50
9
11
 
10
12
  RSpec.configure do |config|
11
13
  # == Mock Framework
@@ -23,5 +25,17 @@ RSpec.configure do |config|
23
25
  # If you're not using ActiveRecord, or you'd prefer not to run each of your
24
26
  # examples within a transaction, remove the following line or assign false
25
27
  # instead of true.
26
- config.use_transactional_fixtures = true
28
+ config.use_transactional_fixtures = false
29
+
30
+ config.before(:suite) do
31
+ DatabaseCleaner.strategy = :truncation
32
+ end
33
+
34
+ config.before(:each) do
35
+ DatabaseCleaner.start
36
+ end
37
+
38
+ config.after(:each) do
39
+ DatabaseCleaner.clean
40
+ end
27
41
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmaps4rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 5
10
- version: 0.6.5
8
+ - 7
9
+ - 0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Benjamin Roth
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-03-23 00:00:00 +01:00
19
+ date: 2011-04-08 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -68,7 +68,6 @@ files:
68
68
  - test/dummy/app/helpers/application_helper.rb
69
69
  - test/dummy/app/helpers/users_helper.rb
70
70
  - test/dummy/app/models/user.rb
71
- - test/dummy/app/views/users/test.rb
72
71
  - test/dummy/config/application.rb
73
72
  - test/dummy/config/boot.rb
74
73
  - test/dummy/config/environment.rb
@@ -88,6 +87,7 @@ files:
88
87
  - test/dummy/spec/controllers/users_controller_spec.rb
89
88
  - test/dummy/spec/factories.rb
90
89
  - test/dummy/spec/models/user_spec.rb
90
+ - test/dummy/spec/requests/users_spec.rb
91
91
  - test/dummy/spec/spec_helper.rb
92
92
  has_rdoc: true
93
93
  homepage: http://github.com/apneadiving/Google-Maps-for-Rails
@@ -129,7 +129,6 @@ test_files:
129
129
  - test/dummy/app/helpers/application_helper.rb
130
130
  - test/dummy/app/helpers/users_helper.rb
131
131
  - test/dummy/app/models/user.rb
132
- - test/dummy/app/views/users/test.rb
133
132
  - test/dummy/config/application.rb
134
133
  - test/dummy/config/boot.rb
135
134
  - test/dummy/config/environment.rb
@@ -149,4 +148,5 @@ test_files:
149
148
  - test/dummy/spec/controllers/users_controller_spec.rb
150
149
  - test/dummy/spec/factories.rb
151
150
  - test/dummy/spec/models/user_spec.rb
151
+ - test/dummy/spec/requests/users_spec.rb
152
152
  - test/dummy/spec/spec_helper.rb
@@ -1,35 +0,0 @@
1
- Gmaps4Rails.map_options.center_longitude = 180;
2
- Gmaps4Rails.map_options.type = 'SATELLITE';
3
- Gmaps4Rails.map_options.zoom = 3;
4
- Gmaps4Rails.initialize();
5
- Gmaps4Rails.polylines = [[
6
- {\"longitude\": -122.214897, \"latitude\": 37.772323},
7
- {\"longitude\": -157.821856, \"latitude\": 21.291982},
8
- {\"longitude\": 178.431, \"latitude\": -18.142599},
9
- {\"longitude\": 153.027892, \"latitude\": -27.46758}
10
- ],
11
- [
12
- {\"longitude\": -120.214897, \"latitude\": 30.772323, \"strokeColor\": \"#000\", \"strokeWeight\" : 2 },
13
- {\"longitude\": -10.821856, \"latitude\": 50.291982}
14
- ]];
15
- Gmaps4Rails.create_polylines();
16
- Gmaps4Rails.circles = [
17
- {\"longitude\": -122.214897, \"latitude\": 37.772323, \"radius\": 1000000},
18
- {\"longitude\": 122.214897, \"latitude\": 37.772323, \"radius\": 1000000, \"strokeColor\": \"#FF0000\"}
19
- ];
20
- Gmaps4Rails.create_circles();
21
- Gmaps4Rails.polygons = [[
22
- {\"longitude\": -80.190262, \"latitude\": 25.774252},
23
- {\"longitude\": -66.118292, \"latitude\": 18.466465},
24
- {\"longitude\": -64.75737, \"latitude\": 32.321384}
25
- ]];
26
- Gmaps4Rails.create_polygons();
27
- Gmaps4Rails.markers = [{ \"description\": \"\", \"title\": \"\", \"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\" } ,{ \"description\": \"\", \"title\": \"\", \"longitude\": \"2.3509871\", \"latitude\": \"48.8566667\", \"picture\": \"\", \"width\": \"\", \"height\": \"\" } ];
28
- Gmaps4Rails.create_markers();
29
- Gmaps4Rails.direction_conf.origin = 'toulon, france';
30
- Gmaps4Rails.direction_conf.destination = 'paris, france';
31
- Gmaps4Rails.direction_conf.display_panel = 'true';
32
- Gmaps4Rails.direction_conf.panel_id = 'instructions';
33
- Gmaps4Rails.direction_conf.travelMode = 'DRIVING';
34
- Gmaps4Rails.direction_conf.waypoints = [{\"stopover\":true,\"location\":\"toulouse, france\"},{\"stopover\":true,\"location\":\"brest, france\"}];
35
- Gmaps4Rails.create_direction();