gmaps4rails 0.11.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/README.rdoc +6 -2
  2. data/app/views/gmaps4rails/_gmaps4rails.html.erb +18 -20
  3. data/lib/gmaps4rails/base.rb +95 -0
  4. data/lib/gmaps4rails/extensions/hash.rb +3 -67
  5. data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +13 -2
  6. data/public/javascripts/gmaps4rails/all_apis.js +5 -0
  7. data/public/javascripts/gmaps4rails/gmaps4rails.base.js +147 -112
  8. data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +182 -171
  9. data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +269 -235
  10. data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +135 -125
  11. data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +227 -218
  12. data/public/stylesheets/gmaps4rails.css +2 -2
  13. metadata +9 -111
  14. data/test/dummy/app/controllers/application_controller.rb +0 -3
  15. data/test/dummy/app/controllers/users_controller.rb +0 -60
  16. data/test/dummy/app/helpers/application_helper.rb +0 -2
  17. data/test/dummy/app/helpers/users_helper.rb +0 -3
  18. data/test/dummy/app/models/user.rb +0 -38
  19. data/test/dummy/config/application.rb +0 -41
  20. data/test/dummy/config/boot.rb +0 -6
  21. data/test/dummy/config/environment.rb +0 -5
  22. data/test/dummy/config/environments/development.rb +0 -26
  23. data/test/dummy/config/environments/production.rb +0 -49
  24. data/test/dummy/config/environments/test.rb +0 -35
  25. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  26. data/test/dummy/config/initializers/inflections.rb +0 -10
  27. data/test/dummy/config/initializers/mime_types.rb +0 -5
  28. data/test/dummy/config/initializers/secret_token.rb +0 -7
  29. data/test/dummy/config/initializers/session_store.rb +0 -8
  30. data/test/dummy/config/routes.rb +0 -7
  31. data/test/dummy/db/migrate/20110306182914_create_users.rb +0 -21
  32. data/test/dummy/db/migrate/20110430081624_add_addresses_to_users.rb +0 -11
  33. data/test/dummy/db/migrate/20110430083824_remove_address_from_users.rb +0 -9
  34. data/test/dummy/db/schema.rb +0 -35
  35. data/test/dummy/db/seeds.rb +0 -7
  36. data/test/dummy/spec/base/base_spec.rb +0 -127
  37. data/test/dummy/spec/helpers/gmaps4rails_helper_spec.rb +0 -13
  38. data/test/dummy/spec/javascripts/support/jasmine_config.rb +0 -23
  39. data/test/dummy/spec/javascripts/support/jasmine_runner.rb +0 -20
  40. data/test/dummy/spec/models/user_spec.rb +0 -284
  41. data/test/dummy/spec/requests/users_spec.rb +0 -22
  42. data/test/dummy/spec/spec_helper.rb +0 -41
  43. data/test/dummy/spec/support/factories.rb +0 -20
  44. data/test/dummy/spec/support/matchers.rb +0 -7
  45. data/test/dummy31/app/controllers/application_controller.rb +0 -3
  46. data/test/dummy31/app/controllers/users_controller.rb +0 -83
  47. data/test/dummy31/app/helpers/application_helper.rb +0 -2
  48. data/test/dummy31/app/helpers/users_helper.rb +0 -2
  49. data/test/dummy31/app/models/user.rb +0 -7
  50. data/test/dummy31/config/application.rb +0 -43
  51. data/test/dummy31/config/boot.rb +0 -6
  52. data/test/dummy31/config/environment.rb +0 -5
  53. data/test/dummy31/config/environments/development.rb +0 -27
  54. data/test/dummy31/config/environments/production.rb +0 -51
  55. data/test/dummy31/config/environments/test.rb +0 -39
  56. data/test/dummy31/config/initializers/backtrace_silencers.rb +0 -7
  57. data/test/dummy31/config/initializers/inflections.rb +0 -10
  58. data/test/dummy31/config/initializers/mime_types.rb +0 -5
  59. data/test/dummy31/config/initializers/secret_token.rb +0 -7
  60. data/test/dummy31/config/initializers/session_store.rb +0 -8
  61. data/test/dummy31/config/initializers/wrap_parameters.rb +0 -12
  62. data/test/dummy31/config/routes.rb +0 -61
  63. data/test/dummy31/db/migrate/20110809134019_create_users.rb +0 -13
  64. data/test/dummy31/db/schema.rb +0 -25
  65. data/test/dummy31/db/seeds.rb +0 -7
@@ -1,127 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Geocode" do
4
-
5
- it "should geocode properly an address" do
6
- Gmaps4rails.geocode("alaska").should be_an(Array)
7
- end
8
-
9
- it "should raise an error when address invalid" do
10
- lambda { Gmaps4rails.geocode("home")}.should raise_error Gmaps4rails::GeocodeStatus
11
- end
12
-
13
- it "should raise an error when net connection failed" #TODO: Damn, I don't know how to test that!
14
-
15
- end
16
-
17
- describe "JS creation from hash" do
18
-
19
- it "should format entries properly" do
20
- options_hash = {
21
- "map_options" => { "type" => "SATELLITE", "center_longitude" => 180, "zoom" => 3},
22
- "markers" => { "data" => '[{ "description": "", "title": "", "longitude": "5.9311119", "latitude": "43.1251606", "picture": "", "width": "", "height": "" } ,{ "description": "", "title": "", "longitude": "2.3509871", "latitude": "48.8566667", "picture": "", "width": "", "height": "" } ]' },
23
- "polylines" => { "data" => '[[
24
- {"longitude": -122.214897, "latitude": 37.772323},
25
- {"longitude": -157.821856, "latitude": 21.291982},
26
- {"longitude": 178.431, "latitude": -18.142599},
27
- {"longitude": 153.027892, "latitude": -27.46758}
28
- ],
29
- [
30
- {"longitude": -120.214897, "latitude": 30.772323, "strokeColor": "#000", "strokeWeight" : 2 },
31
- {"longitude": -10.821856, "latitude": 50.291982}
32
- ]]' },
33
- "polygons" => { "data" => '[[
34
- {"longitude": -80.190262, "latitude": 25.774252},
35
- {"longitude": -66.118292, "latitude": 18.466465},
36
- {"longitude": -64.75737, "latitude": 32.321384}
37
- ]]' },
38
- "circles" => { "data" => '[
39
- {"longitude": -122.214897, "latitude": 37.772323, "radius": 1000000},
40
- {"longitude": 122.214897, "latitude": 37.772323, "radius": 1000000, "strokeColor": "#FF0000"}
41
- ]',
42
- },
43
- "direction" => {
44
- "data" => { "from" => "toulon, france", "to" => "paris, france"} ,
45
- "options" => {"waypoints" => ["toulouse, france", "brest, france"], "travelMode" => "DRIVING", "display_panel" => true, "panel_id" => "instructions"}
46
- }
47
- }
48
- options_hash.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.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();\nGmaps4Rails.callback();"
49
- end
50
-
51
- it "should add map settings when 'true' passed" do
52
- options_hash = {
53
- "map_options" => { "type" => "SATELLITE", "center_longitude" => 180, "zoom" => 3},
54
- "markers" => { "data" => '[{ "description": "", "title": "", "longitude": "5.9311119", "latitude": "43.1251606", "picture": "", "width": "", "height": "" } ,{ "description": "", "title": "", "longitude": "2.3509871", "latitude": "48.8566667", "picture": "", "width": "", "height": "" } ]' },
55
- "polylines" => { "data" => '[[
56
- {"longitude": -122.214897, "latitude": 37.772323},
57
- {"longitude": -157.821856, "latitude": 21.291982},
58
- {"longitude": 178.431, "latitude": -18.142599},
59
- {"longitude": 153.027892, "latitude": -27.46758}
60
- ],
61
- [
62
- {"longitude": -120.214897, "latitude": 30.772323, "strokeColor": "#000", "strokeWeight" : 2 },
63
- {"longitude": -10.821856, "latitude": 50.291982}
64
- ]]' },
65
- "polygons" => { "data" => '[[
66
- {"longitude": -80.190262, "latitude": 25.774252},
67
- {"longitude": -66.118292, "latitude": 18.466465},
68
- {"longitude": -64.75737, "latitude": 32.321384}
69
- ]]' },
70
- "circles" => { "data" => '[
71
- {"longitude": -122.214897, "latitude": 37.772323, "radius": 1000000},
72
- {"longitude": 122.214897, "latitude": 37.772323, "radius": 1000000, "strokeColor": "#FF0000"}
73
- ]',
74
- },
75
- "direction" => {
76
- "data" => { "from" => "toulon, france", "to" => "paris, france"} ,
77
- "options" => {"waypoints" => ["toulouse, france", "brest, france"], "travelMode" => "DRIVING", "display_panel" => true, "panel_id" => "instructions"}
78
- }
79
- }
80
- options_hash.to_gmaps4rails(true).should == "Gmaps4Rails.map_options.center_longitude = 180;\nGmaps4Rails.map_options.type = 'SATELLITE';\nGmaps4Rails.map_options.zoom = 3;\nGmaps4Rails.initialize();\nGmaps4Rails.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.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();\nGmaps4Rails.callback();"
81
- end
82
- end
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(true).should include "Gmaps4Rails.initialize();"
119
- end
120
-
121
- end
122
-
123
- describe "Destination" do
124
- it "should render info from only start_end args"
125
- it "should accept all options properly"
126
- it "should format output in accordance with 'output' variable"
127
- end
@@ -1,13 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Gmaps4railsHelper do
4
-
5
- it "should create a string containing all desired libraries" do
6
- helper.g_libraries(["places", "foo", "bar"]).should eq(",places,foo,bar")
7
- end
8
-
9
- it "should render empty string if no library provided" do
10
- helper.g_libraries(nil).should eq("")
11
- end
12
-
13
- end
@@ -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
@@ -1,284 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- DEFAULT_CONFIG_HASH = {
4
- :lat_column => "latitude",
5
- :lng_column => "longitude",
6
- :check_process => true,
7
- :checker => "gmaps",
8
- :msg => "Address invalid",
9
- :validation => true,
10
- :address => "gmaps4rails_address",
11
- :language => "en"
12
- }
13
-
14
- PARIS = { :latitude => 48.856614, :longitude => 2.3522219 }
15
- TOULON = { :latitude => 43.124228, :longitude => 5.928 }
16
-
17
- #set model configuration
18
- def set_gmaps4rails_options!(change_conf = {})
19
- User.class_eval do
20
- define_method "gmaps4rails_options" do
21
- DEFAULT_CONFIG_HASH.merge(change_conf)
22
- end
23
- end
24
- end
25
-
26
- set_gmaps4rails_options!
27
-
28
- describe Gmaps4rails::ActsAsGmappable do
29
-
30
- let(:user) { Factory(:user) }
31
- let(:invalid_user) { Factory.build(:invalid_user) }
32
-
33
- context "standard configuration, valid user" do
34
-
35
- it "should have a geocoded position" do
36
- user.should have_same_position_as TOULON
37
- end
38
-
39
- it "should set boolean to true once user is created" do
40
- user.gmaps.should be_true
41
- end
42
-
43
- it "should render a valid json from an array of objects" do
44
- user #needed trigger the object from the let statement
45
- Factory(:user_paris)
46
- User.all.to_gmaps4rails.should == "[{\"lng\": \"" + TOULON[:longitude].to_s + "\", \"lat\": \"" + TOULON[:latitude].to_s + "\"},\n{\"lng\": \"" + PARIS[:longitude].to_s + "\", \"lat\": \"" + PARIS[:latitude].to_s + "\"}]"
47
- end
48
-
49
- it "should accept additional block for an array of objects" do
50
- user #needed trigger the object from the let statement
51
- Factory(:user_paris)
52
- User.all.to_gmaps4rails do |u|
53
- "\"model\": \"" + u.class.to_s + "\""
54
- end.should == "[{\"lng\": \"" + TOULON[:longitude].to_s + "\", \"lat\": \"" + TOULON[:latitude].to_s + "\", \"model\": \"User\"},\n{\"lng\": \"" + PARIS[:longitude].to_s + "\", \"lat\": \"" + PARIS[:latitude].to_s + "\", \"model\": \"User\"}]"
55
- end
56
-
57
- it "should accept additional block for a single object" do
58
- user.to_gmaps4rails do |u|
59
- "\"model\": \"" + u.class.to_s + "\""
60
- end.should == "[{\"lng\": \"" + TOULON[:longitude].to_s + "\", \"lat\": \"" + TOULON[:latitude].to_s + "\", \"model\": \"User\"}]"
61
- end
62
-
63
- it "should render a valid json from a single object" do
64
- user.to_gmaps4rails.should == "[{\"lng\": \"" + TOULON[:longitude].to_s + "\", \"lat\": \"" + TOULON[:latitude].to_s + "\"}]"
65
- end
66
-
67
- it "should not geocode again after address changes if checker is true" do
68
- user.update_attributes({ :sec_address => "PARIS, France" })
69
- user.should have_same_position_as TOULON
70
- end
71
-
72
- it "should geocode after address changes if checker is false" do
73
- user.update_attributes({ :sec_address => "PARIS, France",
74
- :gmaps => false})
75
- user.should have_same_position_as PARIS
76
- end
77
- end
78
-
79
-
80
- context "standard configuration, invalid address" do
81
-
82
- it "should raise an error if validation option is turned on and address incorrect" do
83
- invalid_user.should_not be_valid, "Address invalid"
84
- end
85
-
86
- it "should not set boolean to true when address update fails" do
87
- invalid_user.gmaps.should_not be_true
88
- end
89
- end
90
-
91
-
92
- context "model customization" do
93
-
94
- it "should render a valid json even if there is no instance in the db" do
95
- User.all.to_gmaps4rails.should == "[]"
96
- end
97
-
98
- context "acts_as_gmappable options" do
99
-
100
- after(:all) do
101
- #reset all configuration to default
102
- set_gmaps4rails_options!
103
- end
104
-
105
- it "should use indifferently a db column for address if passed in config" do
106
- set_gmaps4rails_options!({:address => "sec_address"})
107
- user.should have_same_position_as TOULON
108
- end
109
-
110
- it "should save the normalized address if requested" do
111
- set_gmaps4rails_options!({ :normalized_address => "norm_address" })
112
- user.norm_address.should == "Toulon, France"
113
- end
114
-
115
- it "should override user's address with normalized address if requested" do
116
- set_gmaps4rails_options!({ :normalized_address => "sec_address" })
117
- user = Factory(:user, :sec_address => "ToUlOn, FrAnCe")
118
- user.sec_address.should == "Toulon, France"
119
- end
120
-
121
- it "should display the proper error message when address is invalid" do
122
- set_gmaps4rails_options!({ :msg => "Custom Address invalid"})
123
- invalid_user.should_not be_valid
124
- invalid_user.errors[:gmaps4rails_address].should include("Custom Address invalid")
125
- end
126
-
127
- it "should not raise an error if validation option is turned off" do
128
- set_gmaps4rails_options!({ :validation => false })
129
- invalid_user.should be_valid
130
- end
131
-
132
- it "should save longitude and latitude to the customized columns" do
133
- set_gmaps4rails_options!({
134
- :lat_column => "lat_test",
135
- :lng_column => "long_test"
136
- })
137
- user.latitude.should be_nil
138
- user.should have_same_position_as TOULON
139
- end
140
-
141
- it "should not save the boolean if check_process is false" do
142
- set_gmaps4rails_options!({ :check_process => false })
143
- user.gmaps.should be_nil
144
- end
145
-
146
- it "should geocode after each save if 'check_process' is false" do
147
- set_gmaps4rails_options!({ :check_process => false })
148
- user = Factory(:user, :sec_address => "PARIS, France")
149
- user.should have_same_position_as PARIS
150
- end
151
-
152
- it "should save to the proper boolean checker set in checker" do
153
- set_gmaps4rails_options!({ :checker => "bool_test" })
154
- user.gmaps.should be_nil
155
- user.bool_test.should be_true
156
- end
157
-
158
- it "should call a callback in the model if asked to" do
159
- User.class_eval do
160
- def gmaps4rails_options
161
- DEFAULT_CONFIG_HASH.merge({ :callback => "save_callback" })
162
- end
163
-
164
- def save_callback(data)
165
- self.called_back = true
166
- end
167
-
168
- attr_accessor :called_back
169
- end
170
- user.called_back.should be_true
171
- end
172
-
173
- it "should return results in the specified language" do
174
- set_gmaps4rails_options!({
175
- :language => "de",
176
- :normalized_address => "norm_address"
177
- })
178
- user.norm_address.should == "Toulon, Frankreich"
179
- end
180
-
181
- end
182
-
183
- context "instance methods" do
184
- let(:user_with_pic) { Factory(:user_with_pic) }
185
-
186
- it "should take into account the description provided in the model" do
187
- user_with_pic.instance_eval do
188
- def gmaps4rails_infowindow
189
- "My Beautiful Picture: #{picture}"
190
- end
191
- end
192
- user_with_pic.to_gmaps4rails.should include "\"description\": \"My Beautiful Picture: http://www.blankdots.com/img/github-32x32.png\""
193
- end
194
-
195
- it "should take into account the picture provided in the model" do
196
- user.instance_eval do
197
- def gmaps4rails_marker_picture
198
- {
199
- "picture" => "http://www.blankdots.com/img/github-32x32.png",
200
- "width" => "32",
201
- "height" => "32"
202
- }
203
- end
204
- end
205
- result = user.to_gmaps4rails
206
- result.should include "\"picture\": \"http://www.blankdots.com/img/github-32x32.png\""
207
- result.should include "\"width\": \"32\""
208
- result.should include "\"height\": \"32\""
209
- end
210
-
211
- it "should take into account the picture and shadow provided in the model" do
212
- user.instance_eval do
213
- def gmaps4rails_marker_picture
214
- {
215
- "picture" => "http://www.blankdots.com/img/github-32x32.png",
216
- "width" => "32",
217
- "height" => "32",
218
- "marker_anchor" => [10, 20],
219
- "shadow_picture" => "http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png" ,
220
- "shadow_width" => "40",
221
- "shadow_height" => "40",
222
- "shadow_anchor" => [5, 10]
223
- }
224
- end
225
- end
226
- result = user.to_gmaps4rails
227
- result.should include "\"shadow_width\": \"40\""
228
- result.should include "\"shadow_height\": \"40\""
229
- result.should include "\"shadow_picture\": \"http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png\""
230
- result.should include "\"shadow_anchor\": [5, 10]"
231
- result.should include "\"marker_anchor\": [10, 20]"
232
- end
233
-
234
- it "should take into account the title provided in the model" do
235
- user.instance_eval do
236
- def gmaps4rails_title
237
- "Sweet Title"
238
- end
239
- end
240
- user.to_gmaps4rails.should == "[{\"title\": \"Sweet Title\", \"lng\": \"" + TOULON[:longitude].to_s + "\", \"lat\": \"" + TOULON[:latitude].to_s + "\"}]"
241
- end
242
-
243
- it "should take into account the sidebar content provided in the model" do
244
- user.instance_eval do
245
- def gmaps4rails_sidebar
246
- "sidebar content"
247
- end
248
- end
249
- user.to_gmaps4rails.should include "\"sidebar\": \"sidebar content\""
250
- end
251
-
252
- it "should take into account all additional data provided in the model" do
253
- user.instance_eval do
254
- def gmaps4rails_infowindow
255
- "My Beautiful Picture: #{picture}"
256
- end
257
-
258
- def gmaps4rails_marker_picture
259
- {
260
- "picture" => "http://www.blankdots.com/img/github-32x32.png",
261
- "width" => "32",
262
- "height" => "32"
263
- }
264
- end
265
-
266
- def gmaps4rails_title
267
- "Sweet Title"
268
- end
269
-
270
- def gmaps4rails_sidebar
271
- "sidebar content"
272
- end
273
- end
274
- result = user.to_gmaps4rails
275
- result.should include "\"description\": \"My Beautiful Picture: \""
276
- result.should include "\"title\": \"Sweet Title\""
277
- result.should include "\"sidebar\": \"sidebar content\""
278
- result.should include "\"picture\": \"http://www.blankdots.com/img/github-32x32.png\""
279
- end
280
-
281
- end
282
- end
283
-
284
- end
@@ -1,22 +0,0 @@
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
@@ -1,41 +0,0 @@
1
- # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- ENV["RAILS_ENV"] ||= 'test'
3
- require File.expand_path("../../config/environment", __FILE__)
4
- require 'rspec/rails'
5
- require 'capybara/rspec'
6
- require 'shoulda-matchers'
7
- # Requires supporting ruby files with custom matchers and macros, etc,
8
- # in spec/support/ and its subdirectories.
9
- Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
10
- Capybara.server_boot_timeout = 90
11
-
12
- RSpec.configure do |config|
13
- # == Mock Framework
14
- #
15
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
16
- #
17
- # config.mock_with :mocha
18
- # config.mock_with :flexmock
19
- # config.mock_with :rr
20
- config.mock_with :rspec
21
-
22
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
23
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
24
-
25
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
26
- # examples within a transaction, remove the following line or assign false
27
- # instead of 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
41
- end
@@ -1,20 +0,0 @@
1
- Factory.define :user do |f|
2
- f.name "me"
3
- f.sec_address "Toulon, France"
4
- end
5
-
6
- Factory.define :user_paris, :parent => :user do |f|
7
- f.name "me"
8
- f.sec_address "Paris, France"
9
- end
10
-
11
- Factory.define :user_with_pic, :parent => :user do |f|
12
- f.name "me"
13
- f.sec_address "Toulon, France"
14
- f.picture "http://www.blankdots.com/img/github-32x32.png"
15
- end
16
-
17
- Factory.define :invalid_user, :parent => :user do |f|
18
- f.name "me"
19
- f.sec_address "home"
20
- end
@@ -1,7 +0,0 @@
1
- require 'rspec/expectations'
2
-
3
- RSpec::Matchers.define :have_same_position_as do |position_hash|
4
- match do |object|
5
- object.send(object.gmaps4rails_options[:lat_column]) == position_hash[:latitude] && object.send(object.gmaps4rails_options[:lng_column]) == position_hash[:longitude]
6
- end
7
- end
@@ -1,3 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
- end
@@ -1,83 +0,0 @@
1
- class UsersController < ApplicationController
2
- # GET /users
3
- # GET /users.json
4
- def index
5
- @users = User.all
6
- @json = User.all.to_gmaps4rails
7
- respond_to do |format|
8
- format.html # index.html.erb
9
- format.json { render :json => @users }
10
- end
11
- end
12
-
13
- # GET /users/1
14
- # GET /users/1.json
15
- def show
16
- @user = User.find(params[:id])
17
-
18
- respond_to do |format|
19
- format.html # show.html.erb
20
- format.json { render :json => @user }
21
- end
22
- end
23
-
24
- # GET /users/new
25
- # GET /users/new.json
26
- def new
27
- @user = User.new
28
-
29
- respond_to do |format|
30
- format.html # new.html.erb
31
- format.json { render :json => @user }
32
- end
33
- end
34
-
35
- # GET /users/1/edit
36
- def edit
37
- @user = User.find(params[:id])
38
- end
39
-
40
- # POST /users
41
- # POST /users.json
42
- def create
43
- @user = User.new(params[:user])
44
-
45
- respond_to do |format|
46
- if @user.save
47
- format.html { redirect_to @user, :notice => 'User was successfully created.' }
48
- format.json { render :json => @user, :status => :created, :location => @user }
49
- else
50
- format.html { render :action => "new" }
51
- format.json { render :json => @user.errors, :status => :unprocessable_entity }
52
- end
53
- end
54
- end
55
-
56
- # PUT /users/1
57
- # PUT /users/1.json
58
- def update
59
- @user = User.find(params[:id])
60
-
61
- respond_to do |format|
62
- if @user.update_attributes(params[:user])
63
- format.html { redirect_to @user, :notice => 'User was successfully updated.' }
64
- format.json { head :ok }
65
- else
66
- format.html { render :action => "edit" }
67
- format.json { render :json => @user.errors, :status => :unprocessable_entity }
68
- end
69
- end
70
- end
71
-
72
- # DELETE /users/1
73
- # DELETE /users/1.json
74
- def destroy
75
- @user = User.find(params[:id])
76
- @user.destroy
77
-
78
- respond_to do |format|
79
- format.html { redirect_to users_url }
80
- format.json { head :ok }
81
- end
82
- end
83
- end
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,2 +0,0 @@
1
- module UsersHelper
2
- end