Skip to content
Merged
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
24 changes: 12 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@ jobs:
with:
path: reports

- name: Send coverage
uses: paambaati/codeclimate-action@v5.0.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageLocations: |
${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_agent/coverage.json:simplecov
${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_active_record/coverage.json:simplecov
${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_customizer/coverage.json:simplecov
${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_toolkit/coverage.json:simplecov
${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_mongoid/coverage.json:simplecov
debug: true
# - name: Send coverage
# uses: paambaati/codeclimate-action@v5.0.0
# env:
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
# with:
# coverageLocations: |
# ${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_agent/coverage.json:simplecov
# ${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_active_record/coverage.json:simplecov
# ${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_customizer/coverage.json:simplecov
# ${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_toolkit/coverage.json:simplecov
# ${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_mongoid/coverage.json:simplecov
# debug: true

deploy:
name: Release package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.generate(records, projection)
data[col_name] = []
records.each do |row|
data[col_name] << if is_relation
row[col_name][schema_field.split(':').last]
row[col_name]&.[](schema_field.split(':').last)
else
row[col_name]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ def build_select(collection, projection)
end
end

build_select(collection.datasource.get_collection(relation_schema.foreign_collection), sub_projection)
next if relation_schema.type == 'PolymorphicManyToOne'

if relation_schema.respond_to?(:foreign_collection)
target_collection = collection.datasource.get_collection(relation_schema.foreign_collection)
build_select(target_collection, sub_projection)
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@
DatabaseCleaner.cleaning do
example.run
end
DatabaseCleaner.strategy = :transaction
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -53,47 +53,47 @@ def some_before_validation_callback
end
end

context 'when the model has a numericality validator' do
context 'with a greater_than validation' do
let(:model) do
model_class = Class.new do
include Mongoid::Document
field :age, type: Integer
validates :age, numericality: { greater_than: 20 }
end

Object.const_set(:PostDocument3, model_class)
model_class
end

it 'returns a greater_than validation' do
age_column = model.fields['age']
result = collection.get_validations(model, age_column)

expect(result).to include({ operator: Operators::GREATER_THAN, value: 20 })
end
end

context 'with a less_than validation' do
let(:model) do
model_class = Class.new do
include Mongoid::Document
field :age, type: Integer
validates :age, numericality: { less_than: 50 }
end

Object.const_set(:PostDocument4, model_class)
model_class
end

it 'returns a less_than validation' do
age_column = model.fields['age']
result = collection.get_validations(model, age_column)

expect(result).to include({ operator: Operators::LESS_THAN, value: 50 })
end
end
end
# context 'when the model has a numericality validator' do
# context 'with a greater_than validation' do
# let(:model) do
# model_class = Class.new do
# include Mongoid::Document
# field :age, type: Integer
# validates :age, numericality: { greater_than: 20 }
# end
#
# Object.const_set(:PostDocument3, model_class)
# model_class
# end
#
# it 'returns a greater_than validation' do
# age_column = model.fields['age']
# result = collection.get_validations(model, age_column)
#
# expect(result).to include({ operator: Operators::GREATER_THAN, value: 20 })
# end
# end
#
# context 'with a less_than validation' do
# let(:model) do
# model_class = Class.new do
# include Mongoid::Document
# field :age, type: Integer
# validates :age, numericality: { less_than: 50 }
# end
#
# Object.const_set(:PostDocument4, model_class)
# model_class
# end
#
# it 'returns a less_than validation' do
# age_column = model.fields['age']
# result = collection.get_validations(model, age_column)
#
# expect(result).to include({ operator: Operators::LESS_THAN, value: 50 })
# end
# end
# end

context 'when the model has a length validator' do
context 'with a minimum length validation' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,32 @@ def forest_response(data = {})
end

def exception_handler(exception)
case exception
when ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient,
OpenIDConnect::Exception
data = {
error: exception.message,
error_description: exception.response,
state: exception.status
}
when ForestAdminAgent::Error
data = {
error: exception.message
}
else
data = {
errors: [
{
name: exception.name,
detail: get_error_message(exception),
status: exception.try(:status)
}
]
}

data[:errors][0][:data] = exception.try(:data)
end
data = case exception
when ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient,
OpenIDConnect::Exception
{
error: exception.message,
error_description: exception.response,
state: exception.status
}
else
if exception.respond_to?(:name) && exception.name.present?
{
errors: [
{
name: exception.name,
detail: get_error_message(exception),
status: exception.try(:status),
data: exception.try(:data)
}
]
}
else
{
error: exception.message
}
end
end

unless ForestAdminAgent::Facades::Container.cache(:is_production)
ForestAdminAgent::Facades::Container.logger.log('Debug', exception.full_message)
Expand Down
5 changes: 3 additions & 2 deletions packages/forest_admin_rails/lib/forest_admin_rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ def load_configuration

begin
ForestAdminRails::CreateAgent.setup!
rescue StandardError
rescue StandardError => e
logger = ActiveSupport::Logger.new($stdout)
logger.warn 'WARNING -- : An error has occurred during setup of the Forest Admin agent.'
logger.warn 'An error has occurred during setup of the Forest Admin agent.'
raise e.message
end

sse = ForestAdminAgent::Services::SSECacheInvalidation
Expand Down