gmaps4rails 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -129,14 +129,15 @@ module Gmaps4rails
129
129
  validate :process_geocoding
130
130
  end
131
131
 
132
+ #instance method
132
133
  define_method "gmaps4rails_options" do
133
134
  {
134
- :lat_column => args[:lat] || "latitude",
135
- :lng_column => args[:lng] || "longitude",
136
- :check_process => args[:check_process] || true,
137
- :checker => args[:checker] || "gmaps",
138
- :msg => args[:msg] || "Address invalid",
139
- :validation => args[:validation] || true
135
+ :lat_column => args[:lat] || "latitude",
136
+ :lng_column => args[:lng] || "longitude",
137
+ :check_process => args[:check_process].nil? ? true : args[:check_process],
138
+ :checker => args[:checker] || "gmaps",
139
+ :msg => args[:msg] || "Address invalid",
140
+ :validation => args[:validation].nil? ? true : args[:validation]
140
141
  #TODO: address as a proc?
141
142
  }
142
143
  end
@@ -197,3 +198,6 @@ module Gmaps4rails
197
198
  end
198
199
 
199
200
  ::ActiveRecord::Base.send :include, Gmaps4rails::ActsAsGmappable::Base
201
+ # Mongoid::Document::ClassMethods.class_eval do
202
+ # include Gmaps4rails::ActsAsGmappable::Base
203
+ # end
@@ -1,6 +1,6 @@
1
1
  class User < ActiveRecord::Base
2
2
  acts_as_gmappable
3
-
3
+
4
4
  def gmaps4rails_address
5
5
  address
6
6
  end
@@ -45,7 +45,7 @@ describe "JS creation from hash" do
45
45
  "options" => {"waypoints" => ["toulouse, france", "brest, france"], "travelMode" => "DRIVING", "display_panel" => true, "panel_id" => "instructions"}
46
46
  }
47
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();"
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();"
49
49
  end
50
50
 
51
51
  it "should add map settings when 'true' passed" do
@@ -77,7 +77,7 @@ describe "JS creation from hash" do
77
77
  "options" => {"waypoints" => ["toulouse, france", "brest, france"], "travelMode" => "DRIVING", "display_panel" => true, "panel_id" => "instructions"}
78
78
  }
79
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();"
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();"
81
81
  end
82
82
  end
83
83
 
@@ -0,0 +1,20 @@
1
+ Factory.define :user do |f|
2
+ f.name "me"
3
+ f.address "Toulon, France"
4
+ end
5
+
6
+ Factory.define :user_paris, :parent => :user do |f|
7
+ f.name "me"
8
+ f.address "Paris, France"
9
+ end
10
+
11
+ Factory.define :user_with_pic, :parent => :user do |f|
12
+ f.name "me"
13
+ f.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.address "home"
20
+ end
@@ -4,7 +4,7 @@ describe "Acts as gmappable" do
4
4
 
5
5
  describe "standard configuration, valid user" do
6
6
  before(:each) do
7
- @user = User.create!(:name => "me", :address => "Toulon, France" )
7
+ @user = Factory(:user)
8
8
  end
9
9
 
10
10
  it "should have a geocoded position" do
@@ -17,7 +17,7 @@ describe "Acts as gmappable" do
17
17
  end
18
18
 
19
19
  it "should render a valid json from an array of ojects" do
20
- @user2 = User.create!(:name => "me", :address => "Paris, France" )
20
+ @user2 = Factory(:user_paris)
21
21
  User.all.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ,{\n\"description\": \"\", \"title\": \"\",\n\"longitude\": \"2.3509871\", \"latitude\": \"48.8566667\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
22
22
  end
23
23
 
@@ -44,7 +44,7 @@ describe "Acts as gmappable" do
44
44
 
45
45
  describe "standard configuration, invalid address" do
46
46
  before(:each) do
47
- @user = User.new(:name => "me", :address => "home" )
47
+ @user = Factory.build(:invalid_user)
48
48
  end
49
49
 
50
50
  it "should raise an error if validation option is turned on and address incorrect" do
@@ -75,7 +75,7 @@ describe "Acts as gmappable" do
75
75
  }
76
76
  end
77
77
  end
78
- @user = User.new(:name => "me", :address => "home" )
78
+ @user = Factory.build(:invalid_user)
79
79
  @user.should_not be_valid, "Custom Address invalid"
80
80
  end
81
81
 
@@ -92,7 +92,7 @@ describe "Acts as gmappable" do
92
92
  }
93
93
  end
94
94
  end
95
- @user = User.new(:name => "me", :address => "home" )
95
+ @user = Factory.build(:invalid_user)
96
96
  @user.should be_valid
97
97
  end
98
98
 
@@ -109,7 +109,7 @@ describe "Acts as gmappable" do
109
109
  }
110
110
  end
111
111
  end
112
- @user = User.create!(:name => "me", :address => "Toulon, France" )
112
+ @user = Factory(:user)
113
113
  @user.lat_test.should == 43.1251606
114
114
  @user.long_test.should == 5.9311119
115
115
  @user.longitude.should == nil
@@ -130,10 +130,30 @@ describe "Acts as gmappable" do
130
130
  }
131
131
  end
132
132
  end
133
- @user = User.create!(:name => "me", :address => "Toulon, France" )
133
+ @user = Factory(:user)
134
134
  @user.gmaps.should == nil
135
135
  end
136
136
 
137
+ it "should geocode after each save if 'check_process' is false" do
138
+ User.class_eval do
139
+ def gmaps4rails_options
140
+ {
141
+ :lat_column => "latitude",
142
+ :lng_column => "longitude",
143
+ :check_process => false,
144
+ :checker => "gmaps",
145
+ :msg => "Address invalid",
146
+ :validation => true
147
+ }
148
+ end
149
+ end
150
+ @user = Factory(:user)
151
+ @user.address = "paris, France"
152
+ @user.save
153
+ @user.latitude.should == 48.8566667
154
+ @user.longitude.should == 2.3509871
155
+ end
156
+
137
157
  it "should save to the proper boolean checker set in checker" do
138
158
  User.class_eval do
139
159
  def gmaps4rails_options
@@ -147,7 +167,7 @@ describe "Acts as gmappable" do
147
167
  }
148
168
  end
149
169
  end
150
- @user = User.create!(:name => "me", :address => "Toulon, France" )
170
+ @user = Factory(:user)
151
171
  @user.gmaps.should == nil
152
172
  @user.bool_test.should == true
153
173
  end
@@ -158,7 +178,7 @@ describe "Acts as gmappable" do
158
178
  "My Beautiful Picture: #{picture}"
159
179
  end
160
180
  end
161
- @user = User.create!(:name => "me", :address => "Toulon, France", :picture => "http://www.blankdots.com/img/github-32x32.png")
181
+ @user = Factory(:user_with_pic)
162
182
  @user.to_gmaps4rails.should == "[{\n\"description\": \"My Beautiful Picture: http://www.blankdots.com/img/github-32x32.png\", \"title\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"\", \"width\": \"\", \"height\": \"\"\n} ]"
163
183
  end
164
184
 
@@ -175,7 +195,7 @@ describe "Acts as gmappable" do
175
195
  }
176
196
  end
177
197
  end
178
- @user = User.create!(:name => "me", :address => "Toulon, France")
198
+ @user = Factory(:user)
179
199
  @user.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"http://www.blankdots.com/img/github-32x32.png\", \"width\": \"32\", \"height\": \"32\"\n} ]"
180
200
  end
181
201
 
@@ -185,7 +205,7 @@ describe "Acts as gmappable" do
185
205
  "Sweet Title"
186
206
  end
187
207
  end
188
- @user = User.create!(:name => "me", :address => "Toulon, France")
208
+ @user = Factory(:user)
189
209
  @user.to_gmaps4rails.should == "[{\n\"description\": \"\", \"title\": \"Sweet Title\",\n\"longitude\": \"5.9311119\", \"latitude\": \"43.1251606\", \"picture\": \"http://www.blankdots.com/img/github-32x32.png\", \"width\": \"32\", \"height\": \"32\"\n} ]"
190
210
  end
191
211
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmaps4rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 4
10
- version: 0.6.4
9
+ - 5
10
+ version: 0.6.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Benjamin Roth
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-03-21 00:00:00 +01:00
19
+ date: 2011-03-23 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -86,6 +86,7 @@ files:
86
86
  - test/dummy/db/seeds.rb
87
87
  - test/dummy/spec/base/base_spec.rb
88
88
  - test/dummy/spec/controllers/users_controller_spec.rb
89
+ - test/dummy/spec/factories.rb
89
90
  - test/dummy/spec/models/user_spec.rb
90
91
  - test/dummy/spec/spec_helper.rb
91
92
  has_rdoc: true
@@ -146,5 +147,6 @@ test_files:
146
147
  - test/dummy/db/seeds.rb
147
148
  - test/dummy/spec/base/base_spec.rb
148
149
  - test/dummy/spec/controllers/users_controller_spec.rb
150
+ - test/dummy/spec/factories.rb
149
151
  - test/dummy/spec/models/user_spec.rb
150
152
  - test/dummy/spec/spec_helper.rb