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,27 @@
1
+ beforeEach(function() {
2
+ var gmap = new Gmaps4RailsGoogle();
3
+ });
4
+
5
+ describe("Mocks Fake", function() {
6
+ it("should create fake Point", function() {
7
+ expect(gmap.createPoint(1,2)).toEqual([1,2]);
8
+ });
9
+ it("should create fake LatLng", function() {
10
+ expect(gmap.createLatLng(1,2)).toEqual([1,2]);
11
+ });
12
+ it("should create fake LatLngBounds", function() {
13
+ expect(gmap.createLatLngBounds()).toEqual([]);
14
+ });
15
+ it("should create fake Map", function() {
16
+ expect(gmap.createMap()).toEqual({ "who": "I'm map"});
17
+ });
18
+ it("should create fake MarkerImage", function() {
19
+ expect(gmap.createMarkerImage("pic", "size", "url", "anchor", "scale")).toEqual({"who": "Point", "picture": "pic", "size": "size", "url": "url", "anchor": "anchor", "scale": "scale"});
20
+ });
21
+ it("should create fake Size", function() {
22
+ expect(gmap.createSize(1, 3)).toEqual([1,3]);
23
+ });
24
+ it("should create fake Clusterer", function() {
25
+ expect(gmap.createClusterer()).toEqual({ "who": "I'm Clusterer" });
26
+ });
27
+ });
@@ -0,0 +1,76 @@
1
+ # src_files
2
+ #
3
+ # Return an array of filepaths relative to src_dir to include before jasmine specs.
4
+ # Default: []
5
+ #
6
+ # EXAMPLE:
7
+ #
8
+ # src_files:
9
+ # - lib/source1.js
10
+ # - lib/source2.js
11
+ # - dist/**/*.js
12
+ #
13
+ src_files:
14
+ - public/javascripts/**/*.js
15
+
16
+ # stylesheets
17
+ #
18
+ # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
19
+ # Default: []
20
+ #
21
+ # EXAMPLE:
22
+ #
23
+ # stylesheets:
24
+ # - css/style.css
25
+ # - stylesheets/*.css
26
+ #
27
+ stylesheets:
28
+ - stylesheets/**/*.css
29
+
30
+ # helpers
31
+ #
32
+ # Return an array of filepaths relative to spec_dir to include before jasmine specs.
33
+ # Default: ["helpers/**/*.js"]
34
+ #
35
+ # EXAMPLE:
36
+ #
37
+ # helpers:
38
+ # - helpers/**/*.js
39
+ #
40
+ helpers:
41
+ - helpers/**/*.js
42
+
43
+ # spec_files
44
+ #
45
+ # Return an array of filepaths relative to spec_dir to include.
46
+ # Default: ["**/*[sS]pec.js"]
47
+ #
48
+ # EXAMPLE:
49
+ #
50
+ # spec_files:
51
+ # - **/*[sS]pec.js
52
+ #
53
+ spec_files:
54
+ - '**/*[sS]pec.js'
55
+
56
+ # src_dir
57
+ #
58
+ # Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
59
+ # Default: project root
60
+ #
61
+ # EXAMPLE:
62
+ #
63
+ # src_dir: public
64
+ #
65
+ src_dir:
66
+
67
+ # spec_dir
68
+ #
69
+ # Spec directory path. Your spec_files must be returned relative to this path.
70
+ # Default: spec/javascripts
71
+ #
72
+ # EXAMPLE:
73
+ #
74
+ # spec_dir: spec/javascripts
75
+ #
76
+ spec_dir: spec/javascripts
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,447 @@
1
+ require 'spec_helper'
2
+
3
+ include Geocoding
4
+
5
+ DEFAULT_CONFIG_HASH = {
6
+ :lat_column => "latitude",
7
+ :lng_column => "longitude",
8
+ :check_process => true,
9
+ :checker => "gmaps",
10
+ :msg => "Address invalid",
11
+ :validation => true,
12
+ :address => "gmaps4rails_address",
13
+ :language => "en",
14
+ :protocol => "http",
15
+ :process_geocoding => true
16
+ }
17
+
18
+ PARIS = { :latitude => 48.856614, :longitude => 2.3522219 }
19
+ TOULON = { :latitude => 43.124228, :longitude => 5.928 }
20
+
21
+ #set model configuration
22
+ def set_gmaps4rails_options!(change_conf = {})
23
+ User.class_eval do
24
+ define_method "gmaps4rails_options" do
25
+ DEFAULT_CONFIG_HASH.merge(change_conf)
26
+ end
27
+ end
28
+ end
29
+
30
+ set_gmaps4rails_options!
31
+
32
+ describe Gmaps4rails::ActsAsGmappable do
33
+
34
+ let(:user) { Factory(:user) }
35
+ let(:invalid_user) { Factory.build(:invalid_user) }
36
+
37
+ before(:each) do
38
+ Geocoding.stub_gecoding
39
+ end
40
+
41
+ context "standard configuration, valid user" do
42
+
43
+ it "should call google api with http by default" do
44
+ address = "toulon, france"
45
+ Gmaps4rails.should_receive(:geocode).with(address, "en", false, "http").and_return [TOULON]
46
+ User.create(:address => address)
47
+ end
48
+
49
+ it "should call google api with https if passed in settings" do
50
+ set_gmaps4rails_options!({ :protocol => "https" })
51
+ address = "toulon, france"
52
+ Gmaps4rails.should_receive(:geocode).with(address, "en", false, "https").and_return [TOULON]
53
+ User.create(:address => address)
54
+ set_gmaps4rails_options!({ :protocol => "http" })
55
+ end
56
+
57
+ it "should have a geocoded position" do
58
+ user.should have_same_position_as TOULON
59
+ end
60
+
61
+ it "should set boolean to true once user is created" do
62
+ user.gmaps.should be_true
63
+ end
64
+
65
+ it "should render a valid json from an array of objects" do
66
+ user #needed trigger the object from the let statement
67
+ Factory(:user_paris)
68
+ JSON.parse(User.all.to_gmaps4rails).should == [{ "lng" => TOULON[:longitude], "lat" => TOULON[:latitude] },{"lng" => PARIS[:longitude], "lat" => PARIS[:latitude] } ]
69
+ end
70
+
71
+ context "to_gmaps4rails block" do
72
+ it "should extend json string for Arrays" do
73
+ user #needed trigger the object from the let statement
74
+ Factory(:user_paris)
75
+ JSON.parse(User.all.to_gmaps4rails do |u, marker|
76
+ '"model":"' + u.class.to_s + '"'
77
+ end).should == [{"model" => "User", "lng" => TOULON[:longitude], "lat" => TOULON[:latitude]},{"model" => "User", "lng" => PARIS[:longitude], "lat" => PARIS[:latitude] }]
78
+ end
79
+
80
+ it "should extend json string for Arrays and custom hash" do
81
+ user #needed trigger the object from the let statement
82
+ Factory(:user_paris)
83
+ JSON.parse(User.all.to_gmaps4rails do |u, marker|
84
+ marker.json({ :model => u.class.to_s })
85
+ end).should == [{"model" => "User", "lng" => TOULON[:longitude], "lat" => TOULON[:latitude]},{"model" => "User", "lng" => PARIS[:longitude], "lat" => PARIS[:latitude] }]
86
+ end
87
+
88
+ it "should extend json string for a single object" do
89
+ JSON.parse(user.to_gmaps4rails do |u, marker|
90
+ "\"model\":\"" + u.class.to_s + "\""
91
+ end).should == [{ "model" => "User", "lng" =>TOULON[:longitude], "lat" => TOULON[:latitude] }]
92
+ end
93
+
94
+ it "json method should produce same result as raw string" do
95
+ from_method = JSON.parse(user.to_gmaps4rails do |u, marker|
96
+ marker.json({ :model => u.class.to_s })
97
+ end)
98
+
99
+ from_string = JSON.parse(user.to_gmaps4rails do |u, marker|
100
+ "\"model\":\"" + u.class.to_s + "\""
101
+ end)
102
+
103
+ from_string.should eq from_method
104
+ end
105
+
106
+ it "infowindow content should be included in json" do
107
+ user.to_gmaps4rails do |u, marker|
108
+ marker.infowindow "in infowindow"
109
+ end.should include "\"description\":\"in infowindow\""
110
+ end
111
+
112
+ it "marker_picture should be included in json" do
113
+ user.to_gmaps4rails do |u, marker|
114
+ marker.picture({
115
+ :picture => "http://www.blankdots.com/img/github-32x32.png",
116
+ :width => "32",
117
+ :height => "32"
118
+ })
119
+ end.should include "\"picture\":\"http://www.blankdots.com/img/github-32x32.png\""
120
+ end
121
+
122
+ it "title content should be included in json" do
123
+ user.to_gmaps4rails do |u, marker|
124
+ marker.title "i'm the title"
125
+ end.should include "\"title\":\"i'm the title\""
126
+ end
127
+
128
+ it "sidebar content should be included in json" do
129
+ user.to_gmaps4rails do |u, marker|
130
+ marker.sidebar "i'm the sidebar"
131
+ end.should include "\"sidebar\":\"i'm the sidebar\""
132
+ end
133
+ end
134
+
135
+ context "process_geocoding" do
136
+ context "Proc" do
137
+ it "should prevent geocoding when returns false" do
138
+ user.instance_eval do
139
+ def gmaps4rails_options
140
+ DEFAULT_CONFIG_HASH.merge({ :process_geocoding => lambda {|user| false } })
141
+ end
142
+ end
143
+ Gmaps4rails.should_not_receive(:geocode)
144
+ user.update_attributes(:address => "Strasbourg, france")
145
+ end
146
+
147
+ context "geocoding required" do
148
+ it "should trigger the geocoding" do
149
+ user.instance_eval do
150
+ def gmaps4rails_options
151
+ DEFAULT_CONFIG_HASH.merge({ :process_geocoding => lambda {|user| true } })
152
+ end
153
+ end
154
+ user.should_receive :gmaps4rails_save_data
155
+ user.update_attributes(:address => "Strasbourg, france")
156
+ end
157
+
158
+ it "should update coordinates but not update checker" do
159
+ #first default behavior
160
+ user.update_attributes(:gmaps => false, :address => "Strasbourg, france")
161
+ user.gmaps.should eq true
162
+ #then tested behavior
163
+ user.instance_eval do
164
+ def gmaps4rails_options
165
+ DEFAULT_CONFIG_HASH.merge({ :process_geocoding => lambda {|user| true } })
166
+ end
167
+ end
168
+ user.update_attributes(:gmaps => false, :address => "Strasbourg, france")
169
+ user.gmaps.should eq false
170
+ end
171
+ end
172
+ end
173
+ end
174
+ it "should render a valid json from a single object" do
175
+ JSON.parse(user.to_gmaps4rails).should == [{"lng" => TOULON[:longitude], "lat" => TOULON[:latitude] }]
176
+ end
177
+
178
+ it "should not geocode again after address changes if checker is true" do
179
+ user.update_attributes({ :address => "Paris, France" })
180
+ user.should have_same_position_as TOULON
181
+ end
182
+
183
+ it "should geocode after address changes if checker is false" do
184
+ user.update_attributes({ :address => "Paris, France",
185
+ :gmaps => false})
186
+ user.should have_same_position_as PARIS
187
+ end
188
+ end
189
+
190
+ context "standard configuration, invalid address" do
191
+
192
+ it "should raise an error if validation option is turned on and address incorrect" do
193
+ invalid_user.should_not be_valid, "Address invalid"
194
+ end
195
+
196
+ it "should not set boolean to true when address update fails" do
197
+ invalid_user.gmaps.should_not be_true
198
+ end
199
+ end
200
+
201
+ context "model customization" do
202
+
203
+ it "should render a valid json even if there is no instance in the db" do
204
+ User.all.to_gmaps4rails.should == "[]"
205
+ end
206
+
207
+ context "acts_as_gmappable options" do
208
+
209
+ after(:all) do
210
+ #reset all configuration to default
211
+ set_gmaps4rails_options!
212
+ end
213
+
214
+ it "should use indifferently a db column for address if passed in config" do
215
+ set_gmaps4rails_options!({:address => "sec_address"})
216
+ user = Factory(:user, :sec_address => "Toulon, France")
217
+ user.should have_same_position_as TOULON
218
+ end
219
+
220
+ it "should save the normalized address if requested" do
221
+ set_gmaps4rails_options!({ :normalized_address => "norm_address" })
222
+ user.norm_address.should == "Toulon, France"
223
+ end
224
+
225
+ it "should override user's address with normalized address if requested" do
226
+ set_gmaps4rails_options!({ :normalized_address => "sec_address" })
227
+ user = Factory(:user, :sec_address => "ToUlOn, FrAnCe")
228
+ user.sec_address.should == "Toulon, France"
229
+ end
230
+
231
+ it "should display the proper error message when address is invalid" do
232
+ set_gmaps4rails_options!({ :msg => "Custom Address invalid"})
233
+ invalid_user.should_not be_valid
234
+ invalid_user.errors[:gmaps4rails_address].should include("Custom Address invalid")
235
+ end
236
+
237
+ it "should not raise an error if validation option is turned off" do
238
+ set_gmaps4rails_options!({ :validation => false })
239
+ invalid_user.should be_valid
240
+ end
241
+
242
+ it "should save longitude and latitude to the customized columns" do
243
+ set_gmaps4rails_options!({
244
+ :lat_column => "lat_test",
245
+ :lng_column => "long_test"
246
+ })
247
+ user.latitude.should be_nil
248
+ user.should have_same_position_as TOULON
249
+ end
250
+
251
+ it "should not save the boolean if check_process is false" do
252
+ set_gmaps4rails_options!({ :check_process => false })
253
+ user.gmaps.should be_nil
254
+ end
255
+
256
+ it "should geocode after each save if 'check_process' is false" do
257
+ set_gmaps4rails_options!({ :check_process => false })
258
+ user = Factory(:user, :address => "Paris, France")
259
+ user.should have_same_position_as PARIS
260
+ end
261
+
262
+ it "should save to the proper boolean checker set in checker" do
263
+ set_gmaps4rails_options!({ :checker => "bool_test" })
264
+ user.gmaps.should be_nil
265
+ user.bool_test.should be_true
266
+ end
267
+
268
+ it "should call a callback in the model if asked to" do
269
+ User.class_eval do
270
+ def gmaps4rails_options
271
+ DEFAULT_CONFIG_HASH.merge({ :callback => "save_callback" })
272
+ end
273
+
274
+ def save_callback(data)
275
+ self.called_back = true
276
+ end
277
+
278
+ attr_accessor :called_back
279
+ end
280
+ user.called_back.should be_true
281
+ end
282
+
283
+ end
284
+
285
+ context "instance methods" do
286
+ let(:user_with_pic) { Factory(:user_with_pic) }
287
+
288
+ it "should take into account the description provided in the model" do
289
+ user_with_pic.instance_eval do
290
+ def gmaps4rails_infowindow
291
+ "My Beautiful Picture: #{picture}"
292
+ end
293
+ end
294
+ user_with_pic.to_gmaps4rails.should include "\"description\":\"My Beautiful Picture: http://www.blankdots.com/img/github-32x32.png\""
295
+ end
296
+
297
+ it "should take into account the picture provided in the model" do
298
+ user.instance_eval do
299
+ def gmaps4rails_marker_picture
300
+ {
301
+ "picture" => "http://www.blankdots.com/img/github-32x32.png",
302
+ "width" => "32",
303
+ "height" => "32"
304
+ }
305
+ end
306
+ end
307
+ result = user.to_gmaps4rails
308
+ result.should include "\"picture\":\"http://www.blankdots.com/img/github-32x32.png\""
309
+ result.should include "\"width\":\"32\""
310
+ result.should include "\"height\":\"32\""
311
+ end
312
+
313
+ it "should take into account the picture and shadow provided in the model" do
314
+ user.instance_eval do
315
+ def gmaps4rails_marker_picture
316
+ {
317
+ "picture" => "http://www.blankdots.com/img/github-32x32.png",
318
+ "width" => "32",
319
+ "height" => "32",
320
+ "marker_anchor" => [10, 20],
321
+ "shadow_picture" => "http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png" ,
322
+ "shadow_width" => "40",
323
+ "shadow_height" => "40",
324
+ "shadow_anchor" => [5, 10]
325
+ }
326
+ end
327
+ end
328
+ result = user.to_gmaps4rails
329
+ result.should include "\"shadow_width\":\"40\""
330
+ result.should include "\"shadow_height\":\"40\""
331
+ result.should include "\"shadow_picture\":\"http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png\""
332
+ result.should include "\"shadow_anchor\":[5,10]"
333
+ result.should include "\"marker_anchor\":[10,20]"
334
+ end
335
+
336
+ it "should take into account the title provided in the model" do
337
+ user.instance_eval do
338
+ def gmaps4rails_title
339
+ "Sweet Title"
340
+ end
341
+ end
342
+ JSON.parse(user.to_gmaps4rails).should == [{"title" => "Sweet Title", "lng" => TOULON[:longitude], "lat" => TOULON[:latitude]}]
343
+ end
344
+
345
+ it "should take into account the sidebar content provided in the model" do
346
+ user.instance_eval do
347
+ def gmaps4rails_sidebar
348
+ "sidebar content"
349
+ end
350
+ end
351
+ user.to_gmaps4rails.should include "\"sidebar\":\"sidebar content\""
352
+ end
353
+
354
+ it "should take into account all additional data provided in the model" do
355
+ user.instance_eval do
356
+ def gmaps4rails_infowindow
357
+ "My Beautiful Picture: #{picture}"
358
+ end
359
+
360
+ def gmaps4rails_marker_picture
361
+ {
362
+ "picture" => "http://www.blankdots.com/img/github-32x32.png",
363
+ "width" => "32",
364
+ "height" => "32"
365
+ }
366
+ end
367
+
368
+ def gmaps4rails_title
369
+ "Sweet Title"
370
+ end
371
+
372
+ def gmaps4rails_sidebar
373
+ "sidebar content"
374
+ end
375
+ end
376
+ result = user.to_gmaps4rails
377
+ result.should include "\"description\":\"My Beautiful Picture: \""
378
+ result.should include "\"title\":\"Sweet Title\""
379
+ result.should include "\"sidebar\":\"sidebar content\""
380
+ result.should include "\"picture\":\"http://www.blankdots.com/img/github-32x32.png\""
381
+ end
382
+
383
+ end
384
+
385
+ it "block info should take precedence over model methods" do
386
+ user.instance_eval do
387
+ def gmaps4rails_infowindow
388
+ "defined in model"
389
+ end
390
+ end
391
+ user.to_gmaps4rails.should include "defined in model"
392
+ result = user.to_gmaps4rails do |u, marker|
393
+ marker.infowindow "defined in block"
394
+ end
395
+ result.should include "defined in block"
396
+ result.should_not include "defined in model"
397
+ end
398
+
399
+ end
400
+
401
+ describe "eval conditions" do
402
+ it "should trigger method if symbol passed" do
403
+ User.class_eval do
404
+ def gmaps4rails_options
405
+ DEFAULT_CONFIG_HASH.merge({ :validation => :published? })
406
+ end
407
+
408
+ def published?; true; end
409
+ end
410
+ user.should_receive :published?
411
+ Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation])
412
+ end
413
+
414
+ it "should evaluate lambda if provided" do
415
+ user.instance_eval do
416
+ def gmaps4rails_options
417
+ DEFAULT_CONFIG_HASH.merge({ :validation => lambda { |object| object.test_me(:foo, :bar) } })
418
+ end
419
+
420
+ def test_me(a,b)
421
+ "#{a}, #{b}"
422
+ end
423
+ end
424
+ user.should_receive(:test_me).with(:foo, :bar)
425
+ Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation])
426
+ end
427
+
428
+ it "should simply accept a true value" do
429
+ user.instance_eval do
430
+ def gmaps4rails_options
431
+ DEFAULT_CONFIG_HASH.merge({ :validation => true })
432
+ end
433
+ end
434
+ Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation]).should be_true
435
+ end
436
+
437
+ it "should simply accept a false value" do
438
+ user.instance_eval do
439
+ def gmaps4rails_options
440
+ DEFAULT_CONFIG_HASH.merge({ :validation => false })
441
+ end
442
+ end
443
+ Gmaps4rails.condition_eval(user, user.gmaps4rails_options[:validation]).should be_false
444
+ end
445
+ end
446
+
447
+ end