on_the_map 0.1.4 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/address.rb +9 -0
- data/lib/on_the_map/addressable.rb +8 -0
- data/lib/on_the_map/geo_locatable.rb +2 -2
- data/lib/on_the_map/version.rb +1 -1
- data/spec/spec_helper.rb +4 -0
- data/spec/support/gmaps_lookup_stubs.rb +106 -86
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 811edf28a0f93de8a49c23d5392dfe0e6b7cbce5
|
4
|
+
data.tar.gz: 16977c27a4d715afde3e6d199bdadcd71eeec096
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd1bdb8f829cbd3a927d9b8229cdf26182616aabd1598943f3a0944d4c95acfbc29e10cdd9c621521ba92c60d6ef2f38f87c274ca9108d628844a314a66f5b2f
|
7
|
+
data.tar.gz: a63b3333a79e43bb0be5eafd122fcfa95cd56f68a7619d382eec3ad40125d175355b4703dceb689e7947a54735be142790d82e305df8297c4fd9586e1389a402
|
data/lib/address.rb
CHANGED
@@ -17,6 +17,15 @@ class Address
|
|
17
17
|
%w{street number floor_adr} + geo_address_fields
|
18
18
|
end
|
19
19
|
|
20
|
+
def self.type_of name
|
21
|
+
case name.to_sym
|
22
|
+
when :latitude, :longitude, :postal_code
|
23
|
+
:int
|
24
|
+
else
|
25
|
+
:string
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
20
29
|
address_fields.each do |name|
|
21
30
|
field name, type: String
|
22
31
|
end
|
@@ -56,13 +56,13 @@ module OnTheMap
|
|
56
56
|
|
57
57
|
def latitude
|
58
58
|
perform_geocoding unless position
|
59
|
-
position[1] if position
|
59
|
+
position[1].to_i if position
|
60
60
|
end
|
61
61
|
alias_method :lat, :latitude
|
62
62
|
|
63
63
|
def longitude
|
64
64
|
perform_geocoding unless position
|
65
|
-
position[0] if position
|
65
|
+
position[0].to_i if position
|
66
66
|
end
|
67
67
|
alias_method :lng, :longitude
|
68
68
|
|
data/lib/on_the_map/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -13,6 +13,7 @@ require 'geocoder'
|
|
13
13
|
|
14
14
|
# Requires supporting files with custom matchers and macros, etc,
|
15
15
|
# in ./support/ and its subdirectories.
|
16
|
+
# Dir["#{File.dirname(__FILE__)}/support/*.rb"].each {|f| require f}
|
16
17
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
17
18
|
|
18
19
|
RSpec.configure do |config|
|
@@ -27,6 +28,9 @@ RSpec.configure do |config|
|
|
27
28
|
|
28
29
|
config.include FactoryGirl::Syntax::Methods
|
29
30
|
|
31
|
+
# Stub geocoding
|
32
|
+
GeocodeStubbing.stub_geocoding!
|
33
|
+
|
30
34
|
# == Mock Framework
|
31
35
|
config.mock_with :rspec
|
32
36
|
|
@@ -1,86 +1,106 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
1
|
+
module GeocodeStubbing
|
2
|
+
def self.stub_geocoding!
|
3
|
+
StubGeocodeLookups.new
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class StubGeocodeLookups
|
8
|
+
def initialize
|
9
|
+
Geocoder.configure(:lookup => :test)
|
10
|
+
configure
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
add_stubs :invalid_adr, :maglekildevej, :gammel_kongevej
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def add_stubs *stubs
|
20
|
+
stubs.flatten.each {|stub| add_stub stub }
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_stub stub
|
24
|
+
stubber = stub_class(stub).new
|
25
|
+
|
26
|
+
stubber.places.flatten.each do |place|
|
27
|
+
Geocoder::Lookup::Test.add_stub place, [stubber.result]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def stub_class name
|
32
|
+
"StubGeocodeLookups::#{name.to_s.camelize}".constantize
|
33
|
+
end
|
34
|
+
|
35
|
+
def resolve *stubs
|
36
|
+
[stubs].flatten.map {|stub| send(stub) }
|
37
|
+
end
|
38
|
+
|
39
|
+
class Stubber
|
40
|
+
end
|
41
|
+
|
42
|
+
class InvalidAdr < Stubber
|
43
|
+
def result
|
44
|
+
{
|
45
|
+
'latitude' => nil,
|
46
|
+
'longitude' => nil,
|
47
|
+
'address' => nil,
|
48
|
+
'state' => nil,
|
49
|
+
'state_code' => nil,
|
50
|
+
'country' => nil,
|
51
|
+
'country_code' => nil
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def places
|
56
|
+
["blip blab", "blip blab, blop", "blip blab, blop, DK"]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Maglekildevej < Stubber
|
61
|
+
def result
|
62
|
+
{
|
63
|
+
'latitude' => 55.677069,
|
64
|
+
'longitude' => 12.513321,
|
65
|
+
'address' => 'Maglekildevej 18, 4th, Frederiksberg, Copenhagen, Denmark',
|
66
|
+
'state' => '',
|
67
|
+
'state_code' => '',
|
68
|
+
'country' => 'Denmark',
|
69
|
+
'country_code' => 'DK'
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def places
|
74
|
+
[
|
75
|
+
"Maglekildevej 18, 4th",
|
76
|
+
"Maglekildevej 18, 4th, Frederiksberg",
|
77
|
+
"Maglekildevej 18, 4th, Denmark, DK",
|
78
|
+
"Maglekildevej 18, 4th, Frederiksberg, DK",
|
79
|
+
"Maglekildevej 18, 4th, Frederiksberg, Denmark, DK"
|
80
|
+
]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class GammelKongevej < Stubber
|
85
|
+
def result
|
86
|
+
{
|
87
|
+
'latitude' => 55.67616169999999,
|
88
|
+
'longitude' => 12.5422907,
|
89
|
+
'address' => 'Gammel kongevej 123, Frederiksberg, Copenhagen, Denmark',
|
90
|
+
'state' => '',
|
91
|
+
'state_code' => '',
|
92
|
+
'country' => 'Denmark',
|
93
|
+
'country_code' => 'DK'
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
def places
|
98
|
+
[
|
99
|
+
"Gammel kongevej 123",
|
100
|
+
"Gammel kongevej 123, Frederiksberg",
|
101
|
+
"Gammel kongevej 123, Frederiksberg, DK",
|
102
|
+
"Gammel kongevej 123, Frederiksberg, Denmark, DK"
|
103
|
+
]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|