gmaps4rails 1.5.8 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.travis.yml +9 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +149 -0
- data/Guardfile.old +24 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +129 -0
- data/Rakefile +4 -0
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +20 -0
- data/gmaps4rails.gemspec +38 -0
- data/lib/generators/gmaps4rails/install_generator.rb +43 -0
- data/lib/generators/templates/README +2 -0
- data/lib/gmaps4rails.rb +26 -0
- data/lib/gmaps4rails/acts_as_gmappable.rb +54 -0
- data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +40 -0
- data/lib/gmaps4rails/api_wrappers/direction.rb +87 -0
- data/lib/gmaps4rails/api_wrappers/geocoder.rb +54 -0
- data/lib/gmaps4rails/api_wrappers/places.rb +74 -0
- data/lib/gmaps4rails/base.rb +126 -0
- data/lib/gmaps4rails/extensions/enumerable.rb +14 -0
- data/lib/gmaps4rails/extensions/hash.rb +9 -0
- data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +33 -0
- data/lib/gmaps4rails/js_builder.rb +154 -0
- data/lib/gmaps4rails/json_builder.rb +140 -0
- data/lib/gmaps4rails/model_handler.rb +101 -0
- data/lib/gmaps4rails/version.rb +3 -0
- data/lib/gmaps4rails/view_helper.rb +172 -0
- data/lib/tasks/jasmine.rake +8 -0
- data/public/javascripts/gmaps4rails/all.js +2144 -0
- data/public/javascripts/gmaps4rails/base.js +792 -0
- data/public/javascripts/gmaps4rails/google.js +556 -0
- data/public/javascripts/gmaps4rails/openlayers.js +377 -0
- data/public/stylesheets/gmaps4rails.css +24 -0
- data/spec/dummy/.gitignore +3 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +18 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +24 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/users_controller.rb +105 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/place.rb +16 -0
- data/spec/dummy/app/models/user.rb +12 -0
- data/spec/dummy/app/views/layouts/application.html.erb +17 -0
- data/spec/dummy/app/views/users/_form.html.erb +37 -0
- data/spec/dummy/app/views/users/edit.html.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +268 -0
- data/spec/dummy/app/views/users/new.html.erb +5 -0
- data/spec/dummy/app/views/users/show.html.erb +30 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +62 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/gmaps4rails.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/db/migrate/20120408170155_create_users.rb +16 -0
- data/spec/dummy/db/schema.rb +29 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/Player.js +22 -0
- data/spec/dummy/public/javascripts/Song.js +7 -0
- data/spec/dummy/public/logo.png +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/place_factory.rb +16 -0
- data/spec/factories/user_factory.rb +23 -0
- data/spec/fixtures/google_direction_valid.json +65 -0
- data/spec/fixtures/google_geocoding_toulon_france.json +58 -0
- data/spec/fixtures/google_places_valid.json +45 -0
- data/spec/fixtures/google_wrong_geocoding.json +4 -0
- data/spec/launchers/all_but_requests.rb +0 -0
- data/spec/launchers/all_specs.rb +0 -0
- data/spec/launchers/requests.rb +0 -0
- data/spec/lib/base_spec.rb +59 -0
- data/spec/lib/direction_spec.rb +53 -0
- data/spec/lib/geocoder_spec.rb +46 -0
- data/spec/lib/js_builder_spec.rb +134 -0
- data/spec/lib/json_builder_spec.rb +232 -0
- data/spec/lib/places_spec.rb +25 -0
- data/spec/models/place_spec.rb +39 -0
- data/spec/models/user_spec.rb +187 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/geocoding.rb +40 -0
- data/spec/support/matchers.rb +73 -0
- data/todo +0 -0
- data/vendor/assets/javascripts/gmaps4rails/all.js +1 -0
- data/vendor/assets/javascripts/gmaps4rails/base.coffee +1 -0
- data/vendor/assets/javascripts/gmaps4rails/base/common.coffee +43 -0
- data/vendor/assets/javascripts/gmaps4rails/base/configuration.coffee +7 -0
- data/vendor/assets/javascripts/gmaps4rails/base/gmaps.coffee +13 -0
- data/vendor/assets/javascripts/gmaps4rails/base/interfaces/basic_interface.coffee +15 -0
- data/vendor/assets/javascripts/gmaps4rails/base/interfaces/controller_interface.coffee +15 -0
- data/vendor/assets/javascripts/gmaps4rails/base/interfaces/map_interface.coffee +27 -0
- data/vendor/assets/javascripts/gmaps4rails/base/interfaces/marker_interface.coffee +15 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main.coffee +124 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/circle_controller.coffee +29 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/kml_controller.coffee +5 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/marker_controller.coffee +76 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polygon_controller.coffee +29 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polyline_controller.coffee +29 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/circle.coffee +12 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/kml.coffee +8 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/map.coffee +62 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/marker.coffee +24 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/polygon.coffee +11 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/polyline.coffee +11 -0
- data/vendor/assets/javascripts/gmaps4rails/bing.coffee +1 -0
- data/vendor/assets/javascripts/gmaps4rails/bing/main.coffee +29 -0
- data/vendor/assets/javascripts/gmaps4rails/bing/objects/map.coffee +63 -0
- data/vendor/assets/javascripts/gmaps4rails/bing/objects/marker.coffee +78 -0
- data/vendor/assets/javascripts/gmaps4rails/bing/shared.coffee +20 -0
- data/vendor/assets/javascripts/gmaps4rails/google.coffee +1 -0
- data/vendor/assets/javascripts/gmaps4rails/google/main.coffee +47 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/circle.coffee +38 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/kml.coffee +16 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/map.coffee +71 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/marker.coffee +114 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/polygon.coffee +38 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/polyline.coffee +49 -0
- data/vendor/assets/javascripts/gmaps4rails/google/shared.coffee +27 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers.coffee +1 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers/main.coffee +138 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/map.coffee +49 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/marker.coffee +68 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/polyline.coffee +39 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers/shared.coffee +19 -0
- metadata +378 -14
- checksums.yaml +0 -7
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Places" do
|
4
|
+
|
5
|
+
let(:places) { File.read "spec/fixtures/google_places_valid.json" }
|
6
|
+
|
7
|
+
context "valid request" do
|
8
|
+
before(:each) do
|
9
|
+
stub_request(:get, "https://maps.googleapis.com/maps/api/place/search/json?key=key&language=en&location=0,0&radius=7500&sensor=false").
|
10
|
+
to_return(:status => 200, :body => places, :headers => {})
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does something" do
|
14
|
+
results = Gmaps4rails.places(0, 0, "key")
|
15
|
+
result = OpenStruct.new results.first
|
16
|
+
|
17
|
+
result.lat.should eq -33.871983
|
18
|
+
result.lng.should eq 151.199086
|
19
|
+
result.name.should eq "Zaaffran Restaurant - BBQ and GRILL, Darling Harbour"
|
20
|
+
result.reference.should =~ /^CpQBjAAAAHDHuimUQATR6gfoWNm.*/
|
21
|
+
result.vicinity.should eq "Harbourside Centre 10 Darling Drive, Darling Harbour, Sydney"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
if RUBY_VERSION == "1.9.3"
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Geocoding
|
6
|
+
|
7
|
+
set_gmaps4rails_options!
|
8
|
+
|
9
|
+
# Mongoid 3.x only
|
10
|
+
require 'mongoid'
|
11
|
+
require 'moped'
|
12
|
+
|
13
|
+
Mongoid.configure do |config|
|
14
|
+
config.connect_to('mongoid_geo_test')
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Gmaps4rails::ActsAsGmappable do
|
18
|
+
|
19
|
+
let(:place) { Factory(:place) }
|
20
|
+
let(:invalid_place) { Factory.build(:invalid_place) }
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
Geocoding.stub_geocoding
|
24
|
+
end
|
25
|
+
|
26
|
+
context "standard configuration, valid place" do
|
27
|
+
after(:each) do
|
28
|
+
set_gmaps4rails_options!({})
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should save longitude and latitude to the customized position array" do
|
32
|
+
set_gmaps4rails_options!(:position => 'pos')
|
33
|
+
place.pos.should_not be_nil
|
34
|
+
place.should have_same_position_as TOULON
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Geocoding
|
4
|
+
|
5
|
+
describe Gmaps4rails::ActsAsGmappable do
|
6
|
+
|
7
|
+
let(:user) { Factory(:user) }
|
8
|
+
let(:invalid_user) { FactoryGirl.build(:invalid_user) }
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
set_gmaps4rails_options!
|
12
|
+
end
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
Geocoding.stub_geocoding
|
16
|
+
end
|
17
|
+
|
18
|
+
context "standard configuration, valid user" do
|
19
|
+
|
20
|
+
it "should have a geocoded position" do
|
21
|
+
user.should have_same_position_as TOULON
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set boolean to true once user is created" do
|
25
|
+
user.gmaps.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
context "process_geocoding" do
|
29
|
+
context "Proc" do
|
30
|
+
it "should prevent geocoding when returns false" do
|
31
|
+
user.instance_eval do
|
32
|
+
def gmaps4rails_options
|
33
|
+
DEFAULT_CONFIG_HASH.merge({ :process_geocoding => lambda {|user| false } })
|
34
|
+
end
|
35
|
+
end
|
36
|
+
Gmaps4rails.should_not_receive(:geocode)
|
37
|
+
user.update_attributes(:address => "Strasbourg, france")
|
38
|
+
end
|
39
|
+
|
40
|
+
context "geocoding required" do
|
41
|
+
it "should trigger the geocoding" do
|
42
|
+
user.instance_eval do
|
43
|
+
def gmaps4rails_options
|
44
|
+
DEFAULT_CONFIG_HASH.merge({ :process_geocoding => lambda {|user| true } })
|
45
|
+
end
|
46
|
+
end
|
47
|
+
Gmaps4rails.should_receive(:geocode)
|
48
|
+
user.update_attributes(:address => "Strasbourg, france")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should update coordinates but not update checker" do
|
52
|
+
#first default behavior
|
53
|
+
user.update_attributes(:gmaps => false, :address => "Strasbourg, france")
|
54
|
+
user.gmaps.should eq true
|
55
|
+
#then tested behavior
|
56
|
+
user.instance_eval do
|
57
|
+
def gmaps4rails_options
|
58
|
+
DEFAULT_CONFIG_HASH.merge({ :process_geocoding => lambda {|user| true } })
|
59
|
+
end
|
60
|
+
end
|
61
|
+
user.update_attributes(:gmaps => false, :address => "Strasbourg, france")
|
62
|
+
user.gmaps.should eq false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
it "should not geocode again after address changes if checker is true" do
|
70
|
+
user.update_attributes({ :address => "Paris, France" })
|
71
|
+
user.should have_same_position_as TOULON
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should geocode after address changes if checker is false" do
|
75
|
+
user.update_attributes({ :address => "Paris, France",
|
76
|
+
:gmaps => false})
|
77
|
+
user.should have_same_position_as PARIS
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "standard configuration, invalid address" do
|
82
|
+
|
83
|
+
it "should raise an error if validation option is turned on and address incorrect" do
|
84
|
+
invalid_user.should_not be_valid, "Address invalid"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not set boolean to true when address update fails" do
|
88
|
+
invalid_user.gmaps.should_not be_true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
context "acts_as_gmappable options" do
|
94
|
+
|
95
|
+
after(:all) do
|
96
|
+
#reset all configuration to default
|
97
|
+
set_gmaps4rails_options!
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should call google api with http by default" do
|
101
|
+
address = "toulon, france"
|
102
|
+
Gmaps4rails.should_receive(:geocode).with(address, "en", false, "http").and_return [TOULON]
|
103
|
+
User.create(:address => address)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should call google api with https if passed in settings" do
|
107
|
+
set_gmaps4rails_options!({ :protocol => "https" })
|
108
|
+
address = "toulon, france"
|
109
|
+
Gmaps4rails.should_receive(:geocode).with(address, "en", false, "https").and_return [TOULON]
|
110
|
+
User.create(:address => address)
|
111
|
+
set_gmaps4rails_options!({ :protocol => "http" })
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should use indifferently a db column for address if passed in config" do
|
115
|
+
set_gmaps4rails_options!({:address => "sec_address"})
|
116
|
+
user = Factory(:user, :sec_address => "Toulon, France")
|
117
|
+
user.should have_same_position_as TOULON
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should save the normalized address if requested" do
|
121
|
+
set_gmaps4rails_options!({ :normalized_address => "norm_address" })
|
122
|
+
user.norm_address.should == "Toulon, France"
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should override user's address with normalized address if requested" do
|
126
|
+
set_gmaps4rails_options!({ :normalized_address => "sec_address" })
|
127
|
+
user = Factory(:user, :sec_address => "ToUlOn, FrAnCe")
|
128
|
+
user.sec_address.should == "Toulon, France"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should display the proper error message when address is invalid" do
|
132
|
+
set_gmaps4rails_options!({ :msg => "Custom Address invalid"})
|
133
|
+
invalid_user.should_not be_valid
|
134
|
+
invalid_user.errors[:address].should include("Custom Address invalid")
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should not raise an error if validation option is turned off" do
|
138
|
+
set_gmaps4rails_options!({ :validation => false })
|
139
|
+
invalid_user.should be_valid
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should save longitude and latitude to the customized columns" do
|
143
|
+
set_gmaps4rails_options!({
|
144
|
+
:lat_column => "lat_test",
|
145
|
+
:lng_column => "long_test"
|
146
|
+
})
|
147
|
+
user.latitude.should be_nil
|
148
|
+
user.should have_same_position_as TOULON
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should not save the boolean if check_process is false" do
|
152
|
+
set_gmaps4rails_options!({ :check_process => false })
|
153
|
+
user.gmaps.should be_nil
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should geocode after each save if 'check_process' is false" do
|
157
|
+
set_gmaps4rails_options!({ :check_process => false })
|
158
|
+
user = Factory(:user, :address => "Paris, France")
|
159
|
+
user.should have_same_position_as PARIS
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should save to the proper boolean checker set in checker" do
|
163
|
+
set_gmaps4rails_options!({ :checker => "bool_test" })
|
164
|
+
user.gmaps.should be_nil
|
165
|
+
user.bool_test.should be_true
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should call a callback in the model if asked to" do
|
169
|
+
User.class_eval do
|
170
|
+
def gmaps4rails_options
|
171
|
+
DEFAULT_CONFIG_HASH.merge({ :callback => "save_callback" })
|
172
|
+
end
|
173
|
+
|
174
|
+
def save_callback(data)
|
175
|
+
self.called_back = true
|
176
|
+
end
|
177
|
+
|
178
|
+
attr_accessor :called_back
|
179
|
+
end
|
180
|
+
user.called_back.should be_true
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
ENV["RAILS_ENV"] ||= 'test'
|
4
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
5
|
+
require 'rspec/rails'
|
6
|
+
require 'pry'
|
7
|
+
#require 'capybara/rspec'
|
8
|
+
require 'factory_girl_rails'
|
9
|
+
require 'database_cleaner'
|
10
|
+
require 'webmock/rspec'
|
11
|
+
|
12
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f }
|
13
|
+
FactoryGirl.definition_file_paths = [ File.join(Rails.root, '../factories') ]
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
17
|
+
config.filter_run :focus => true
|
18
|
+
config.run_all_when_everything_filtered = true
|
19
|
+
|
20
|
+
config.use_transactional_fixtures = true
|
21
|
+
config.infer_base_class_for_anonymous_controllers = false
|
22
|
+
|
23
|
+
config.before(:suite) do
|
24
|
+
FactoryGirl.reload
|
25
|
+
File.open("#{Rails.root}/log/test.log", 'w') {|file| file.truncate(0) } #cleans the log file to make it readable and control it's size
|
26
|
+
DatabaseCleaner.strategy = :truncation
|
27
|
+
end
|
28
|
+
|
29
|
+
config.before(:each) do
|
30
|
+
DatabaseCleaner.start
|
31
|
+
DatabaseCleaner.clean
|
32
|
+
end
|
33
|
+
|
34
|
+
config.after(:each) do
|
35
|
+
DatabaseCleaner.clean
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Geocoding
|
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 => "address",
|
11
|
+
:language => "en",
|
12
|
+
:protocol => "http",
|
13
|
+
:process_geocoding => true
|
14
|
+
}
|
15
|
+
|
16
|
+
PARIS = { :latitude => 48.856614, :longitude => 2.3522219 }
|
17
|
+
TOULON = { :latitude => 43.124228, :longitude => 5.928 }
|
18
|
+
|
19
|
+
#set model configuration
|
20
|
+
def set_gmaps4rails_options!(change_conf = {})
|
21
|
+
User.class_eval do
|
22
|
+
define_method "gmaps4rails_options" do
|
23
|
+
DEFAULT_CONFIG_HASH.merge(change_conf)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.stub_geocoding
|
29
|
+
Gmaps4rails.stub(:geocode) do |*args|
|
30
|
+
case args[0]
|
31
|
+
when "Paris, France"
|
32
|
+
[{:lat=>48.856614, :lng=>2.3522219, :matched_address=>"Paris, France", :bounds=>{"northeast"=>{"lat"=>48.902145, "lng"=>2.4699209}, "southwest"=>{"lat"=>48.815573, "lng"=>2.224199}}, :full_data=>{"address_components"=>[{"long_name"=>"Paris", "short_name"=>"Paris", "types"=>["locality", "political"]}, {"long_name"=>"Paris", "short_name"=>"75", "types"=>["administrative_area_level_2", "political"]}, {"long_name"=>"Ile-de-France", "short_name"=>"IdF", "types"=>["administrative_area_level_1", "political"]}, {"long_name"=>"France", "short_name"=>"FR", "types"=>["country", "political"]}], "formatted_address"=>"Paris, France", "geometry"=>{"bounds"=>{"northeast"=>{"lat"=>48.902145, "lng"=>2.4699209}, "southwest"=>{"lat"=>48.815573, "lng"=>2.224199}}, "location"=>{"lat"=>48.856614, "lng"=>2.3522219}, "location_type"=>"APPROXIMATE", "viewport"=>{"northeast"=>{"lat"=>48.9153104, "lng"=>2.4802813}, "southwest"=>{"lat"=>48.7978487, "lng"=>2.2241625}}}, "types"=>["locality", "political"]}}]
|
33
|
+
when "home"
|
34
|
+
raise Gmaps4rails::GeocodeStatus
|
35
|
+
else
|
36
|
+
[{:lat=>43.124228, :lng=>5.928, :matched_address=>"Toulon, France", :bounds=>{"northeast"=>{"lat"=>43.171673, "lng"=>5.987382999999999}, "southwest"=>{"lat"=>43.101049, "lng"=>5.879479}}, :full_data=>{"address_components"=>[{"long_name"=>"Toulon", "short_name"=>"Toulon", "types"=>["locality", "political"]}, {"long_name"=>"Var", "short_name"=>"83", "types"=>["administrative_area_level_2", "political"]}, {"long_name"=>"Provence-Alpes-Cote d'Azur", "short_name"=>"PACA", "types"=>["administrative_area_level_1", "political"]}, {"long_name"=>"France", "short_name"=>"FR", "types"=>["country", "political"]}], "formatted_address"=>"Toulon, France", "geometry"=>{"bounds"=>{"northeast"=>{"lat"=>43.171673, "lng"=>5.987382999999999}, "southwest"=>{"lat"=>43.101049, "lng"=>5.879479}}, "location"=>{"lat"=>43.124228, "lng"=>5.928}, "location_type"=>"APPROXIMATE", "viewport"=>{"northeast"=>{"lat"=>43.156795, "lng"=>5.9920297}, "southwest"=>{"lat"=>43.0916437, "lng"=>5.8639703}}}, "types"=>["locality", "political"]}}]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rspec/expectations'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
def has_same_content_as?(actual, expected)
|
5
|
+
case actual
|
6
|
+
when Array
|
7
|
+
case expected
|
8
|
+
when Array
|
9
|
+
result = true
|
10
|
+
case actual.first
|
11
|
+
when Array
|
12
|
+
actual.each do |actual_subarray|
|
13
|
+
bool = false
|
14
|
+
expected.each do |expected_subarray|
|
15
|
+
bool = bool || has_same_content_as?(actual_subarray, expected_subarray)
|
16
|
+
end
|
17
|
+
result = result && bool
|
18
|
+
end
|
19
|
+
result
|
20
|
+
else
|
21
|
+
(actual - expected).empty?
|
22
|
+
end
|
23
|
+
else
|
24
|
+
false
|
25
|
+
end
|
26
|
+
else
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class PositionMatcher
|
32
|
+
attr_reader :object, :position_hash
|
33
|
+
delegate :position, :lat_column, :lng_column, :to => :@options
|
34
|
+
|
35
|
+
def initialize object, position_hash
|
36
|
+
@object, @position_hash = object, position_hash
|
37
|
+
@options = ::OpenStruct.new object.gmaps4rails_options
|
38
|
+
end
|
39
|
+
|
40
|
+
def same_pos?
|
41
|
+
position_hash[:latitude] == lat && position_hash[:longitude] == lng
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def lat
|
47
|
+
position ? object.send("#{position}")[0] : object.send("#{lat_column}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def lng
|
51
|
+
position ? object.send("#{position}")[1] : object.send("#{lng_column}")
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def position_matcher object, position_hash
|
57
|
+
PositionMatcher.new object, position_hash
|
58
|
+
end
|
59
|
+
|
60
|
+
RSpec::Matchers.define :have_same_position_as do |position_hash|
|
61
|
+
match do |object|
|
62
|
+
position_matcher(object, position_hash).same_pos?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
RSpec::Matchers.define :be_same_json_as do |expected|
|
67
|
+
match do |actual|
|
68
|
+
has_same_content_as?(JSON.parse(actual), JSON.parse(expected))
|
69
|
+
end
|
70
|
+
failure_message_for_should do |actual|
|
71
|
+
"Both object don't have the same content. Beware though, be sure to compare only arrays."
|
72
|
+
end
|
73
|
+
end
|
data/todo
ADDED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
//=require_tree '.'
|
@@ -0,0 +1 @@
|
|
1
|
+
#= require './base/main'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
moduleKeywords = ['extended', 'included']
|
3
|
+
|
4
|
+
@Gmaps4Rails = {}
|
5
|
+
|
6
|
+
class @Gmaps4Rails.Common
|
7
|
+
|
8
|
+
@extend: (obj) ->
|
9
|
+
for key, value of obj when key not in moduleKeywords
|
10
|
+
@[key] = value
|
11
|
+
|
12
|
+
obj.extended?.apply(@)
|
13
|
+
this
|
14
|
+
|
15
|
+
@include: (obj) ->
|
16
|
+
for key, value of obj when key not in moduleKeywords
|
17
|
+
# Assign properties to the prototype
|
18
|
+
@::[key] = value
|
19
|
+
obj.included?.apply(@)
|
20
|
+
this
|
21
|
+
|
22
|
+
#//basic function to check existence of a variable
|
23
|
+
exists : (var_name) ->
|
24
|
+
return (var_name != "" and typeof var_name != "undefined")
|
25
|
+
|
26
|
+
mergeObjects: (object, defaultObject) ->
|
27
|
+
@constructor.mergeObjects(object, defaultObject)
|
28
|
+
|
29
|
+
@mergeObjects: (object, defaultObject) ->
|
30
|
+
copy_object = {}
|
31
|
+
for key, value of object
|
32
|
+
copy_object[key] = value
|
33
|
+
|
34
|
+
for key, value of defaultObject
|
35
|
+
copy_object[key] = value unless copy_object[key]?
|
36
|
+
return copy_object
|
37
|
+
|
38
|
+
@mergeWith : (object) ->
|
39
|
+
for key, value of object
|
40
|
+
@[key] = value unless @[key]?
|
41
|
+
|
42
|
+
#gives a value between -1 and 1
|
43
|
+
random : -> return(Math.random() * 2 -1)
|