Skip to content

Business intelligence made simple

Added more tests

Andrew Kane4e6157983f6c
diff --git a/lib/blazer.rb b/lib/blazer.rb
index 0c44ed89..10a69e79 100644
--- a/lib/blazer.rb
+++ b/lib/blazer.rb
@@ -43,6 +43,8 @@ module Blazer
autoload :CheckMailer, "blazer/check_mailer"
# net/http optional
autoload :SlackNotifier, "blazer/slack_notifier"
+ # activejob optional
+ autoload :RunStatementJob, "blazer/run_statement_job"
class << self
attr_accessor :audit
diff --git a/lib/blazer/engine.rb b/lib/blazer/engine.rb
index 03caa9ac..abf403e2 100644
--- a/lib/blazer/engine.rb
+++ b/lib/blazer/engine.rb
@@ -30,10 +30,6 @@ module Blazer
Blazer.anomaly_checks = Blazer.settings["anomaly_checks"] || false
Blazer.forecasting = Blazer.settings["forecasting"] || false
Blazer.async = Blazer.settings["async"] || false
- if Blazer.async
- require "blazer/run_statement_job"
- end
-
Blazer.images = Blazer.settings["images"] || false
Blazer.override_csp = Blazer.settings["override_csp"] || false
Blazer.slack_oauth_token = Blazer.settings["slack_oauth_token"] || ENV["BLAZER_SLACK_OAUTH_TOKEN"]
diff --git a/test/dashboards_test.rb b/test/dashboards_test.rb
index d5cec2db..426de4cf 100644
--- a/test/dashboards_test.rb
+++ b/test/dashboards_test.rb
@@ -1,6 +1,11 @@
require_relative "test_helper"
class DashboardsTest < ActionDispatch::IntegrationTest
+ def setup
+ Blazer::Query.delete_all
+ Blazer::Dashboard.delete_all
+ end
+
def test_new
get blazer.new_dashboard_path
assert_response :success
@@ -18,6 +23,13 @@ class DashboardsTest < ActionDispatch::IntegrationTest
assert_response :redirect
end
+ def test_refresh
+ dashboard = create_dashboard
+ dashboard.queries << create_query
+ post blazer.refresh_dashboard_path(dashboard)
+ assert_response :redirect
+ end
+
def create_dashboard
Blazer::Dashboard.create!(name: "Test")
end
diff --git a/test/queries_test.rb b/test/queries_test.rb
index 961b4152..1c51d9e7 100644
--- a/test/queries_test.rb
+++ b/test/queries_test.rb
@@ -56,6 +56,12 @@ class QueriesTest < ActionDispatch::IntegrationTest
assert_response :success
end
+ def test_refresh
+ query = create_query
+ post blazer.refresh_query_path(query)
+ assert_response :redirect
+ end
+
def test_variables_time
query = create_query(statement: "SELECT {created_at}")
get blazer.query_path(query)
@@ -117,4 +123,13 @@ class QueriesTest < ActionDispatch::IntegrationTest
assert_match %{<img referrerpolicy="no-referrer" src="http://localhost:3000/image.png" }, response.body
end
end
+
+ def test_async
+ Blazer.stub(:async, true) do
+ perform_enqueued_jobs do
+ run_query "SELECT 123"
+ end
+ assert_match "123", response.body
+ end
+ end
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 73ab728c..fe78e408 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -7,9 +7,10 @@ require "minitest/pride"
logger = ActiveSupport::Logger.new(ENV["VERBOSE"] ? STDERR : nil)
Combustion.path = "test/internal"
-Combustion.initialize! :active_record, :action_controller, :action_mailer, :sprockets do
+Combustion.initialize! :active_record, :action_controller, :action_mailer, :active_job, :sprockets do
config.action_controller.logger = logger
config.action_mailer.logger = logger
+ config.active_job.logger = logger
config.active_record.logger = logger
config.cache_store = :memory_store
end