Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/fastapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
require 'fastapi/utilities'

module FastAPI

def self.logger
@@logger ||= ActiveSupport::Logger.new(STDERR)
end

Oj.default_options = { mode: :compat }

class Wrapper
Expand Down Expand Up @@ -188,9 +193,12 @@ def fastapi_query(filters = {}, safe = false)
parsed_filters = parse_filters(filters, safe)
prepared_data = FastAPI::SQL.new(parsed_filters, offset, count, @model, @whitelist_fields)
rescue StandardError => exception
FastAPI.logger.error("FastAPI -- Error Creating SQL:\n\t#{exception.message}")
return error(offset, exception.message)
end

FastAPI.logger.debug("FastAPI -- SQL:\n\t#{prepared_data[:query]}")

model_lookup = prepared_data[:models].each_with_object({}) do |(key, model), lookup|
columns = model.columns_hash
lookup[key] = {
Expand All @@ -204,6 +212,7 @@ def fastapi_query(filters = {}, safe = false)
count_result = ActiveRecord::Base.connection.execute(prepared_data[:count_query])
result = ActiveRecord::Base.connection.execute(prepared_data[:query])
rescue StandardError
FastAPI.logger.error("FastAPI -- Error Executing Query:\n\t#{prepared_data[:query]}")
return error(offset, 'Query failed')
end

Expand Down
8 changes: 8 additions & 0 deletions spec/bucket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
let!(:bucket) { create(:blue_paper_bucket) }
let(:response) { ModelHelper.response(Bucket, { id: 1 }, safe: true) }

before(:all) do
FastAPI.logger.level = ActiveSupport::Logger::FATAL
end

after(:all) do
FastAPI.logger.level = ActiveSupport::Logger::INFO
end

it_behaves_like 'fastapi_meta' do
let(:expected) { { total: 0, count: 0, offset: 0, error: /Filter "id" not supported/ } }
end
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)

FastAPI.logger.level = ActiveSupport::Logger::INFO
end

config.around(:each) do |example|
Expand Down