CDB-1856 partial commit, reactivating specs, pending adding new url format detection

pull/366/head
Kartones 11 years ago
parent fbc7c125a1
commit b12c523977

@ -22,6 +22,8 @@ WORKING_SPECS = \
spec/requests/admin/tables_spec.rb \
spec/models/geocoding_spec.rb \
spec/requests/api/imports_spec.rb \
services/importer/spec/unit/url_translator/osm_spec.rb \
services/importer/spec/unit/url_translator/osm2_spec.rb \
$(NULL)
CDB_PATH=lib/assets/javascripts/cdb

@ -6,6 +6,8 @@ module CartoDB
module UrlTranslator
class OSM2
URL_REGEX = %r{openstreetmap.org/#map=}
# New format as of Feb2014
#URL_REGEX2 = %r{openstreetmap.org/export#map=}
TRANSLATED_URL_REGEX = /api.openstreetmap.org/
URL_TEMPLATE = "http://api.openstreetmap.org/api/0.6/map?bbox="
DW = 1200.0/2.0
@ -38,12 +40,20 @@ module CartoDB
end #bounding_box_for
def supported?(url)
!!(url =~ URL_REGEX)
!!(url =~ URL_REGEX) #|| !!(url =~ URL_REGEX2)
end #supported?
def translated?(url)
!!(url =~ TRANSLATED_URL_REGEX)
end #translated?
private
def is_old_format?(url)
end #is_old_format?
end #OSM2
end # UrlTranslator
end # Importer2

@ -1,6 +1,4 @@
# encoding: utf-8
gem 'minitest'
require 'minitest/autorun'
require_relative '../../../lib/importer/url_translator/osm2'
include CartoDB::Importer2
@ -10,17 +8,17 @@ describe UrlTranslator::OSM2 do
it 'returns a translated OSM2 url' do
url = "http://www.openstreetmap.org/#map=18/40.43494/-3.70068"
translated = UrlTranslator::OSM2.new.translate(url)
translated.must_match /api.openstreetmap.org/
translated.should match /api.openstreetmap.org/
end
it 'returns the url if already translated' do
translated = 'http://api.openstreetmap.org'
UrlTranslator::OSM2.new.translate(translated).must_equal translated
UrlTranslator::OSM2.new.translate(translated).should eq translated
end
it 'returns the url if not supported' do
not_supported = 'http://bogus.com'
UrlTranslator::OSM2.new.translate(not_supported).must_equal not_supported
UrlTranslator::OSM2.new.translate(not_supported).should eq not_supported
end
end #translate
@ -35,7 +33,7 @@ describe UrlTranslator::OSM2 do
url = "http://www.openstreetmap.org/#map=18/40.43494/-3.70068"
UrlTranslator::OSM2.new.bounding_box_for(url)
.must_equal bounding_box.join(',')
.should eq bounding_box.join(',')
end
end #bounding_box_for
@ -43,18 +41,18 @@ describe UrlTranslator::OSM2 do
it 'returns true if URL is from OSM2' do
url = "http://www.openstreetmap.org/#map=18/40.43494/-3.70068"
UrlTranslator::OSM2.new.supported?(url)
.must_equal true
.should eq true
UrlTranslator::OSM2.new.supported?('http://bogus.com')
.must_equal false
.should eq false
end
end #supported?
describe '#translated?' do
it 'returns true if URL already translated' do
UrlTranslator::OSM2.new.translated?('http://api.openstreetmap.org')
.must_equal true
.should eq true
UrlTranslator::OSM2.new.translated?('http://www.openstreetmap.org')
.must_equal false
.should eq false
end
end #translated?
end # UrlTranslator::OSM2

@ -1,6 +1,4 @@
# encoding: utf-8
gem 'minitest'
require 'minitest/autorun'
require_relative '../../../lib/importer/url_translator/osm'
include CartoDB::Importer2
@ -10,17 +8,17 @@ describe UrlTranslator::OSM do
it 'returns a translated OSM url' do
url = "http://www.openstreetmap.org/?lat=40.01005&lon=-105.27517&zoom=15&layers=M"
translated = UrlTranslator::OSM.new.translate(url)
translated.must_match /api.openstreetmap.org/
translated.should match /api.openstreetmap.org/
end
it 'returns the url if already translated' do
translated = 'http://api.openstreetmap.org'
UrlTranslator::OSM.new.translate(translated).must_equal translated
UrlTranslator::OSM.new.translate(translated).should eq translated
end
it 'returns the url if not supported' do
not_supported = 'http://bogus.com'
UrlTranslator::OSM.new.translate(not_supported).must_equal not_supported
UrlTranslator::OSM.new.translate(not_supported).should eq not_supported
end
end #translate
@ -35,7 +33,7 @@ describe UrlTranslator::OSM do
url = "http://www.openstreetmap.org/?lat=40.01005&lon=-105.27517&zoom=15&layers=M"
UrlTranslator::OSM.new.bounding_box_for(url)
.must_equal bounding_box.join(',')
.should eq bounding_box.join(',')
end
end #bounding_box_for
@ -43,18 +41,18 @@ describe UrlTranslator::OSM do
it 'returns true if URL is from OSM' do
url = "http://www.openstreetmap.org/?lat=40.01005&lon=-105.27517&zoom=15&layers=M"
UrlTranslator::OSM.new.supported?(url)
.must_equal true
.should eq true
UrlTranslator::OSM.new.supported?('http://bogus.com')
.must_equal false
.should eq false
end
end #supported?
describe '#translated?' do
it 'returns true if URL already translated' do
UrlTranslator::OSM.new.translated?('http://api.openstreetmap.org')
.must_equal true
.should eq true
UrlTranslator::OSM.new.translated?('http://www.openstreetmap.org')
.must_equal false
.should eq false
end
end #translated?
end # UrlTranslator::OSM

Loading…
Cancel
Save