on_the_map 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,87 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "on_the_map"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kristian Mandrup"]
12
+ s.date = "2013-03-04"
13
+ s.description = "Makes it easy to add functionality to models related to geocoding, addressing and placing them as pins on a map"
14
+ s.email = "kmandrup@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/address.rb",
29
+ "lib/on_the_map.rb",
30
+ "lib/on_the_map/addressable.rb",
31
+ "lib/on_the_map/geo_locatable.rb",
32
+ "lib/on_the_map/mappable.rb",
33
+ "lib/on_the_map/positionable.rb",
34
+ "on_the_map.gemspec",
35
+ "spec/address_spec.rb",
36
+ "spec/on_the_map/addressable_spec.rb",
37
+ "spec/on_the_map/geo_locatable_spec.rb",
38
+ "spec/on_the_map/geo_locatable_valid_spec.rb",
39
+ "spec/on_the_map/mappable_spec.rb",
40
+ "spec/on_the_map/positionable_spec.rb",
41
+ "spec/on_the_map_spec.rb",
42
+ "spec/spec_helper.rb",
43
+ "spec/support/gmaps_lookup_stubs.rb"
44
+ ]
45
+ s.homepage = "http://github.com/kristianmandrup/on_the_map"
46
+ s.licenses = ["MIT"]
47
+ s.require_paths = ["lib"]
48
+ s.rubygems_version = "1.8.25"
49
+ s.summary = "Pre-baked Mongoid concerns to put models on the map"
50
+
51
+ if s.respond_to? :specification_version then
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_runtime_dependency(%q<mongoid>, [">= 4"])
56
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.7.3"])
57
+ s.add_runtime_dependency(%q<hashie>, ["~> 1.2"])
58
+ s.add_runtime_dependency(%q<concerned>, ["~> 0.1.3"])
59
+ s.add_development_dependency(%q<rspec>, [">= 2.12.0"])
60
+ s.add_development_dependency(%q<rdoc>, [">= 3.1"])
61
+ s.add_development_dependency(%q<bundler>, [">= 1.1.0"])
62
+ s.add_development_dependency(%q<jeweler>, [">= 1.8.4"])
63
+ s.add_development_dependency(%q<simplecov>, [">= 0.5"])
64
+ else
65
+ s.add_dependency(%q<mongoid>, [">= 4"])
66
+ s.add_dependency(%q<sugar-high>, ["~> 0.7.3"])
67
+ s.add_dependency(%q<hashie>, ["~> 1.2"])
68
+ s.add_dependency(%q<concerned>, ["~> 0.1.3"])
69
+ s.add_dependency(%q<rspec>, [">= 2.12.0"])
70
+ s.add_dependency(%q<rdoc>, [">= 3.1"])
71
+ s.add_dependency(%q<bundler>, [">= 1.1.0"])
72
+ s.add_dependency(%q<jeweler>, [">= 1.8.4"])
73
+ s.add_dependency(%q<simplecov>, [">= 0.5"])
74
+ end
75
+ else
76
+ s.add_dependency(%q<mongoid>, [">= 4"])
77
+ s.add_dependency(%q<sugar-high>, ["~> 0.7.3"])
78
+ s.add_dependency(%q<hashie>, ["~> 1.2"])
79
+ s.add_dependency(%q<concerned>, ["~> 0.1.3"])
80
+ s.add_dependency(%q<rspec>, [">= 2.12.0"])
81
+ s.add_dependency(%q<rdoc>, [">= 3.1"])
82
+ s.add_dependency(%q<bundler>, [">= 1.1.0"])
83
+ s.add_dependency(%q<jeweler>, [">= 1.8.4"])
84
+ s.add_dependency(%q<simplecov>, [">= 0.5"])
85
+ end
86
+ end
87
+
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Address do
4
+ pending 'todo'
5
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ require 'on_the_map/addressable'
3
+
4
+ class MyAddress
5
+ include Mongoid::Document
6
+ include OnTheMap::Addressable
7
+ end
8
+
9
+ class MyGeoCodedAddress
10
+ include Mongoid::Document
11
+ include OnTheMap::Addressable
12
+
13
+ def perform_geocoding
14
+ end
15
+ end
16
+
17
+ describe OnTheMap::Addressable do
18
+ subject { address }
19
+
20
+ context 'blank/empty address' do
21
+ let(:address) { MyGeoCodableAddress.create street: '', city: '' }
22
+
23
+ it 'should have a blank full address' do
24
+ expect(subject.address.full).to be_blank
25
+ end
26
+
27
+ it 'should not be geolocatable' do
28
+ expect(subject.geolocatable?).to be false
29
+ end
30
+ end
31
+
32
+ let(:address) { MyAddress.create street: 'maglekildevej 18, 4th', city: '1853 Frederiksberg C' }
33
+
34
+ context 'without geocoding' do
35
+ Address.address_fields.each do |fname|
36
+ describe fname do
37
+ it 'should return value' do
38
+ expect { subject.send fname }.to_not raise_error
39
+ end
40
+ end
41
+
42
+ describe "#{fname}=" do
43
+ it 'should set value' do
44
+ subject.send("#{fname}=", 'hello')
45
+ expect(subject.send fname).to eq 'hello'
46
+ end
47
+ end
48
+ end
49
+
50
+ describe 'region' do
51
+ it 'should use the field' do
52
+ subject.state = 'denmark'
53
+ expect(subject.region).to match /denmark/
54
+ end
55
+ end
56
+
57
+ describe 'full_address' do
58
+ it 'should use the field' do
59
+ subject.street = 'denmark'
60
+ expect(subject.full_address).to match /denmark/
61
+ end
62
+ end
63
+
64
+ describe 'set_address' do
65
+ it 'should set the fields' do
66
+ subject.set_address(city: 'barcelona')
67
+ expect(subject.city).to eq 'barcelona'
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'on_the_map/geo_locatable'
3
+
4
+ class MyGeoCodableAddress
5
+ include Mongoid::Document
6
+ include OnTheMap::GeoLocatable
7
+ end
8
+
9
+
10
+ describe OnTheMap::GeoLocatable do
11
+ subject { address }
12
+
13
+ context 'empty address' do
14
+ let(:address) { MyGeoCodableAddress.create street: '', city: '' }
15
+
16
+ it 'should have a blank full address' do
17
+ expect(subject.address.full).to be_blank
18
+ end
19
+
20
+ it 'should not be geolocatable' do
21
+ expect(subject.geolocatable?).to be false
22
+ end
23
+
24
+ it 'should not be geocoded?' do
25
+ expect(subject.geocoded?).to be false
26
+ end
27
+ end
28
+
29
+ context 'invalid address' do
30
+ let(:address) { MyGeoCodableAddress.create street: 'blip blab', city: 'blop' }
31
+
32
+ it 'should be geolocatable' do
33
+ expect(subject.geolocatable?).to be_true
34
+ end
35
+
36
+ it 'should not calculate a position' do
37
+ expect(subject.position.to_a).to be_blank
38
+ end
39
+
40
+ it 'should not be geocoded?' do
41
+ expect(subject.geocoded?).to be false
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'on_the_map/geo_locatable'
3
+
4
+ class MyGeoCodableAddress
5
+ include Mongoid::Document
6
+ include OnTheMap::GeoLocatable
7
+ end
8
+
9
+ describe OnTheMap::GeoLocatable do
10
+ subject { address }
11
+
12
+ context 'valid address' do
13
+ let(:address) { MyGeoCodableAddress.create street: street, city: city }
14
+
15
+ let(:city) { 'Frederiksberg' }
16
+ let(:street) { 'Maglekildevej 18, 4th' }
17
+
18
+ describe 'creation' do
19
+ its(:city) { should == city }
20
+ its(:street) { should == street }
21
+
22
+ it 'should be geocoded?' do
23
+ expect(subject.geocoded?).to be true
24
+ end
25
+
26
+ its('position.to_a') { should_not be_empty }
27
+
28
+ it 'should geocode and calculate latitude' do
29
+ expect(subject.latitude).to be_within(1).of 55
30
+ end
31
+
32
+ it 'should geocode and calculate longitude' do
33
+ expect(subject.longitude).to be_within(1).of 12
34
+ end
35
+
36
+ context 'after update of street address' do
37
+ before do
38
+ @old_address = subject.dup
39
+ subject.street = 'Gammel kongevej 123'
40
+ end
41
+
42
+ describe 'calculated new position' do
43
+ it 'has been updated' do
44
+ expect(subject.position.to_a).to_not eq @old_address.position.to_a
45
+ end
46
+
47
+ it 'has new latitude' do
48
+ expect(subject.latitude).to_not eq @old_address.latitude
49
+ end
50
+
51
+ it 'has longitude' do
52
+ expect(subject.longitude).to_not eq @old_address.longitude
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rails'
4
+ require 'gmaps4rails'
5
+
6
+ require 'on_the_map/mappable'
7
+
8
+
9
+ class MyMappableAddress
10
+ include Mongoid::Document
11
+ # include OnTheMap::GeoLocatable
12
+ include OnTheMap::Mappable
13
+ end
14
+
15
+
16
+ describe OnTheMap::Mappable do
17
+ subject { address }
18
+
19
+ context 'empty address' do
20
+ let(:address) { MyMappableAddress.create street: '', city: '' }
21
+
22
+ it 'should have a blank full address' do
23
+ expect(subject.address.full).to be_blank
24
+ end
25
+
26
+ it 'should not be geolocatable' do
27
+ expect(subject.geolocatable?).to be false
28
+ end
29
+
30
+ it 'should not be geocoded?' do
31
+ expect(subject.geocoded?).to be false
32
+ end
33
+
34
+ it 'should not have a gmaps' do
35
+ expect(subject.gmaps).to_not be true
36
+ end
37
+
38
+ it 'should not have a normalized address' do
39
+ expect(subject.normalized_address).to be_blank
40
+ end
41
+ end
42
+
43
+ context 'invalid address' do
44
+ let(:address) { MyMappableAddress.create street: 'blip blab', city: 'blop' }
45
+
46
+ it 'should be geolocatable' do
47
+ expect(subject.geolocatable?).to be_true
48
+ end
49
+
50
+ it 'should not calculate a position' do
51
+ expect(subject.position.to_a).to be_blank
52
+ end
53
+
54
+ it 'should not be geocoded?' do
55
+ expect(subject.geocoded?).to be false
56
+ end
57
+
58
+ it 'should not have a gmaps' do
59
+ expect(subject.gmaps).to_not be_true
60
+ end
61
+
62
+ it 'should not have a normalized address' do
63
+ expect(subject.normalized_address).to be_blank
64
+ end
65
+ end
66
+
67
+ context 'valid address' do
68
+ let(:address) { MyMappableAddress.create street: street, city: city }
69
+
70
+ let(:city) { 'Frederiksberg' }
71
+ let(:street) { 'Maglekildevej 18, 4th' }
72
+
73
+ describe 'creation' do
74
+ its(:city) { should == city }
75
+ its(:street) { should == street }
76
+
77
+ # leave geocoding to geocoder!
78
+ its(:gmaps_geocode?) { should be_false }
79
+
80
+ # geocoder sets gmaps when position has been calculated
81
+ its(:gmaps) { should be_true }
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ require 'on_the_map/positionable'
4
+
5
+ require 'rails'
6
+ require 'mongoid'
7
+ require 'rails/mongoid'
8
+
9
+ module Dummy
10
+ class Application < Rails::Application
11
+ end
12
+ end
13
+
14
+ require 'mongoid_indexing'
15
+
16
+ class MyPositionableAddress
17
+ include Mongoid::Document
18
+ # include OnTheMap::GeoLocatable
19
+ include OnTheMap::Positionable
20
+ end
21
+
22
+ describe OnTheMap::Positionable do
23
+ subject { address }
24
+
25
+ before :suite do
26
+ Mongoid.logger = Logger.new($stdout)
27
+ Moped.logger = Logger.new($stdout)
28
+ end
29
+
30
+ context 'empty address' do
31
+ let(:address) { }
32
+
33
+ before do
34
+ 5.times do |n|
35
+ MyPositionableAddress.create position: [rand(n), n*4]
36
+ end
37
+
38
+ ::Mongoid::Indexing.create_indexes
39
+ end
40
+
41
+ describe 'positions' do
42
+ before do
43
+ @nearby = MyPositionableAddress.nearby(MyPositionableAddress.first.position)
44
+ # puts "nearby: #{@nearby.to_a.inspect}"
45
+ end
46
+
47
+ it 'should have all nearby' do
48
+ expect(@nearby).to have(5).items
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe "OnTheMap" do
4
+ pending 'TODO'
5
+ end
@@ -0,0 +1,44 @@
1
+ require 'rspec'
2
+ require 'on_the_map'
3
+
4
+ require 'hashie'
5
+ require 'concerned'
6
+
7
+ require 'mongoid'
8
+ require 'moped'
9
+
10
+ require 'factory_girl'
11
+
12
+ require 'geocoder'
13
+
14
+ # Requires supporting files with custom matchers and macros, etc,
15
+ # in ./support/ and its subdirectories.
16
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
17
+
18
+ RSpec.configure do |config|
19
+ Mongoid.configure do |mongoid_config|
20
+ mongoid_config.connect_to('mongoid_map_test')
21
+ end
22
+
23
+ # Remove this line if you don't want RSpec's should and should_not
24
+ # methods or matchers
25
+ require 'rspec/expectations'
26
+ config.include RSpec::Matchers
27
+
28
+ config.include FactoryGirl::Syntax::Methods
29
+
30
+ # == Mock Framework
31
+ config.mock_with :rspec
32
+
33
+ config.include Mongoid::Matchers
34
+
35
+ # Clean up the database
36
+ require 'database_cleaner'
37
+ config.before(:suite) do
38
+ DatabaseCleaner[:mongoid].strategy = :truncation
39
+ end
40
+
41
+ config.before(:each) do
42
+ DatabaseCleaner.clean
43
+ end
44
+ end
@@ -0,0 +1,86 @@
1
+ Geocoder.configure(:lookup => :test)
2
+
3
+ Invalid_adr = {
4
+ 'latitude' => nil,
5
+ 'longitude' => nil,
6
+ 'address' => nil,
7
+ 'state' => nil,
8
+ 'state_code' => nil,
9
+ 'country' => nil,
10
+ 'country_code' => nil
11
+ }
12
+
13
+ # Invalid
14
+
15
+ Geocoder::Lookup::Test.add_stub(
16
+ "blip blab", [Invalid_adr]
17
+ )
18
+
19
+ Geocoder::Lookup::Test.add_stub(
20
+ "blip blab, blop", [Invalid_adr]
21
+ )
22
+
23
+ Geocoder::Lookup::Test.add_stub(
24
+ "blip blab, blop, DK", [Invalid_adr]
25
+ )
26
+
27
+ Maglekildevej = {
28
+ 'latitude' => 55.677069,
29
+ 'longitude' => 12.513321,
30
+ 'address' => 'Maglekildevej 18, 4th, Frederiksberg, Copenhagen, Denmark',
31
+ 'state' => '',
32
+ 'state_code' => '',
33
+ 'country' => 'Denmark',
34
+ 'country_code' => 'DK'
35
+ }
36
+
37
+ Gammel_kongevej = {
38
+ 'latitude' => 55.67616169999999,
39
+ 'longitude' => 12.5422907,
40
+ 'address' => 'Gammel kongevej 123, Frederiksberg, Copenhagen, Denmark',
41
+ 'state' => '',
42
+ 'state_code' => '',
43
+ 'country' => 'Denmark',
44
+ 'country_code' => 'DK'
45
+ }
46
+
47
+ # Gammel kongevej
48
+
49
+ Geocoder::Lookup::Test.add_stub(
50
+ "Gammel kongevej 123, Frederiksberg", [Gammel_kongevej]
51
+ )
52
+
53
+ Geocoder::Lookup::Test.add_stub(
54
+ "Gammel kongevej 123", [Gammel_kongevej]
55
+ )
56
+
57
+ Geocoder::Lookup::Test.add_stub(
58
+ "Gammel kongevej 123, Frederiksberg, DK", [Gammel_kongevej]
59
+ )
60
+
61
+ Geocoder::Lookup::Test.add_stub(
62
+ "Gammel kongevej 123, Frederiksberg, Denmark, DK", [Gammel_kongevej]
63
+ )
64
+
65
+
66
+ # Maglekildevej
67
+
68
+ Geocoder::Lookup::Test.add_stub(
69
+ "Maglekildevej 18, 4th, Frederiksberg", [Maglekildevej]
70
+ )
71
+
72
+ Geocoder::Lookup::Test.add_stub(
73
+ "Maglekildevej 18, 4th", [Maglekildevej]
74
+ )
75
+
76
+ Geocoder::Lookup::Test.add_stub(
77
+ "Maglekildevej 18, 4th, Denmark, DK", [Maglekildevej]
78
+ )
79
+
80
+ Geocoder::Lookup::Test.add_stub(
81
+ "Maglekildevej 18, 4th, Frederiksberg, Denmark, DK", [Maglekildevej]
82
+ )
83
+
84
+ Geocoder::Lookup::Test.add_stub(
85
+ "Maglekildevej 18, 4th, Frederiksberg, DK", [Maglekildevej]
86
+ )