Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable integration with geocoder for mongo using reverse internal arr…
…ay format [lng,lat]
- Loading branch information
1 parent
2df768b
commit dd9c8de
Showing
9 changed files
with
115 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
if RUBY_VERSION == "1.9.3" | ||
|
||
require 'mongoid' | ||
|
||
class GeoPlace | ||
include Mongoid::Document | ||
include Gmaps4rails::ActsAsGmappable | ||
|
||
# Array position format in the form: [lng, lat] | ||
# This format is f.ex used by *geocoder* gem | ||
acts_as_gmappable :address => :address, :position => :pos, :pos_order => [:lng, :lat] | ||
|
||
field :pos, :type => Array | ||
field :address, :type => String | ||
field :gmaps, :type => Boolean | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FactoryGirl.define do | ||
factory :geo_place do | ||
|
||
trait :paris do | ||
address "Paris, France" | ||
end | ||
|
||
trait :invalid do | ||
address "home" | ||
end | ||
|
||
address "Toulon, France" | ||
|
||
factory :geo_place_paris, :traits => [:paris] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
if RUBY_VERSION == "1.9.3" | ||
|
||
require 'spec_helper' | ||
|
||
include Geocoding | ||
|
||
set_gmaps4rails_options! | ||
|
||
# Mongoid 3.x only | ||
require 'mongoid' | ||
require 'moped' | ||
|
||
Mongoid.configure do |config| | ||
config.connect_to('mongoid_geo_test') | ||
end | ||
|
||
describe Gmaps4rails::ActsAsGmappable do | ||
|
||
# Tests Array position format in the form: [lng, lat] | ||
# F.ex required for integration with *geocoder* gem | ||
let(:geo_place) { Factory(:geo_place) } | ||
let(:invalid_geo_place) { Factory.build(:invalid_geo_place) } | ||
|
||
before(:each) do | ||
Geocoding.stub_geocoding | ||
end | ||
|
||
context "standard configuration, valid place" do | ||
it "should save longitude and latitude to the customized position array" do | ||
set_gmaps4rails_options!(:position => 'location', :pos_order => [:lng, :lat]) | ||
geo_place.pos.should_not be_nil | ||
geo_place.should have_same_position_as TOULON | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters