Add new test file for AbstractTableGeocoder

pull/4283/head
Rafa de la Torre 9 years ago
parent 3f7df180e3
commit bc432b4334

@ -179,6 +179,7 @@ WORKING_SPECS_10 = \
spec/models/carto/user_spec.rb \
spec/models/carto/user_creation_spec.rb \
spec/models/carto/organization_spec.rb \
services/table-geocoder/spec/lib/abstract_table_geocoder_spec.rb \
$(NULL)
CDB_PATH=lib/assets/javascripts/cdb

@ -0,0 +1,84 @@
# encoding: utf-8
require_relative '../factories/pg_connection'
require_relative '../../lib/abstract_table_geocoder'
require_relative '../../../../spec/rspec_configuration.rb'
describe CartoDB::AbstractTableGeocoder do
before(:all) do
class ConcreteTableGeocoder < CartoDB::AbstractTableGeocoder; end
conn = CartoDB::Importer2::Factories::PGConnection.new
@db = conn.connection
@pg_options = conn.pg_options
@table_name = "ne_10m_populated_places_simple"
load_csv path_to("populated_places_short.csv")
end
after(:all) do
@db.drop_table @table_name
end
describe '#initialize' do
it 'sets the connection timeout to 5 hours' do
tg = ConcreteTableGeocoder.new({
connection: @db,
table_name: @table_name,
qualified_table_name: @table_name
})
timeout = @db.fetch("SHOW statement_timeout").first.fetch(:statement_timeout)
timeout.should == '5h'
end
end
describe '#add_georef_status_column' do
before(:each) do
@tg = ConcreteTableGeocoder.new({
connection: @db,
table_name: @table_name,
qualified_table_name: @table_name
})
end
it 'adds a georef_status_column if it does not exists' do
@tg.send(:add_georef_status_column)
assert_correctness_of_georef_status_column
end
it 'does nothing if the column already exists' do
@tg.send(:add_georef_status_column)
@tg.send(:add_georef_status_column)
assert_correctness_of_georef_status_column
end
it 'casts its type if the column exists and is not bool' do
@db.add_column @table_name, :georef_status_column, :text
@tg.send(:add_georef_status_column)
assert_correctness_of_georef_status_column
end
end
def assert_correctness_of_georef_status_column
georef_status_column = @db.schema(@table_name, reload: true).select {|c| c[0] == :cartodb_georef_status}.first
georef_status_column.nil?.should == false
georef_status_column[1][:db_type].should == 'boolean'
end
def load_csv(path)
@db.run("CREATE TABLE #{@table_name} (the_geom geometry, cartodb_id integer, name text, iso3 text)")
@db.run("COPY #{@table_name.lit}(cartodb_id, name, iso3) FROM '#{path}' DELIMITER ',' CSV")
end
def path_to(filepath = '')
File.expand_path(
File.join(File.dirname(__FILE__), "../fixtures/#{filepath}")
)
end
end

@ -221,12 +221,12 @@ describe CartoDB::TableGeocoder do
File.expand_path(
File.join(File.dirname(__FILE__), "../spec/fixtures/#{filepath}")
)
end #path_to
end
def load_csv(path)
@db.run("CREATE TABLE #{@table_name} (the_geom geometry, cartodb_id integer, name text, iso3 text)")
@db.run("COPY #{@table_name.lit}(cartodb_id, name, iso3) FROM '#{path}' DELIMITER ',' CSV")
end # create_table
end
end

Loading…
Cancel
Save