touchpass 0.0.8.1
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.
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +38 -0
- data/Guardfile +9 -0
- data/Rakefile +1 -0
- data/app/controllers/touchpass/verifications_controller.rb +30 -0
- data/bin/tpcli.rb +248 -0
- data/config/routes.rb +8 -0
- data/lib/engine.rb +4 -0
- data/lib/generators/templates/config/initializers/devise.rb +204 -0
- data/lib/generators/templates/config/initializers/touchpass.rb +24 -0
- data/lib/generators/templates/config/locales/devise.en.yml +53 -0
- data/lib/generators/touchpass/install_generator.rb +36 -0
- data/lib/touchpass/client.rb +431 -0
- data/lib/touchpass/crypt.rb +51 -0
- data/lib/touchpass/device.rb +18 -0
- data/lib/touchpass/key_file_creator.rb +56 -0
- data/lib/touchpass/prp.rb +256 -0
- data/lib/touchpass/verification.rb +112 -0
- data/lib/touchpass/version.rb +3 -0
- data/lib/touchpass.rb +53 -0
- data/spec/bounding_box_spec.rb +26 -0
- data/spec/geocode_spec.rb +22 -0
- data/spec/helpers/client_spec_helper.rb +1 -0
- data/spec/helpers/gtp_spec_helper.rb +98 -0
- data/spec/key_file_creator_spec.rb +30 -0
- data/spec/proximity_spec.rb +283 -0
- data/spec/prp_spec.rb +86 -0
- data/spec/resolution_spec.rb +46 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/touchpass_client_spec.rb +319 -0
- data/touchpass.gemspec +27 -0
- metadata +146 -0
@@ -0,0 +1,283 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Proximity" do
|
4
|
+
|
5
|
+
context "using apple store sydney and mecca espresso in king street sydney" do
|
6
|
+
it "should be proximate for STREET resolution" do
|
7
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => apple_store_sydney, :resolution => "STREET")
|
8
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => mecca_espresso_king_st, :resolution => "STREET")
|
9
|
+
prp1.proximate?(prp2).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be proximate for LOCAL resolution" do
|
13
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => "367 George Street Sydney 2000 NSW Australia", :resolution => "LOCAL")
|
14
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => mecca_espresso_king_st, :resolution => "LOCAL")
|
15
|
+
prp1.proximate?(prp2).should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be proximate for METRO resolution" do
|
19
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => "367 George Street Sydney 2000 NSW Australia", :resolution => "METRO")
|
20
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => mecca_espresso_king_st, :resolution => "METRO")
|
21
|
+
prp1.proximate?(prp2).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be proximate for REGIONAL resolution" do
|
25
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => "367 George Street Sydney 2000 NSW Australia", :resolution => "REGIONAL")
|
26
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => mecca_espresso_king_st, :resolution => "REGIONAL")
|
27
|
+
prp1.proximate?(prp2).should be_true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "using 10 holdsworth st neutral bay and 92 pacific hwy north sydney" do
|
32
|
+
it "should not be proximate for STREET resolution" do
|
33
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => holdsworth_st_neutralbay, :resolution => "STREET")
|
34
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => north_sydney_post_office, :resolution => "STREET")
|
35
|
+
prp1.proximate?(prp2).should be_false
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be proximate for LOCAL resolution" do
|
39
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => holdsworth_st_neutralbay, :resolution => "LOCAL")
|
40
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => north_sydney_post_office, :resolution => "LOCAL")
|
41
|
+
prp1.proximate?(prp2).should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be proximate for METRO resolution" do
|
45
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => holdsworth_st_neutralbay, :resolution => "METRO")
|
46
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => north_sydney_post_office, :resolution => "METRO")
|
47
|
+
prp1.proximate?(prp2).should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be proximate for REGIONAL resolution" do
|
51
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => holdsworth_st_neutralbay, :resolution => "REGIONAL")
|
52
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => north_sydney_post_office, :resolution => "REGIONAL")
|
53
|
+
prp1.proximate?(prp2).should be_true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "using 127 talga rd rothbury and cessnock post office" do
|
58
|
+
it "should not be proximate for STREET resolution" do
|
59
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => talga_rd_rothbury, :resolution => "STREET")
|
60
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => cessnock_post_office, :resolution => "STREET")
|
61
|
+
prp1.proximate?(prp2).should be_false
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not be proximate for LOCAL resolution" do
|
65
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => talga_rd_rothbury, :resolution => "LOCAL")
|
66
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => cessnock_post_office, :resolution => "LOCAL")
|
67
|
+
prp1.proximate?(prp2).should be_false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should be proximate for METRO resolution" do
|
71
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => talga_rd_rothbury, :resolution => "METRO")
|
72
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => cessnock_post_office, :resolution => "METRO")
|
73
|
+
prp1.proximate?(prp2).should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be proximate for REGIONAL resolution" do
|
77
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => talga_rd_rothbury, :resolution => "REGIONAL")
|
78
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => cessnock_post_office, :resolution => "REGIONAL")
|
79
|
+
prp1.proximate?(prp2).should be_true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "using orbitec office in sydney and cessnock post office" do
|
84
|
+
it "should not be proximate for STREET resolution" do
|
85
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => orbitec_office, :resolution => "STREET")
|
86
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => cessnock_post_office, :resolution => "STREET")
|
87
|
+
prp1.proximate?(prp2).should be_false
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should not be proximate for LOCAL resolution" do
|
91
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => orbitec_office, :resolution => "LOCAL")
|
92
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => cessnock_post_office, :resolution => "LOCAL")
|
93
|
+
prp1.proximate?(prp2).should be_false
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should not be proximate for METRO resolution" do
|
97
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => orbitec_office, :resolution => "METRO")
|
98
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => cessnock_post_office, :resolution => "METRO")
|
99
|
+
prp1.proximate?(prp2).should be_false
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should be proximate for REGIONAL resolution" do
|
103
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => orbitec_office, :resolution => "REGIONAL")
|
104
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => cessnock_post_office, :resolution => "REGIONAL")
|
105
|
+
prp1.proximate?(prp2).should be_true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "using empire state building new york and orbitec office in sydney" do
|
110
|
+
it "should not be proximate for STREET resolution" do
|
111
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => empire_state_building, :resolution => "STREET")
|
112
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => orbitec_office, :resolution => "STREET")
|
113
|
+
prp1.proximate?(prp2).should be_false
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should not be proximate for LOCAL resolution" do
|
117
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => empire_state_building, :resolution => "LOCAL")
|
118
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => orbitec_office, :resolution => "LOCAL")
|
119
|
+
prp1.proximate?(prp2).should be_false
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should not be proximate for METRO resolution" do
|
123
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => empire_state_building, :resolution => "METRO")
|
124
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => orbitec_office, :resolution => "METRO")
|
125
|
+
prp1.proximate?(prp2).should be_false
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should not be proximate for REGIONAL resolution" do
|
129
|
+
prp1 = Touchpass::Proximity::PRP.new(:address => empire_state_building, :resolution => "REGIONAL")
|
130
|
+
prp2 = Touchpass::Proximity::PRP.new(:address => orbitec_office, :resolution => "REGIONAL")
|
131
|
+
prp1.proximate?(prp2).should be_false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
context "using corner cases with LOCAL resolution" do
|
137
|
+
|
138
|
+
context "using geographic coordinates around the equator" do
|
139
|
+
|
140
|
+
it "north of equator (#{north_of_equator[:lat]}, #{north_of_equator[:lng]}) should be proximate to south of equator (#{south_of_equator[:lat]}, #{south_of_equator[:lng]})" do
|
141
|
+
prp = Touchpass::Proximity::PRP.new(north_of_equator)
|
142
|
+
prp2 = Touchpass::Proximity::PRP.new(south_of_equator)
|
143
|
+
prp.proximate?(prp2).should be_true
|
144
|
+
end
|
145
|
+
|
146
|
+
it "north of equator (#{north_of_equator[:lat]}, #{north_of_equator[:lng]}) should be proximate to south of equator (#{south_of_equator[:lat]}, #{south_of_equator[:lng]})" do
|
147
|
+
prp = Touchpass::Proximity::PRP.new(north_of_equator)
|
148
|
+
prp2 = Touchpass::Proximity::PRP.new(south_of_equator)
|
149
|
+
prp.proximate?(prp2).should be_true
|
150
|
+
end
|
151
|
+
|
152
|
+
it "north of equator (#{north_of_equator[:lat]}, #{north_of_equator[:lng]}) should be proximate to somewhere also in north of equator (#{north_of_equator[:lat]+0.1}, #{north_of_equator[:lng]+0.1})" do
|
153
|
+
prp = Touchpass::Proximity::PRP.new(north_of_equator)
|
154
|
+
prp2 = Touchpass::Proximity::PRP.new(:lat => north_of_equator[:lat]+0.1, :lng => north_of_equator[:lng]+0.1)
|
155
|
+
prp.proximate?(prp2).should be_true
|
156
|
+
end
|
157
|
+
|
158
|
+
it "south of equator (#{south_of_equator[:lat]}, #{south_of_equator[:lng]}) should be proximate to somewhere also in south of equator (#{south_of_equator[:lat]-0.1}, #{south_of_equator[:lng]-0.1})" do
|
159
|
+
prp = Touchpass::Proximity::PRP.new(south_of_equator)
|
160
|
+
prp2 = Touchpass::Proximity::PRP.new(:lat => south_of_equator[:lat]-0.1, :lng => south_of_equator[:lng]-0.1)
|
161
|
+
prp.proximate?(prp2).should be_true
|
162
|
+
end
|
163
|
+
|
164
|
+
it "east of gmt (#{east_of_gmt[:lat]}, #{east_of_gmt[:lng]}) should be proximate to west of gmt (#{west_of_gmt[:lat]}, #{west_of_gmt[:lng]})" do
|
165
|
+
prp = Touchpass::Proximity::PRP.new(east_of_gmt)
|
166
|
+
prp2 = Touchpass::Proximity::PRP.new(west_of_gmt)
|
167
|
+
prp.proximate?(prp2).should be_true
|
168
|
+
end
|
169
|
+
|
170
|
+
it "east of gmt (#{east_of_gmt[:lat]}, #{east_of_gmt[:lng]}) should be proximate to somewhere also in east of gmt (#{east_of_gmt[:lat]+0.1}, #{east_of_gmt[:lng]+0.1})" do
|
171
|
+
prp = Touchpass::Proximity::PRP.new(east_of_gmt)
|
172
|
+
prp2 = Touchpass::Proximity::PRP.new(:lat => east_of_gmt[:lat]+0.1, :lng => east_of_gmt[:lng]+0.1)
|
173
|
+
prp.proximate?(prp2).should be_true
|
174
|
+
end
|
175
|
+
|
176
|
+
it "west of gmt (#{west_of_gmt[:lat]}, #{west_of_gmt[:lng]}) should be proximate to somewhere also in west of gmt (#{west_of_gmt[:lat]-0.1}, #{west_of_gmt[:lng]-0.1})" do
|
177
|
+
prp = Touchpass::Proximity::PRP.new(west_of_gmt)
|
178
|
+
prp2 = Touchpass::Proximity::PRP.new(:lat => west_of_gmt[:lat]-0.1, :lng => west_of_gmt[:lng]-0.1)
|
179
|
+
prp.proximate?(prp2).should be_true
|
180
|
+
end
|
181
|
+
|
182
|
+
it "north west of equator and gmt (#{north_west_of_equator_and_gmt[:lat]}, #{north_west_of_equator_and_gmt[:lng]}) should be proximate to north east of equator and gmt (#{north_east_of_equator_and_gmt[:lat]}, #{north_east_of_equator_and_gmt[:lng]})" do
|
183
|
+
prp = Touchpass::Proximity::PRP.new(north_west_of_equator_and_gmt)
|
184
|
+
prp2 = Touchpass::Proximity::PRP.new(north_east_of_equator_and_gmt)
|
185
|
+
prp.proximate?(prp2).should be_true
|
186
|
+
end
|
187
|
+
|
188
|
+
it "north east of equator and gmt (#{north_east_of_equator_and_gmt[:lat]}, #{north_east_of_equator_and_gmt[:lng]}) should be proximate to south east of equator and gmt (#{south_east_of_equator_and_gmt[:lat]}, #{south_east_of_equator_and_gmt[:lng]})" do
|
189
|
+
prp = Touchpass::Proximity::PRP.new(north_east_of_equator_and_gmt)
|
190
|
+
prp2 = Touchpass::Proximity::PRP.new(south_east_of_equator_and_gmt)
|
191
|
+
prp.proximate?(prp2).should be_true
|
192
|
+
end
|
193
|
+
|
194
|
+
it "south east of equator and gmt (#{south_east_of_equator_and_gmt[:lat]}, #{south_east_of_equator_and_gmt[:lng]}) should be proximate to south west of equator and gmt (#{south_west_of_equator_and_gmt[:lat]}, #{south_west_of_equator_and_gmt[:lng]})" do
|
195
|
+
prp = Touchpass::Proximity::PRP.new(south_east_of_equator_and_gmt)
|
196
|
+
prp2 = Touchpass::Proximity::PRP.new(south_west_of_equator_and_gmt)
|
197
|
+
prp.proximate?(prp2).should be_true
|
198
|
+
end
|
199
|
+
|
200
|
+
it "south west of equator and gmt (#{south_west_of_equator_and_gmt[:lat]}, #{south_west_of_equator_and_gmt[:lng]}) should be proximate to north west of equator and gmt (#{north_west_of_equator_and_gmt[:lat]}, #{north_west_of_equator_and_gmt[:lng]})" do
|
201
|
+
prp = Touchpass::Proximity::PRP.new(south_west_of_equator_and_gmt)
|
202
|
+
prp2 = Touchpass::Proximity::PRP.new(north_west_of_equator_and_gmt)
|
203
|
+
prp.proximate?(prp2).should be_true
|
204
|
+
end
|
205
|
+
|
206
|
+
it "north west of equator and gmt (#{north_west_of_equator_and_gmt[:lat]}, #{north_west_of_equator_and_gmt[:lng]}) should be proximate to south east of equator and gmt (#{south_east_of_equator_and_gmt[:lat]}, #{south_east_of_equator_and_gmt[:lng]})" do
|
207
|
+
prp = Touchpass::Proximity::PRP.new(north_west_of_equator_and_gmt)
|
208
|
+
prp2 = Touchpass::Proximity::PRP.new(south_east_of_equator_and_gmt)
|
209
|
+
prp.proximate?(prp2).should be_true
|
210
|
+
end
|
211
|
+
|
212
|
+
it "north east of equator and gmt (#{north_east_of_equator_and_gmt[:lat]}, #{north_east_of_equator_and_gmt[:lng]}) should be proximate to south west of equator and gmt (#{south_west_of_equator_and_gmt[:lat]}, #{south_west_of_equator_and_gmt[:lng]})" do
|
213
|
+
prp = Touchpass::Proximity::PRP.new(north_east_of_equator_and_gmt)
|
214
|
+
prp2 = Touchpass::Proximity::PRP.new(south_west_of_equator_and_gmt)
|
215
|
+
prp.proximate?(prp2).should be_true
|
216
|
+
end
|
217
|
+
|
218
|
+
it "north of equator (#{north_of_equator[:lat]}, #{north_of_equator[:lng]}) should be proximate to south west of equator and gmt (#{south_west_of_equator_and_gmt[:lat]}, #{south_west_of_equator_and_gmt[:lng]})" do
|
219
|
+
prp = Touchpass::Proximity::PRP.new(north_of_equator)
|
220
|
+
prp2 = Touchpass::Proximity::PRP.new(south_west_of_equator_and_gmt)
|
221
|
+
prp.proximate?(prp2).should be_true
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
context "using more corner cases" do
|
226
|
+
|
227
|
+
it "should be proximate around (#{cornercase1[:lat]}, #{cornercase1[:lng]})" do
|
228
|
+
cc1 = Touchpass::Proximity::PRP.new(cornercase1)
|
229
|
+
cc1a = Touchpass::Proximity::PRP.new(:lat => cornercase1[:lat]+0.005, :lng => cornercase1[:lng]+0.005 )
|
230
|
+
cc1b = Touchpass::Proximity::PRP.new(:lat => cornercase1[:lat]-0.005, :lng => cornercase1[:lng]+0.005 )
|
231
|
+
cc1c = Touchpass::Proximity::PRP.new(:lat => cornercase1[:lat]+0.005, :lng => cornercase1[:lng]-0.005 )
|
232
|
+
cc1d = Touchpass::Proximity::PRP.new(:lat => cornercase1[:lat]-0.005, :lng => cornercase1[:lng]-0.005 )
|
233
|
+
|
234
|
+
cc1.proximate?(cc1a).should be_true
|
235
|
+
cc1.proximate?(cc1b).should be_true
|
236
|
+
cc1.proximate?(cc1c).should be_true
|
237
|
+
cc1.proximate?(cc1d).should be_true
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should be proximate around (#{cornercase2[:lat]}, #{cornercase2[:lng]})" do
|
241
|
+
cc1 = Touchpass::Proximity::PRP.new(cornercase2)
|
242
|
+
cc1a = Touchpass::Proximity::PRP.new(:lat => cornercase2[:lat]+0.005, :lng => cornercase2[:lng]+0.005 )
|
243
|
+
cc1b = Touchpass::Proximity::PRP.new(:lat => cornercase2[:lat]-0.005, :lng => cornercase2[:lng]+0.005 )
|
244
|
+
cc1c = Touchpass::Proximity::PRP.new(:lat => cornercase2[:lat]+0.005, :lng => cornercase2[:lng]-0.005 )
|
245
|
+
cc1d = Touchpass::Proximity::PRP.new(:lat => cornercase2[:lat]-0.005, :lng => cornercase2[:lng]-0.005 )
|
246
|
+
|
247
|
+
cc1.proximate?(cc1a).should be_true
|
248
|
+
cc1.proximate?(cc1b).should be_true
|
249
|
+
cc1.proximate?(cc1c).should be_true
|
250
|
+
cc1.proximate?(cc1d).should be_true
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should be proximate around (#{cornercase3[:lat]}, #{cornercase3[:lng]})" do
|
254
|
+
cc1 = Touchpass::Proximity::PRP.new(cornercase3)
|
255
|
+
cc1a = Touchpass::Proximity::PRP.new(:lat => cornercase3[:lat]+0.005, :lng => cornercase3[:lng]+0.005 )
|
256
|
+
cc1b = Touchpass::Proximity::PRP.new(:lat => cornercase3[:lat]-0.005, :lng => cornercase3[:lng]+0.005 )
|
257
|
+
cc1c = Touchpass::Proximity::PRP.new(:lat => cornercase3[:lat]+0.005, :lng => cornercase3[:lng]-0.005 )
|
258
|
+
cc1d = Touchpass::Proximity::PRP.new(:lat => cornercase3[:lat]-0.005, :lng => cornercase3[:lng]-0.005 )
|
259
|
+
|
260
|
+
cc1.proximate?(cc1a).should be_true
|
261
|
+
cc1.proximate?(cc1b).should be_true
|
262
|
+
cc1.proximate?(cc1c).should be_true
|
263
|
+
cc1.proximate?(cc1d).should be_true
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should be proximate around (#{cornercase4[:lat]}, #{cornercase4[:lng]})" do
|
267
|
+
cc1 = Touchpass::Proximity::PRP.new(cornercase4)
|
268
|
+
cc1a = Touchpass::Proximity::PRP.new(:lat => cornercase4[:lat]+0.005, :lng => cornercase4[:lng]+0.005 )
|
269
|
+
cc1b = Touchpass::Proximity::PRP.new(:lat => cornercase4[:lat]-0.005, :lng => cornercase4[:lng]+0.005 )
|
270
|
+
cc1c = Touchpass::Proximity::PRP.new(:lat => cornercase4[:lat]+0.005, :lng => cornercase4[:lng]-0.005 )
|
271
|
+
cc1d = Touchpass::Proximity::PRP.new(:lat => cornercase4[:lat]-0.005, :lng => cornercase4[:lng]-0.005 )
|
272
|
+
|
273
|
+
cc1.proximate?(cc1a).should be_true
|
274
|
+
cc1.proximate?(cc1b).should be_true
|
275
|
+
cc1.proximate?(cc1c).should be_true
|
276
|
+
cc1.proximate?(cc1d).should be_true
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
data/spec/prp_spec.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Touchpass::Proximity::PRP do
|
4
|
+
|
5
|
+
describe ".new" do
|
6
|
+
|
7
|
+
context "using mecca espresso king st sydney address" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@prp = Touchpass::Proximity::PRP.new(:address => mecca_espresso_king_st)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set the latitude and longitude" do
|
14
|
+
@prp.lat.should be
|
15
|
+
@prp.lng.should be
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should generate the bounding box" do
|
19
|
+
@prp.bounding_box.should be
|
20
|
+
@prp.bounding_box.keys.size.should eql(4)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".encrypt" do
|
28
|
+
|
29
|
+
context "using sha256 crypto provider" do
|
30
|
+
|
31
|
+
before do
|
32
|
+
@prp1 = Touchpass::Proximity::PRP.new(:address => apple_store_sydney)
|
33
|
+
@prp2 = Touchpass::Proximity::PRP.new(:address => mecca_espresso_king_st)
|
34
|
+
@prp3 = Touchpass::Proximity::PRP.new(:address => cessnock_post_office)
|
35
|
+
@prp4 = Touchpass::Proximity::PRP.new(:address => empire_state_building)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should generate 256 characters string" do
|
39
|
+
encrypted_prp = @prp1.encrypt(Touchpass::Crypt.salt)
|
40
|
+
encrypted_prp.size.should eql(256)
|
41
|
+
|
42
|
+
encrypted_prp = @prp2.encrypt(Touchpass::Crypt.salt)
|
43
|
+
encrypted_prp.size.should eql(256)
|
44
|
+
|
45
|
+
encrypted_prp = @prp3.encrypt(Touchpass::Crypt.salt)
|
46
|
+
encrypted_prp.size.should eql(256)
|
47
|
+
|
48
|
+
encrypted_prp = @prp4.encrypt(Touchpass::Crypt.salt)
|
49
|
+
encrypted_prp.size.should eql(256)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#calibrate_lat" do
|
57
|
+
|
58
|
+
it "-0.0 should be calibrated to 0.0" do
|
59
|
+
Touchpass::Proximity::PRP.calibrate_lat(-0.00).should eql(0.0)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "latitude should be within -90.0 and 90.0" do
|
63
|
+
Touchpass::Proximity::PRP.calibrate_lat(0.00).should be >= Touchpass::Proximity::PRP::MIN_LAT and be <= Touchpass::Proximity::PRP::MAX_LAT
|
64
|
+
Touchpass::Proximity::PRP.calibrate_lat(45.00).should be >= Touchpass::Proximity::PRP::MIN_LAT and be <= Touchpass::Proximity::PRP::MAX_LAT
|
65
|
+
Touchpass::Proximity::PRP.calibrate_lat(90.05).should be >= Touchpass::Proximity::PRP::MIN_LAT and be <= Touchpass::Proximity::PRP::MAX_LAT
|
66
|
+
Touchpass::Proximity::PRP.calibrate_lat(-90.05).should be >= Touchpass::Proximity::PRP::MIN_LAT and be <= Touchpass::Proximity::PRP::MAX_LAT
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#calibrate_lng" do
|
72
|
+
|
73
|
+
it "-0.0 should be calibrated to 0.0" do
|
74
|
+
Touchpass::Proximity::PRP.calibrate_lng(-0.00).should eql(0.0)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "longitude should be within -180.0 and 180.0" do
|
78
|
+
Touchpass::Proximity::PRP.calibrate_lng(0.00).should be >= Touchpass::Proximity::PRP::MIN_LNG and be <= Touchpass::Proximity::PRP::MAX_LNG
|
79
|
+
Touchpass::Proximity::PRP.calibrate_lng(100.00).should be >= Touchpass::Proximity::PRP::MIN_LNG and be <= Touchpass::Proximity::PRP::MAX_LNG
|
80
|
+
Touchpass::Proximity::PRP.calibrate_lng(180.05).should be >= Touchpass::Proximity::PRP::MIN_LNG and be <= Touchpass::Proximity::PRP::MAX_LNG
|
81
|
+
Touchpass::Proximity::PRP.calibrate_lng(-180.05).should be >= Touchpass::Proximity::PRP::MIN_LNG and be <= Touchpass::Proximity::PRP::MAX_LNG
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Resolution" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
#coord = -33.868297, 151.2035896
|
7
|
+
Geocoder.stub(:coordinates).and_return([-33.868297, 151.2035896])
|
8
|
+
end
|
9
|
+
|
10
|
+
[orbitec_office, north_of_equator].each do |point|
|
11
|
+
|
12
|
+
context point.is_a?(String) ? "using address '#{point}'" : "using lat: #{point[:lat]}, lng: #{point[:lng]}" do
|
13
|
+
|
14
|
+
[["STREET", 3], ["LOCAL", 2], ["METRO", 1], ["REGIONAL", 0]].each do |resolution, decimal_places|
|
15
|
+
|
16
|
+
context "using #{resolution} resolution" do
|
17
|
+
|
18
|
+
it "should have #{decimal_places} decimal places coordinates" do
|
19
|
+
if point.is_a? String
|
20
|
+
prp = Touchpass::Proximity::PRP.new :address => point, :resolution => resolution
|
21
|
+
else
|
22
|
+
prp = Touchpass::Proximity::PRP.new :lat => point[:lat], :lng => point[:lng], :resolution => resolution
|
23
|
+
end
|
24
|
+
prp.resolution.should eql(eval("Touchpass::Proximity::PRP::BBoxResolution::#{resolution.upcase}"))
|
25
|
+
|
26
|
+
lat = Touchpass::Proximity::PRP.format_decimal(prp.lat, Touchpass::Proximity::PRP.truncate_size(prp.resolution))
|
27
|
+
lng = Touchpass::Proximity::PRP.format_decimal(prp.lng, Touchpass::Proximity::PRP.truncate_size(prp.resolution))
|
28
|
+
case resolution
|
29
|
+
when 'REGIONAL'
|
30
|
+
lat.to_s.split(".").size.should eql(1)
|
31
|
+
lng.to_s.split(".").size.should eql(1)
|
32
|
+
else
|
33
|
+
lat.to_s.split(".").last.size.should eql(Touchpass::Proximity::PRP.truncate_size(prp.resolution))
|
34
|
+
lng.to_s.split(".").last.size.should eql(Touchpass::Proximity::PRP.truncate_size(prp.resolution))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
SPEC_KEYS_PATH = File.join(ENV['HOME'], ".touchpass", "certs_spec")
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
config.before(:suite) do
|
16
|
+
# use a different directory for spec keys
|
17
|
+
Touchpass::KeyFileCreator.keys_path = SPEC_KEYS_PATH
|
18
|
+
FileUtils::rm_rf(SPEC_KEYS_PATH)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'helpers/gtp_spec_helper'
|
24
|
+
require 'helpers/client_spec_helper'
|