gmaps4rails 1.4.8 → 1.5.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.gitignore +11 -0
  2. data/.travis.yml +10 -0
  3. data/Gemfile +9 -0
  4. data/Gemfile.lock +175 -0
  5. data/Guardfile +38 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.rdoc +26 -37
  8. data/Rakefile +4 -0
  9. data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +40 -34
  10. data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +4 -2
  11. data/app/views/gmaps4rails/_gmaps4rails.html.erb +13 -12
  12. data/gmaps4rails.gemspec +38 -0
  13. data/lib/gmaps4rails.rb +0 -8
  14. data/lib/gmaps4rails/acts_as_gmappable.rb +55 -33
  15. data/lib/gmaps4rails/base.rb +7 -12
  16. data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +16 -42
  17. data/lib/gmaps4rails/js_builder.rb +121 -0
  18. data/lib/gmaps4rails/json_builder.rb +127 -0
  19. data/lib/gmaps4rails/version.rb +3 -0
  20. data/lib/gmaps4rails/view_helper.rb +171 -0
  21. data/lib/tasks/gmaps4rails_tasks.rake +4 -0
  22. data/lib/tasks/jasmine.rake +8 -0
  23. data/public/javascripts/gmaps4rails/gmaps4rails.base.js +81 -30
  24. data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +34 -11
  25. data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +45 -21
  26. data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +33 -14
  27. data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +33 -20
  28. data/spec/base/base_spec.rb +185 -0
  29. data/spec/base/geocoding_spec.rb +17 -0
  30. data/spec/dummy/.gitignore +2 -0
  31. data/spec/dummy/.rspec +1 -0
  32. data/spec/dummy/README.rdoc +261 -0
  33. data/spec/dummy/Rakefile +7 -0
  34. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  35. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  36. data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +24 -0
  37. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  38. data/spec/dummy/app/controllers/users_controller.rb +96 -0
  39. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  40. data/spec/dummy/app/mailers/.gitkeep +0 -0
  41. data/spec/dummy/app/models/.gitkeep +0 -0
  42. data/spec/dummy/app/models/user.rb +9 -0
  43. data/spec/dummy/app/views/layouts/application.html.erb +16 -0
  44. data/spec/dummy/app/views/users/_form.html.erb +37 -0
  45. data/spec/dummy/app/views/users/_my_template.html.erb +2 -0
  46. data/spec/dummy/app/views/users/_my_template2.html.erb +1 -0
  47. data/spec/dummy/app/views/users/ajax_data.js.erb +2 -0
  48. data/spec/dummy/app/views/users/ajax_test.html.erb +22 -0
  49. data/spec/dummy/app/views/users/edit.html.erb +6 -0
  50. data/spec/dummy/app/views/users/index.html.erb +238 -0
  51. data/spec/dummy/app/views/users/new.html.erb +5 -0
  52. data/spec/dummy/app/views/users/show.html.erb +30 -0
  53. data/spec/dummy/config.ru +4 -0
  54. data/spec/dummy/config/application.rb +62 -0
  55. data/spec/dummy/config/boot.rb +10 -0
  56. data/spec/dummy/config/database.yml +25 -0
  57. data/spec/dummy/config/environment.rb +5 -0
  58. data/spec/dummy/config/environments/development.rb +37 -0
  59. data/spec/dummy/config/environments/production.rb +67 -0
  60. data/spec/dummy/config/environments/test.rb +37 -0
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/dummy/config/initializers/inflections.rb +15 -0
  63. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  64. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  65. data/spec/dummy/config/initializers/session_store.rb +8 -0
  66. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  67. data/spec/dummy/config/locales/en.yml +5 -0
  68. data/spec/dummy/config/routes.rb +60 -0
  69. data/spec/dummy/db/migrate/20120408170155_create_users.rb +16 -0
  70. data/spec/dummy/db/schema.rb +29 -0
  71. data/spec/dummy/lib/assets/.gitkeep +0 -0
  72. data/spec/dummy/log/.gitkeep +0 -0
  73. data/spec/dummy/public/404.html +26 -0
  74. data/spec/dummy/public/422.html +26 -0
  75. data/spec/dummy/public/500.html +25 -0
  76. data/spec/dummy/public/favicon.ico +0 -0
  77. data/spec/dummy/public/javascripts/Player.js +22 -0
  78. data/spec/dummy/public/javascripts/Song.js +7 -0
  79. data/spec/dummy/script/rails +6 -0
  80. data/spec/factories/user_factory.rb +23 -0
  81. data/spec/javascripts/basic_methods_spec.js +103 -0
  82. data/spec/javascripts/helpers/.gitkeep +0 -0
  83. data/spec/javascripts/helpers/SpecHelper.js +87 -0
  84. data/spec/javascripts/map_spec.js +49 -0
  85. data/spec/javascripts/markers_methods_spec.js +368 -0
  86. data/spec/javascripts/mocks_spec.js +27 -0
  87. data/spec/javascripts/support/jasmine.yml +76 -0
  88. data/spec/javascripts/support/jasmine_config.rb +23 -0
  89. data/spec/javascripts/support/jasmine_runner.rb +20 -0
  90. data/spec/launchers/all_but_requests.rb +0 -0
  91. data/spec/launchers/all_specs.rb +0 -0
  92. data/spec/launchers/requests.rb +0 -0
  93. data/spec/models/user_spec.rb +447 -0
  94. data/spec/spec_helper.rb +44 -0
  95. data/spec/support/geocoding.rb +14 -0
  96. data/spec/support/matchers.rb +43 -0
  97. metadata +364 -31
  98. data/LICENSE.txt +0 -21
  99. data/app/assets/javascripts/gmaps4rails/all_apis.js +0 -5
  100. data/app/assets/javascripts/gmaps4rails/bing.js +0 -2
  101. data/app/assets/javascripts/gmaps4rails/googlemaps.js +0 -2
  102. data/app/assets/javascripts/gmaps4rails/mapquest.js +0 -2
  103. data/app/assets/javascripts/gmaps4rails/openlayers.js +0 -2
  104. data/app/views/gmaps4rails/_html.html.erb +0 -12
  105. data/app/views/gmaps4rails/_scripts.html.erb +0 -37
  106. data/lib/gmaps4rails/js_handler.rb +0 -112
  107. data/lib/gmaps4rails/json_handler.rb +0 -116
  108. data/public/images/marker.png +0 -0
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20120408170155) do
15
+
16
+ create_table "users", :force => true do |t|
17
+ t.string "name"
18
+ t.string "address"
19
+ t.string "norm_address"
20
+ t.string "sec_address"
21
+ t.string "picture"
22
+ t.float "latitude"
23
+ t.float "longitude"
24
+ t.boolean "gmaps"
25
+ t.datetime "created_at", :null => false
26
+ t.datetime "updated_at", :null => false
27
+ end
28
+
29
+ end
File without changes
File without changes
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,22 @@
1
+ function Player() {
2
+ }
3
+ Player.prototype.play = function(song) {
4
+ this.currentlyPlayingSong = song;
5
+ this.isPlaying = true;
6
+ };
7
+
8
+ Player.prototype.pause = function() {
9
+ this.isPlaying = false;
10
+ };
11
+
12
+ Player.prototype.resume = function() {
13
+ if (this.isPlaying) {
14
+ throw new Error("song is already playing");
15
+ }
16
+
17
+ this.isPlaying = true;
18
+ };
19
+
20
+ Player.prototype.makeFavorite = function() {
21
+ this.currentlyPlayingSong.persistFavoriteStatus(true);
22
+ };
@@ -0,0 +1,7 @@
1
+ function Song() {
2
+ }
3
+
4
+ Song.prototype.persistFavoriteStatus = function(value) {
5
+ // something complicated
6
+ throw new Error("not yet implemented");
7
+ };
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,23 @@
1
+ FactoryGirl.define do
2
+ factory :user do
3
+
4
+ trait :paris do
5
+ address "Paris, France"
6
+ end
7
+
8
+ trait :with_pic do
9
+ picture "http://www.blankdots.com/img/github-32x32.png"
10
+ end
11
+
12
+ trait :invalid do
13
+ address "home"
14
+ end
15
+
16
+ name "Guinea Pig"
17
+ address "Toulon, France"
18
+
19
+ factory :user_paris, :traits => [:paris]
20
+ factory :user_with_pic, :traits => [:with_pic]
21
+ factory :invalid_user, :traits => [:invalid]
22
+ end
23
+ end
@@ -0,0 +1,103 @@
1
+ var gmap;
2
+
3
+ beforeEach(function() {
4
+ gmap = new Gmaps4RailsGoogle();
5
+ });
6
+
7
+ describe("Gmaps4Rails", function() {
8
+
9
+ describe("Basic methods", function() {
10
+
11
+ describe("exists", function() {
12
+ it("should render true for valid cases", function() {
13
+ var test = { "ok": "I exist", "null": null}
14
+ fake_array = [];
15
+ expect(gmap.exists(test.ok)).toBeTruthy();
16
+ expect(gmap.exists(test.null)).toBeTruthy();
17
+ expect(gmap.exists(fake_array)).toBeTruthy();
18
+ });
19
+ it("should render false for invalid cases", function() {
20
+ var test = { "empty": ""};
21
+ expect(gmap.exists(test.empty)).toBeFalsy();
22
+ expect(gmap.exists(test.unknown)).toBeFalsy();
23
+ });
24
+ });
25
+
26
+ describe("merges", function() {
27
+
28
+ beforeEach(function() {
29
+ this.default_obj = {
30
+ foo: 1,
31
+ bar: 1
32
+ };
33
+ this.obj = {
34
+ bar: 2,
35
+ baz: 3
36
+ };
37
+ this.expected_result = {
38
+ foo: 1,
39
+ bar: 2,
40
+ baz: 3
41
+ };
42
+ });
43
+
44
+
45
+ describe("mergeWithDefault", function() {
46
+ it("should merge default_object within object", function() {
47
+ gmap.default_foo = this.default_obj;
48
+ gmap.foo = this.obj;
49
+ expect(gmap.mergeWithDefault("foo")).toBeTruthy();
50
+ expect(gmap.foo).toEqual(this.expected_result);
51
+ });
52
+ });
53
+
54
+ describe("mergeObjectWithDefault", function() {
55
+ it("should return proper values without changing actual objects", function() {
56
+ var copy_default = this.default_obj;
57
+ var copy_obj = this.obj;
58
+ var result = gmap.mergeObjectWithDefault(copy_obj, copy_default);
59
+ expect(result).toEqual(this.expected_result);
60
+ expect(this.obj).toEqual(copy_obj);
61
+ expect(this.default_obj).toEqual(copy_default);
62
+ });
63
+ });
64
+ });
65
+
66
+
67
+ describe("random", function() {
68
+ it("should return a number between between -1 and 1", function() {
69
+ for (var i = 0; i < 100; ++i) {
70
+ var x = gmap.random();
71
+ expect(x).toBeLessThan(1);
72
+ expect(x).toBeGreaterThan(-1);
73
+ }
74
+ });
75
+ });
76
+
77
+ describe("randomize", function() {
78
+ it("should alter coordinates within a determined radius", function() {
79
+ gmap.markers_conf.max_random_distance = 100;
80
+ for (var i = 0; i < 100; ++i) {
81
+ var x = gmap.randomize(0,0);
82
+ var distanceInMeters = geoHelpers.getDistanceFromO(x[0], x[1])/1000;
83
+ //this test coul seem weird, but because latitude AND longitude could be moved by 100m, the highest diagonal is 142m
84
+ expect(distanceInMeters).toBeLessThan(142);
85
+ }
86
+ });
87
+ });
88
+ });
89
+ });
90
+
91
+ describe("Gmaps", function() {
92
+
93
+ it("should initialize all requested maps", function() {
94
+ Gmaps.load_test1 = jasmine.createSpy('myStub');
95
+ Gmaps.load_test2 = jasmine.createSpy('myStub');
96
+ Gmaps.test1 = true;
97
+ Gmaps.test2 = true;
98
+ Gmaps.loadMaps();
99
+ expect(Gmaps.load_test1).toHaveBeenCalled();
100
+ expect(Gmaps.load_test2).toHaveBeenCalled();
101
+ });
102
+
103
+ });
File without changes
@@ -0,0 +1,87 @@
1
+ RichMarker = function(args) {
2
+ return { "who": "I'm RichMarker" };
3
+ }
4
+
5
+ google = new function(){
6
+ this.maps = new function(){
7
+ this.Point = function(a,b){
8
+ return [a, b];
9
+ };
10
+ this.LatLng = function(a,b){
11
+ return [a, b];
12
+ };
13
+ this.Map = function(arg1, arg2){
14
+ return { "who": "I'm map"};
15
+ };
16
+ this.LatLngBounds = function(){
17
+ return [];
18
+ };
19
+ this.MarkerImage = function(markerPicture, markerSize, origin, anchor, scaledSize){
20
+ return {"who": "Point", "picture": markerPicture, "size": markerSize, "url": origin, "anchor": anchor, "scale": scaledSize};
21
+ };
22
+ this.Marker = function(args){
23
+ return { "who": "I'm marker" };
24
+ };
25
+ this.Marker.prototype.map = null;
26
+ this.Marker.prototype.setMap = function(mapId) { this.map = mapId; };
27
+
28
+ this.Size = function(w, h){
29
+ return [w,h];
30
+ };
31
+ this.MapTypeId = function(){
32
+ return "MapTypeId";
33
+ };
34
+ this.InfoWindow = function(){
35
+
36
+ };
37
+ this.event = new function(){
38
+ this.addListener = function(){};
39
+ }
40
+ };
41
+ };
42
+
43
+ geoHelpers = new function(){
44
+ //returns distance in km
45
+ this.getDistance = function(lat1, lon1, lat2, lon2){
46
+ var R = 6371; // km
47
+ var dLat = (lat2-lat1).toRad();
48
+ var dLon = (lon2-lon1).toRad();
49
+ var lat1 = lat1.toRad();
50
+ var lat2 = lat2.toRad();
51
+ var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
52
+ Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
53
+ var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
54
+ return(R * c);
55
+ };
56
+ //just return distance from point 0, 0
57
+ this.getDistanceFromO = function(lat1, lon1){
58
+ return(geoHelpers.getDistance(lat1, lon1, 0, 0));
59
+ };
60
+ };
61
+
62
+ MarkerClusterer = function() { return {"who": "I'm Clusterer"}; };
63
+
64
+ Number.prototype.toRad = function() {
65
+ return this * Math.PI / 180;
66
+ };
67
+
68
+ getRawMarkers = function() {
69
+ return [{ "lng": "5.9311119", "latitude": "43.1251606"}
70
+ ,{ "lng": "2.3509871", "lat": "48.8566667"}
71
+ ,{ "lng": "2.3509871", "lat": "48.8566667", "serviceObject": true}
72
+ ,{ "lng": "2.3509871", "lat": "48.8566667", "serviceObject": false}];
73
+ };
74
+
75
+ getFullMarker = function() {
76
+ return { "lng": "5", "lat": "43", "picture": "picture", "width": "width", "height": "height", "title": "title", "marker_anchor": [0,1], "shadow_anchor": [1,0], "shadow_picture": "shadow_picture", "shadow_width": "shadow_width", "shadow_height": "shadow_height", "draggable": true, "description": "infowindow content" };
77
+ };
78
+
79
+ getEmptyMarker = function() {
80
+ return { "lng": "5", "lat": "43"};
81
+ };
82
+
83
+ clearMarkerTraces = function(){
84
+ gmap.markers = [];
85
+ gmap.markers_conf.offset = 0;
86
+ gmap.markers_conf.randomize = false;
87
+ };
@@ -0,0 +1,49 @@
1
+ var gmap;
2
+
3
+ beforeEach(function() {
4
+ gmap = new Gmaps4RailsGoogle();
5
+ });
6
+
7
+ describe("initialization", function() {
8
+
9
+ beforeEach(function() {
10
+ this.default_config = {
11
+ maxZoom: gmap.map_options.maxZoom,
12
+ minZoom: gmap.map_options.minZoom,
13
+ zoom: gmap.map_options.zoom,
14
+ center: gmap.createLatLng(gmap.map_options.center_latitude, gmap.map_options.center_longitude),
15
+ mapTypeId: google.maps.MapTypeId[gmap.map_options.type],
16
+ mapTypeControl: gmap.map_options.mapTypeControl,
17
+ disableDefaultUI: gmap.map_options.disableDefaultUI,
18
+ disableDoubleClickZoom: gmap.map_options.disableDoubleClickZoom,
19
+ draggable: gmap.map_options.draggable
20
+ }
21
+
22
+ spyOn(document, "getElementById").andReturn("map");
23
+ spyOn(google.maps, "Map");
24
+ });
25
+
26
+ it("should send default config when no raw provided", function() {
27
+ gmap.createMap();
28
+ expect(google.maps.Map).toHaveBeenCalledWith("map", this.default_config);
29
+ });
30
+
31
+ it("should take default config passed", function() {
32
+ gmap.map_options.raw = { disableDefaultUI: true, heading: 20 };
33
+ gmap.createMap();
34
+ var correct_options = {
35
+ maxZoom: gmap.map_options.maxZoom,
36
+ minZoom: gmap.map_options.minZoom,
37
+ zoom: gmap.map_options.zoom,
38
+ center: gmap.createLatLng(gmap.map_options.center_latitude, gmap.map_options.center_longitude),
39
+ mapTypeId: google.maps.MapTypeId[gmap.map_options.type],
40
+ mapTypeControl: gmap.map_options.mapTypeControl,
41
+ disableDefaultUI: true,
42
+ disableDoubleClickZoom: gmap.map_options.disableDoubleClickZoom,
43
+ draggable: gmap.map_options.draggable,
44
+ heading: 20
45
+ };
46
+ expect(google.maps.Map).toHaveBeenCalledWith("map", correct_options);
47
+
48
+ });
49
+ });
@@ -0,0 +1,368 @@
1
+ var gmap;
2
+
3
+ beforeEach(function() {
4
+ gmap = new Gmaps4RailsGoogle();
5
+ });
6
+
7
+ describe("Images Handling", function() {
8
+
9
+ beforeEach(function(){
10
+ gmap.markerImages = [{"url": "test0"}, {"url": "test1"}, {"url": "test2"}, {"url": "test3"}];
11
+ });
12
+
13
+ afterEach(function(){
14
+ gmap.markerImages = [];
15
+ });
16
+
17
+ describe("includeMarkerImage", function() {
18
+ it("should retrieve the index when url is in array", function() {
19
+ expect(gmap.includeMarkerImage(gmap.markerImages, "test2")).toEqual(2);
20
+ });
21
+
22
+ it("should return false when the url isn't in array", function() {
23
+ expect(gmap.includeMarkerImage(gmap.markerImages, "test4")).toBeFalsy();
24
+ });
25
+ });
26
+
27
+ describe("createOrRetrieveImage", function() {
28
+ it("should return existing image when image already exists", function() {
29
+ var image = gmap.createOrRetrieveImage("test1", 20, 20, null);
30
+ expect(image).toEqual({"url": "test1"});
31
+ });
32
+
33
+ it("should return new image when image doesn't exist yet", function() {
34
+ var image = gmap.createOrRetrieveImage("test4", 20, 20, null);
35
+ expect(image.who).toEqual("Point");
36
+ });
37
+ });
38
+ });
39
+
40
+ describe("createImageAnchorPosition", function() {
41
+ it("should render null when no coordinates passed", function() {
42
+ expect(gmap.createImageAnchorPosition(null)).toEqual(null);
43
+ });
44
+
45
+ it("should render a Point with same coordinates as passed", function() {
46
+ expect(gmap.createImageAnchorPosition([10, 20])[0]).toEqual(10);
47
+ expect(gmap.createImageAnchorPosition([10, 20])[1]).toEqual(20);
48
+ });
49
+ });
50
+
51
+ describe("createServiceMarkersFromMarkers", function() {
52
+ beforeEach(function() {
53
+ gmap.markers = getRawMarkers();
54
+ });
55
+
56
+ afterEach(function() {
57
+ clearMarkerTraces();
58
+ });
59
+
60
+ describe("launch method directly", function() {
61
+ beforeEach(function() {
62
+ spyOn(gmap, "createInfoWindow");
63
+ spyOn(gmap, "createSidebar");
64
+ gmap.createServiceMarkersFromMarkers();
65
+ });
66
+
67
+ it("should create objects for each marker", function() {
68
+ for (var i = 0; i < gmap.markers.length; ++i) {
69
+ expect(gmap.markers[i].serviceObject).toBeDefined();
70
+ }
71
+ });
72
+
73
+ it("should set offset properly", function() {
74
+ expect(gmap.markers_conf.offset).toEqual(gmap.markers.length);
75
+ });
76
+
77
+ // it("should trigger InfoWindow only with markers without serviceObject", function() {
78
+ // expect(gmap.createInfoWindow).toHaveBeenCalledWith(gmap.markers[0]);
79
+ // expect(gmap.createInfoWindow).toHaveBeenCalledWith(gmap.markers[1]);
80
+ // expect(gmap.createInfoWindow).not.toHaveBeenCalledWith(gmap.markers[2]);
81
+ // });
82
+ //
83
+ // it("should trigger createSidebar only with markers without serviceObject", function() {
84
+ // expect(gmap.createSidebar).toHaveBeenCalledWith(gmap.markers[0]);
85
+ // expect(gmap.createSidebar).toHaveBeenCalledWith(gmap.markers[1]);
86
+ // expect(gmap.createSidebar).not.toHaveBeenCalledWith(gmap.markers[2]);
87
+ // });
88
+ });
89
+
90
+ describe("required delay to launch method", function() {
91
+
92
+ it("should randomize if enabled", function() {
93
+ gmap.markers_conf.randomize = true;
94
+ spyOn(gmap, "randomize").andReturn([0,1]);
95
+ gmap.createServiceMarkersFromMarkers();
96
+ expect(gmap.randomize).toHaveBeenCalled();
97
+ });
98
+
99
+ it("should not randomize it not requested", function() {
100
+ gmap.markers_conf.randomize = false;
101
+ spyOn(gmap, "randomize");
102
+ gmap.createServiceMarkersFromMarkers();
103
+ expect(gmap.randomize).not.toHaveBeenCalled();
104
+ });
105
+
106
+ });
107
+ });
108
+
109
+ describe("createServiceMarkersFromMarkers full stack", function() {
110
+
111
+ afterEach(function() {
112
+ clearMarkerTraces();
113
+ gmap.map = null;
114
+ });
115
+
116
+ it("should process all attributes from a marker (without default values)", function() {
117
+ var marker = getFullMarker();
118
+ gmap.markers = [marker];
119
+ gmap.map = "map";
120
+
121
+ spyOn(gmap, "createMarker");
122
+
123
+ gmap.createServiceMarkersFromMarkers();
124
+
125
+ expect(gmap.createMarker).toHaveBeenCalledWith({
126
+ "marker_picture": marker.picture,
127
+ "marker_width": marker.width,
128
+ "marker_height": marker.height,
129
+ "marker_title": marker.title,
130
+ "marker_anchor": marker.marker_anchor,
131
+ "shadow_anchor": marker.shadow_anchor,
132
+ "shadow_picture": marker.shadow_picture,
133
+ "shadow_width": marker.shadow_width,
134
+ "shadow_height": marker.shadow_height,
135
+ "marker_draggable": marker.draggable,
136
+ "rich_marker": null,
137
+ "zindex": null,
138
+ "Lat": marker.lat,
139
+ "Lng": marker.lng,
140
+ "index": 0
141
+ });
142
+
143
+ });
144
+
145
+ it("should process all attributes from a marker (with default values)", function() {
146
+ var marker = getEmptyMarker();
147
+ gmap.markers = [marker];
148
+ gmap.map = "map";
149
+
150
+ spyOn(gmap, "createMarker");
151
+
152
+ gmap.createServiceMarkersFromMarkers();
153
+
154
+ expect(gmap.createMarker).toHaveBeenCalledWith({
155
+ "marker_picture": gmap.markers_conf.picture,
156
+ "marker_width": gmap.markers_conf.width,
157
+ "marker_height": gmap.markers_conf.length,
158
+ "marker_title": null,
159
+ "marker_anchor": null,
160
+ "shadow_anchor": null,
161
+ "shadow_picture": null,
162
+ "shadow_width": null,
163
+ "shadow_height": null,
164
+ "marker_draggable": gmap.markers_conf.draggable,
165
+ "rich_marker": null,
166
+ "zindex": null,
167
+ "Lat": marker.lat,
168
+ "Lng": marker.lng,
169
+ "index": 0
170
+ });
171
+
172
+ });
173
+
174
+ it("should create Richmarker", function() {
175
+ var args = { "rich_marker": true, "marker_anchor":null };
176
+ var marker = gmap.createMarker(args);
177
+ expect(marker.who).toEqual("I'm RichMarker");
178
+ });
179
+
180
+ it("should create marker with picture", function() {
181
+ var args = { "marker_picture": "foo.png", "rich_marker": null };
182
+ spyOn(gmap, "createImageAnchorPosition");
183
+ spyOn(gmap, "createOrRetrieveImage");
184
+ spyOn(gmap, "mergeObjectWithDefault");
185
+ var marker = gmap.createMarker(args);
186
+ expect(marker.who).toEqual("I'm marker");
187
+ expect(gmap.createImageAnchorPosition).toHaveBeenCalled();
188
+ });
189
+
190
+ it("should create marker with no picture", function() {
191
+ var args = { "marker_picture": "", "rich_marker": null };
192
+ spyOn(gmap, "createImageAnchorPosition");
193
+ spyOn(gmap, "createOrRetrieveImage");
194
+ spyOn(gmap, "mergeObjectWithDefault");
195
+ var marker = gmap.createMarker(args);
196
+ expect(marker.who).toEqual("I'm marker");
197
+ expect(gmap.createImageAnchorPosition).not.toHaveBeenCalled();
198
+ });
199
+
200
+
201
+ });
202
+
203
+ describe("create_markers", function() {
204
+
205
+ it("should call all necessary methods", function() {
206
+ spyOn(gmap, "createServiceMarkersFromMarkers");
207
+ spyOn(gmap, "clusterize");
208
+ gmap.create_markers();
209
+ expect(gmap.createServiceMarkersFromMarkers).toHaveBeenCalled();
210
+ expect(gmap.clusterize).toHaveBeenCalled();
211
+ });
212
+
213
+ it("should set offset properly", function() {
214
+ spyOn(gmap, "createServiceMarkersFromMarkers");
215
+ spyOn(gmap, "clusterize");
216
+ spyOn(gmap, "adjustMapToBounds");
217
+ gmap.create_markers();
218
+ //offset should be 0 here: createServiceMarkersFromMarkers has been mocked
219
+ expect(gmap.markers_conf.offset).toEqual(0);
220
+ });
221
+
222
+ it("should set offset properly", function() {
223
+ //spyOn(gmap, "createServiceMarkersFromMarkers");
224
+ spyOn(gmap, "clusterize");
225
+ spyOn(gmap, "adjustMapToBounds");
226
+ gmap.markers_conf.offset = 2;
227
+ gmap.markers = getRawMarkers();
228
+ gmap.create_markers();
229
+ //offset should not have changed here: createServiceMarkersFromMarkers has been mocked
230
+ expect(gmap.markers[0]).toBeUndefined;
231
+ expect(gmap.markers[1]).toBeUndefined;
232
+ expect(gmap.markers_conf.offset).toEqual(4);
233
+ });
234
+
235
+
236
+ });
237
+
238
+ describe("generic markers methods", function() {
239
+
240
+ beforeEach(function() {
241
+ gmap.markers = getRawMarkers();
242
+ });
243
+
244
+ describe("showMarkers", function() {
245
+ it("should call show with all markers", function() {
246
+ spyOn(gmap, "showMarker");
247
+ gmap.showMarkers();
248
+ expect(gmap.showMarker.callCount).toEqual(gmap.markers.length);
249
+ });
250
+ });
251
+
252
+ describe("hideMarkers", function() {
253
+ it("should call hide with all markers", function() {
254
+ spyOn(gmap, "hideMarker");
255
+ gmap.hideMarkers();
256
+ expect(gmap.hideMarker.callCount).toEqual(gmap.markers.length);
257
+ });
258
+ });
259
+
260
+ describe("clearMarkers", function() {
261
+ it("should call clear with all markers", function() {
262
+ spyOn(gmap, "clearMarker");
263
+ gmap.clearMarkers();
264
+ expect(gmap.clearMarker.callCount).toEqual(gmap.markers.length);
265
+ });
266
+ });
267
+ });
268
+
269
+ describe("replaceMarkers", function() {
270
+ it("should call all necessary methods", function() {
271
+ gmap.markers = ["full_of_markers"];
272
+ spyOn(gmap, "clearMarkers");
273
+ spyOn(gmap, "createLatLngBounds");
274
+ spyOn(gmap, "resetSidebarContent");
275
+ spyOn(gmap, "addMarkers");
276
+ gmap.replaceMarkers(getRawMarkers());
277
+ //test if everything is reset (nothing added because addMarkers is stubbed)
278
+ expect(gmap.markers).toEqual([]);
279
+ //test if necessary methods are well called
280
+ expect(gmap.clearMarkers).toHaveBeenCalled();
281
+ expect(gmap.createLatLngBounds).toHaveBeenCalled();
282
+ expect(gmap.resetSidebarContent).toHaveBeenCalled();
283
+ expect(gmap.addMarkers).toHaveBeenCalledWith(getRawMarkers());
284
+ expect(gmap.markers_conf.offset).toEqual(0);
285
+ });
286
+ });
287
+
288
+ describe("addMarkers", function() {
289
+ it("should concat markers and create them", function() {
290
+ gmap.markers = [{"hello": "dolly"}];
291
+ spyOn(gmap, "clearMarkers");
292
+ spyOn(gmap, "adjustMapToBounds");
293
+ spyOn(gmap, "createMarker");
294
+ spyOn(gmap, "createInfoWindow");
295
+ spyOn(gmap, "createSidebar");
296
+
297
+ gmap.addMarkers(getRawMarkers());
298
+ expect(gmap.markers.length).toEqual(1 + getRawMarkers().length);
299
+ expect(gmap.markers_conf.offset).toEqual(1 + getRawMarkers().length);
300
+ expect(gmap.adjustMapToBounds).toHaveBeenCalled();
301
+ });
302
+ });
303
+
304
+ describe("clusterize", function() {
305
+ beforeEach(function() {
306
+ gmap.markers = getRawMarkers();
307
+ spyOn(gmap, "createClusterer");
308
+ spyOn(gmap, "clearClusterer");
309
+ });
310
+
311
+ afterEach(function() {
312
+ gmap.markers_conf.do_clustering = true;
313
+ });
314
+
315
+ it("should do nothing when do_clustering is false", function() {
316
+ gmap.markers_conf.do_clustering = false;
317
+ gmap.clusterize();
318
+ expect(gmap.createClusterer).not.toHaveBeenCalled();
319
+ });
320
+
321
+ it("should launch createClusterer when do_clustering is true", function() {
322
+ gmap.markers_conf.do_clustering = true;
323
+ gmap.clusterize();
324
+ expect(gmap.createClusterer).toHaveBeenCalledWith([ undefined, undefined, true, false]);
325
+ });
326
+
327
+ it("should not clear previous clusterer if null", function() {
328
+ gmap.markerClusterer = null;
329
+ gmap.clusterize();
330
+ expect(gmap.clearClusterer).not.toHaveBeenCalled();
331
+ });
332
+
333
+ // it("should clear previous clusterer if exists", function() {
334
+ // gmap.markerClusterer = [];
335
+ // gmap.clusterize();
336
+ // expect(gmap.clearClusterer).toHaveBeenCalled();
337
+ // });
338
+
339
+ });
340
+
341
+ describe("infowindows", function() {
342
+ beforeEach(function() {
343
+ gmap.markers = [getFullMarker()];
344
+ this.initial_description = getFullMarker().description;
345
+ });
346
+
347
+ it("infowindow should contain marker's description", function() {
348
+ gmap.createInfoWindow(gmap.markers[0]);
349
+ expect(gmap.markers[0].description).toEqual(this.initial_description);
350
+ });
351
+
352
+ it("infowindow should contain template's content", function() {
353
+ gmap.jsTemplate = function(marker_container){
354
+ var output = "ok ";
355
+ output += marker_container.description;
356
+ return output;
357
+ }
358
+ gmap.createInfoWindow(gmap.markers[0]);
359
+ expect(gmap.markers[0].description).toEqual("ok " + this.initial_description);
360
+ });
361
+
362
+ it("infowindow should not contain template's content if it's not a function", function() {
363
+ gmap.jsTemplate = "ok ";
364
+ gmap.createInfoWindow(gmap.markers[0]);
365
+ expect(gmap.markers[0].description).toEqual(this.initial_description);
366
+ });
367
+
368
+ });