gmaps4rails 1.5.7 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. metadata +6 -386
  3. data/.gitignore +0 -17
  4. data/.travis.yml +0 -10
  5. data/Gemfile +0 -9
  6. data/Gemfile.lock +0 -182
  7. data/Guardfile +0 -24
  8. data/MIT-LICENSE +0 -20
  9. data/README.rdoc +0 -135
  10. data/Rakefile +0 -4
  11. data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +0 -444
  12. data/app/assets/javascripts/gmaps4rails/gmaps4rails.bing.js.coffee +0 -174
  13. data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +0 -339
  14. data/app/assets/javascripts/gmaps4rails/gmaps4rails.mapquest.js.coffee +0 -145
  15. data/app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee +0 -261
  16. data/app/views/gmaps4rails/_gmaps4rails.html.erb +0 -20
  17. data/gmaps4rails.gemspec +0 -39
  18. data/lib/generators/gmaps4rails/install_generator.rb +0 -48
  19. data/lib/generators/templates/README +0 -2
  20. data/lib/gmaps4rails.rb +0 -26
  21. data/lib/gmaps4rails/acts_as_gmappable.rb +0 -54
  22. data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +0 -40
  23. data/lib/gmaps4rails/api_wrappers/direction.rb +0 -87
  24. data/lib/gmaps4rails/api_wrappers/geocoder.rb +0 -54
  25. data/lib/gmaps4rails/api_wrappers/places.rb +0 -74
  26. data/lib/gmaps4rails/base.rb +0 -119
  27. data/lib/gmaps4rails/extensions/enumerable.rb +0 -14
  28. data/lib/gmaps4rails/extensions/hash.rb +0 -9
  29. data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +0 -33
  30. data/lib/gmaps4rails/js_builder.rb +0 -157
  31. data/lib/gmaps4rails/json_builder.rb +0 -140
  32. data/lib/gmaps4rails/model_handler.rb +0 -101
  33. data/lib/gmaps4rails/version.rb +0 -3
  34. data/lib/gmaps4rails/view_helper.rb +0 -175
  35. data/lib/tasks/gmaps4rails_tasks.rake +0 -4
  36. data/lib/tasks/jasmine.rake +0 -8
  37. data/public/javascripts/gmaps4rails/gmaps4rails.base.js +0 -464
  38. data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +0 -226
  39. data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +0 -430
  40. data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +0 -178
  41. data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +0 -265
  42. data/public/stylesheets/gmaps4rails.css +0 -24
  43. data/spec/dummy/.gitignore +0 -2
  44. data/spec/dummy/.rspec +0 -1
  45. data/spec/dummy/README.rdoc +0 -261
  46. data/spec/dummy/Rakefile +0 -7
  47. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  48. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  49. data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +0 -24
  50. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  51. data/spec/dummy/app/controllers/users_controller.rb +0 -101
  52. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  53. data/spec/dummy/app/mailers/.gitkeep +0 -0
  54. data/spec/dummy/app/models/.gitkeep +0 -0
  55. data/spec/dummy/app/models/place.rb +0 -16
  56. data/spec/dummy/app/models/user.rb +0 -12
  57. data/spec/dummy/app/views/layouts/application.html.erb +0 -16
  58. data/spec/dummy/app/views/users/_form.html.erb +0 -37
  59. data/spec/dummy/app/views/users/_map.html.erb +0 -5
  60. data/spec/dummy/app/views/users/edit.html.erb +0 -6
  61. data/spec/dummy/app/views/users/index.html.erb +0 -260
  62. data/spec/dummy/app/views/users/new.html.erb +0 -5
  63. data/spec/dummy/app/views/users/show.html.erb +0 -30
  64. data/spec/dummy/config.ru +0 -4
  65. data/spec/dummy/config/application.rb +0 -62
  66. data/spec/dummy/config/boot.rb +0 -10
  67. data/spec/dummy/config/database.yml +0 -25
  68. data/spec/dummy/config/environment.rb +0 -5
  69. data/spec/dummy/config/environments/development.rb +0 -37
  70. data/spec/dummy/config/environments/production.rb +0 -67
  71. data/spec/dummy/config/environments/test.rb +0 -37
  72. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  73. data/spec/dummy/config/initializers/gmaps4rails.rb +0 -1
  74. data/spec/dummy/config/initializers/inflections.rb +0 -15
  75. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  76. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  77. data/spec/dummy/config/initializers/session_store.rb +0 -8
  78. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  79. data/spec/dummy/config/locales/en.yml +0 -5
  80. data/spec/dummy/config/routes.rb +0 -60
  81. data/spec/dummy/db/migrate/20120408170155_create_users.rb +0 -16
  82. data/spec/dummy/db/schema.rb +0 -29
  83. data/spec/dummy/lib/assets/.gitkeep +0 -0
  84. data/spec/dummy/log/.gitkeep +0 -0
  85. data/spec/dummy/public/404.html +0 -26
  86. data/spec/dummy/public/422.html +0 -26
  87. data/spec/dummy/public/500.html +0 -25
  88. data/spec/dummy/public/favicon.ico +0 -0
  89. data/spec/dummy/public/javascripts/Player.js +0 -22
  90. data/spec/dummy/public/javascripts/Song.js +0 -7
  91. data/spec/dummy/public/logo.png +0 -0
  92. data/spec/dummy/script/rails +0 -6
  93. data/spec/factories/place_factory.rb +0 -16
  94. data/spec/factories/user_factory.rb +0 -23
  95. data/spec/fixtures/google_direction_valid.json +0 -65
  96. data/spec/fixtures/google_geocoding_toulon_france.json +0 -58
  97. data/spec/fixtures/google_places_valid.json +0 -45
  98. data/spec/fixtures/google_wrong_geocoding.json +0 -4
  99. data/spec/javascripts/basic_methods_spec.js +0 -103
  100. data/spec/javascripts/helpers/.gitkeep +0 -0
  101. data/spec/javascripts/helpers/SpecHelper.js +0 -87
  102. data/spec/javascripts/map_spec.js +0 -49
  103. data/spec/javascripts/markers_methods_spec.js +0 -368
  104. data/spec/javascripts/mocks_spec.js +0 -27
  105. data/spec/javascripts/support/jasmine.yml +0 -10
  106. data/spec/javascripts/support/jasmine_config.rb +0 -23
  107. data/spec/javascripts/support/jasmine_runner.rb +0 -20
  108. data/spec/launchers/all_but_requests.rb +0 -0
  109. data/spec/launchers/all_specs.rb +0 -0
  110. data/spec/launchers/requests.rb +0 -0
  111. data/spec/lib/base_spec.rb +0 -59
  112. data/spec/lib/direction_spec.rb +0 -53
  113. data/spec/lib/geocoder_spec.rb +0 -46
  114. data/spec/lib/js_builder_spec.rb +0 -139
  115. data/spec/lib/json_builder_spec.rb +0 -232
  116. data/spec/lib/places_spec.rb +0 -25
  117. data/spec/models/place_spec.rb +0 -35
  118. data/spec/models/user_spec.rb +0 -187
  119. data/spec/spec_helper.rb +0 -44
  120. data/spec/support/geocoding.rb +0 -41
  121. data/spec/support/matchers.rb +0 -73
@@ -1,23 +0,0 @@
1
- module Jasmine
2
- class Config
3
-
4
- # Add your overrides or custom config code here
5
-
6
- end
7
- end
8
-
9
-
10
- # Note - this is necessary for rspec2, which has removed the backtrace
11
- module Jasmine
12
- class SpecBuilder
13
- def declare_spec(parent, spec)
14
- me = self
15
- example_name = spec["name"]
16
- @spec_ids << spec["id"]
17
- backtrace = @example_locations[parent.description + " " + example_name]
18
- parent.it example_name, {} do
19
- me.report_spec(spec["id"])
20
- end
21
- end
22
- end
23
- end
@@ -1,20 +0,0 @@
1
- $:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
2
-
3
- require 'rubygems'
4
- require 'jasmine'
5
- require 'rspec'
6
- jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
7
- require jasmine_config_overrides if File.exists?(jasmine_config_overrides)
8
-
9
- jasmine_config = Jasmine::Config.new
10
- spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
11
-
12
- should_stop = false
13
-
14
- RSpec.configuration.after(:suite) do
15
- spec_builder.stop if should_stop
16
- end
17
-
18
- spec_builder.start
19
- should_stop = true
20
- spec_builder.declare_suites
File without changes
File without changes
File without changes
@@ -1,59 +0,0 @@
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
-
@@ -1,53 +0,0 @@
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
@@ -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,139 +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\.polygons = (.*?);/m).first.first
22
-
23
- actual_polygons.should be_same_json_as expected_polygons
24
- result.should include "Gmaps.map.create_polygons();"
25
- end
26
-
27
- it "should format polylines" do
28
- expected_polylines = '[[
29
- {"longitude": -122.214897, "latitude": 37.772323},
30
- {"longitude": -157.821856, "latitude": 21.291982},
31
- {"longitude": 178.431, "latitude": -18.142599},
32
- {"longitude": 153.027892, "latitude": -27.46758}
33
- ],
34
- [
35
- {"longitude": -120.214897, "latitude": 30.772323, "strokeColor": "#000", "strokeWeight" : 2 },
36
- {"longitude": -10.821856, "latitude": 50.291982}
37
- ]]'
38
- options_hash = {
39
- :polylines => { :data => expected_polylines }
40
- }
41
- result = options_hash.to_gmaps4rails
42
- actual_polylines = result.scan(/Gmaps\.map\.polylines = (.*?);/m).first.first
43
-
44
- actual_polylines.should be_same_json_as expected_polylines
45
- result.should include "Gmaps.map.create_polylines();"
46
- end
47
-
48
- it "should format circles" do
49
- expected_circles = '[
50
- {"longitude": -122.214897, "latitude": 37.772323, "radius": 1000000},
51
- {"longitude": 122.214897, "latitude": 37.772323, "radius": 1000000, "strokeColor": "#FF0000"}
52
- ]'
53
- options_hash = {
54
- :circles => { :data => expected_circles }
55
- }
56
- result = options_hash.to_gmaps4rails
57
- actual_circles = result.scan(/Gmaps\.map\.circles = (.*?);/m).first.first
58
-
59
- actual_circles.should be_same_json_as expected_circles
60
- result.should include "Gmaps.map.create_circles();"
61
- end
62
-
63
- it "should format markers" do
64
- expected_markers = '[{ "description": "", "title": "", "longitude": "5.9311119", "latitude": "43.1251606", "picture": "", "width": "", "height": "" } ,{ "description": "", "title": "", "longitude": "2.3509871", "latitude": "48.8566667", "picture": "", "width": "", "height": "" } ]'
65
- options_hash = {
66
- :markers => { :data => expected_markers }
67
- }
68
- result = options_hash.to_gmaps4rails
69
- actual_markers = result.scan(/Gmaps\.map\.markers = (.*?);/m).first.first
70
-
71
- actual_markers.should be_same_json_as expected_markers
72
- result.should include "Gmaps.map.create_markers();"
73
- end
74
-
75
- it "should format map" do
76
- options_hash = {
77
- :map_options => { :type => "SATELLITE", :center_longitude => 180, "zoom" => 3, :raw => '{ok: true}'}
78
- }
79
- result = options_hash.to_gmaps4rails
80
-
81
- result.should include "Gmaps.map = new Gmaps4RailsGoogle();"
82
- result.should include "Gmaps.map.map_options.center_longitude = 180;"
83
- result.should include "Gmaps.map.map_options.type = \"SATELLITE\""
84
- result.should include "Gmaps.map.map_options.raw = {ok: true};"
85
- result.should include "Gmaps.map.map_options.zoom = 3;"
86
- result.should include "Gmaps.map.initialize();"
87
- end
88
-
89
- it "should invoke callback" do
90
- result = {}.to_gmaps4rails
91
- result.should include "Gmaps.map.callback();"
92
- end
93
-
94
- it "should format kml" do
95
- expected_kml = '[{ url: "http://www.searcharoo.net/SearchKml/newyork.kml"}, { url: "http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml", options: {clickable: false } }]'
96
- options_hash = {
97
- :kml => {:data => expected_kml }
98
- }
99
- result = options_hash.to_gmaps4rails
100
- actual_kml = result.scan(/Gmaps\.map\.kml = (.*?);/m).first.first
101
-
102
- actual_kml.should eq expected_kml
103
- result.should include "Gmaps.map.create_kml();"
104
- end
105
-
106
- it "should format directions" do
107
- options_hash = {
108
- "direction" => {
109
- "data" => { "from" => "toulon, france", "to" => "paris, france"} ,
110
- "options" => {"waypoints" => ["toulouse, france", "brest, france"], "travelMode" => "DRIVING", "display_panel" => true, "panel_id" => "instructions"}
111
- }
112
- }
113
- result = options_hash.to_gmaps4rails
114
- result.should include "Gmaps.map.direction_conf.origin = 'toulon, france';\nGmaps.map.direction_conf.destination = 'paris, france';"
115
- result.should include "Gmaps.map.direction_conf.display_panel = true;"
116
- result.should include "Gmaps.map.direction_conf.panel_id = \"instructions\";"
117
- result.should include "Gmaps.map.direction_conf.travelMode = \"DRIVING\";"
118
- result.should include "Gmaps.map.create_direction();"
119
-
120
- actual_directions = result.scan(/Gmaps\.map\.direction_conf\.waypoints = (.*?);/m).first.first
121
- actual_directions.should be_same_json_as "[{\"stopover\":true,\"location\":\"toulouse, france\"},{\"stopover\":true,\"location\":\"brest, france\"}]"
122
- end
123
-
124
- it "should not call map builder if not last_map" do
125
- hash = {:last_map => false}
126
- hash.to_gmaps4rails.should_not include "window.onload"
127
- end
128
-
129
- it "should call map builder if last_map" do
130
- trigger_script = "Gmaps.oldOnload = window.onload;\n window.onload = function() { Gmaps.triggerOldOnload(); Gmaps.loadMaps(); };"
131
- hash = {:last_map => true}
132
- hash.to_gmaps4rails.should include trigger_script
133
- hash = {}
134
- hash.to_gmaps4rails.should include trigger_script
135
- end
136
-
137
- end
138
-
139
- 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