Skip to content

Business intelligence made simple

Improved upload tests [skip ci]

Andrew Kane81be4446db5c
diff --git a/test/test_helper.rb b/test/test_helper.rb
index c10cfeb3..ad67889c 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -15,10 +15,6 @@ end
Rails.cache.logger = logger
-ActiveSupport.on_load(:active_record) do
- connection.execute("CREATE SCHEMA IF NOT EXISTS uploads")
-end
-
class ActionDispatch::IntegrationTest
def run_query(statement, **params)
post blazer.run_queries_path, params: {statement: statement, data_source: "main"}.merge(params), xhr: true
diff --git a/test/uploads_test.rb b/test/uploads_test.rb
index 8fe9c0b2..b38181c8 100644
--- a/test/uploads_test.rb
+++ b/test/uploads_test.rb
@@ -3,6 +3,8 @@ require_relative "test_helper"
class UploadsTest < ActionDispatch::IntegrationTest
def setup
Blazer::Upload.delete_all
+ Blazer::UploadsConnection.connection.execute("DROP SCHEMA IF EXISTS uploads CASCADE")
+ Blazer::UploadsConnection.connection.execute("CREATE SCHEMA uploads")
end
def test_index
@@ -16,7 +18,7 @@ class UploadsTest < ActionDispatch::IntegrationTest
end
def test_create
- post blazer.uploads_path, params: {upload: {table: "line_items", description: "Billing line items", file: fixture_file_upload("test/support/line_items.csv", "text/csv")}}
+ create_upload
assert_response :redirect
upload = Blazer::Upload.last
@@ -34,4 +36,15 @@ class UploadsTest < ActionDispatch::IntegrationTest
assert_equal "text", column_types["e"]
assert_equal "text", column_types["f"]
end
+
+ def test_create_duplicate_table
+ create_upload
+ assert_response :redirect
+ create_upload
+ assert_response :unprocessable_entity
+ end
+
+ def create_upload
+ post blazer.uploads_path, params: {upload: {table: "line_items", description: "Billing line items", file: fixture_file_upload("test/support/line_items.csv", "text/csv")}}
+ end
end