Fixes imports specs

2.0
Fernando Espinosa 12 years ago
parent d8edd0ec82
commit 0c85e76fdc

@ -118,7 +118,7 @@ class DataImport < Sequel::Model
def before_save def before_save
self.updated_now self.updated_now
end end
def after_rollback(*args, &block) def after_rollback(*args, &block)
self.save self.save

@ -5,14 +5,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe "Imports API" do describe "Imports API" do
before(:each) do before(:each) do
User.all.each(&:destroy)
@user = create_user(:username => 'test', :email => "client@example.com", :password => "clientex") @user = create_user(:username => 'test', :email => "client@example.com", :password => "clientex")
@user.set_map_key @user.set_map_key
end end
it 'allows users to perform asynchronous imports' do it 'allows users to perform asynchronous imports' do
post v1_imports_url(:host => 'test.localhost.lan'), :file_uri => upload_file('spec/support/data/column_boolean_to_string.csv', 'text/plain'), :api_key => @user.get_map_key post v1_imports_url(:host => 'test.localhost.lan'), :file_uri => upload_file('db/fake_data/column_string_to_boolean.csv', 'text/plain'), :api_key => @user.get_map_key
response.code.should be == '200' response.code.should be == '200'
@ -22,12 +22,12 @@ describe "Imports API" do
last_import = DataImport.order(:updated_at.desc).first last_import = DataImport.order(:updated_at.desc).first
last_import.queue_id.should be == response_json['item_queue_id'] last_import.queue_id.should be == response_json['item_queue_id']
last_import.state.should be == 'preprocessing' last_import.state.should be == 'complete'
end end
it 'allows users to get a list of all performed imports' do it 'allows users to get a list of all performed imports' do
%w(column_boolean_to_string column_number_to_boolean column_number_to_string column_string_to_boolean).each do |file_name| %w(arrivals_BCN clubbing column_number_to_boolean column_string_to_boolean).each do |file_name|
post v1_imports_url(:host => 'test.localhost.lan'), :file_uri => upload_file("spec/support/data/#{file_name}.csv", 'text/plain'), :api_key => @user.get_map_key post v1_imports_url(:host => 'test.localhost.lan'), :file_uri => upload_file("db/fake_data/#{file_name}.csv", 'text/plain'), :api_key => @user.get_map_key
end end
get v1_imports_url(:host => 'test.localhost.lan'), :api_key => @user.get_map_key get v1_imports_url(:host => 'test.localhost.lan'), :api_key => @user.get_map_key
@ -41,17 +41,19 @@ describe "Imports API" do
end end
it 'allows users to get the detail of an import' do it 'allows users to get the detail of an import' do
post v1_imports_url(:host => 'test.localhost.lan'), :file_uri => upload_file('spec/support/data/clubbing.csv', 'text/plain'), post v1_imports_url(:host => 'test.localhost.lan'), :file_uri => upload_file('db/fake_data/clubbing.csv', 'text/plain'),
:table_name => 'wadus', :table_name => 'wadus',
:api_key => @user.get_map_key :api_key => @user.get_map_key
item_queue_id = JSON.parse(response.body)['item_queue_id'] item_queue_id = JSON.parse(response.body)['item_queue_id']
puts item_queue_id
get v1_import_url(:host => 'test.localhost.lan', :id => item_queue_id), :api_key => @user.get_map_key get v1_import_url(:host => 'test.localhost.lan', :id => item_queue_id), :api_key => @user.get_map_key
response.code.should be == '200' response.code.should be == '200'
response_json = JSON.parse(response.body) import = JSON.parse(response.body)
import = response_json['import']
import['state'].should be == 'complete' import['state'].should be == 'complete'
end end

@ -31,6 +31,7 @@ module CartoDB
def create_user(attributes = {}) def create_user(attributes = {})
user = new_user(attributes) user = new_user(attributes)
user.save user.save
user
end end
def create_admin(attributes = {}) def create_admin(attributes = {})

Loading…
Cancel
Save