forest_liana 9.5.7 → 9.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef02f4f1dde4cd777a5716344e1ffe08328870746e34cd4b61fe0494462765f8
4
- data.tar.gz: f00356a4fd733f3d08cd317e0f1a74e81ff936c71b6263da013f2f9528e3a5e4
3
+ metadata.gz: 4ba2b1f8d8557f9d5627817377b70bb733804ab8cba4f8f5c63868261f9e00ad
4
+ data.tar.gz: 8d493de4d0148d02e826338b6bb2287c1015094333dfe9891de39be17cc7de8b
5
5
  SHA512:
6
- metadata.gz: c7b5c5c600644678f25cac77cbef4ec5e410a1d324638abf00f897f9c9b1f4683ae1f94f9b11a9a643a803881f9160ebc2b6fdad72cab124a3a09a4e38d06475
7
- data.tar.gz: 1c20cb1fb9457418ef6aa7d91bb68d842a9d311b484c95be108b6a1b848b74a022e8370cfa3c56685cdae91c550c6ebbbb5031b2a11e357461addd34d66e705c
6
+ metadata.gz: 1e136b9bfe6ba3bb94a5c525f04c6db27a88989fa8b2bff0b2a4341266b8ae901c5cac8c53111d4d0e1b443a9b4dfffdb5954f40a72ac31d1a62ff89a8f2a83b
7
+ data.tar.gz: a8e80f6812a1146af8f3faaa5c20733d3cb731f9a0cd79e63bf93118daa1daadb4e6e5e18d5ae6c54d8f09c4bb567b953af474e63b29ffac365c89424c8fcc92
@@ -127,8 +127,8 @@ module ForestLiana
127
127
  ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/relationships/#{attribute_name}"
128
128
  end
129
129
  end
130
- rescue TypeError, ActiveRecord::StatementInvalid, NoMethodError
131
- puts "Cannot load the association #{attribute_name} on #{object.class.name} #{object.id}."
130
+ rescue TypeError, ActiveRecord::StatementInvalid, NoMethodError => exception
131
+ FOREST_LOGGER.warn "Cannot load the association #{attribute_name} on #{object.class.name} #{object.id}.\n#{exception&.backtrace&.join("\n\t")}"
132
132
  end
133
133
  end
134
134
 
@@ -2,12 +2,13 @@ module ForestLiana
2
2
  module Ability
3
3
  module Exceptions
4
4
  class AccessDenied < ForestLiana::Errors::ExpectedError
5
- def initialize
5
+ def initialize (backtrace = nil)
6
6
  super(
7
7
  403,
8
8
  :forbidden,
9
9
  'You don\'t have permission to access this resource',
10
- 'AccessDenied'
10
+ 'AccessDenied',
11
+ backtrace
11
12
  )
12
13
  end
13
14
  end
@@ -2,12 +2,13 @@ module ForestLiana
2
2
  module Ability
3
3
  module Exceptions
4
4
  class ActionConditionError < ForestLiana::Errors::ExpectedError
5
- def initialize
5
+ def initialize (backtrace = nil)
6
6
  super(
7
7
  409,
8
8
  :conflict,
9
9
  'The conditions to trigger this action cannot be verified. Please contact an administrator.',
10
- 'InvalidActionConditionError'
10
+ 'InvalidActionConditionError',
11
+ backtrace
11
12
  )
12
13
  end
13
14
  end
@@ -3,13 +3,14 @@ module ForestLiana
3
3
  module Exceptions
4
4
  class RequireApproval < ForestLiana::Errors::ExpectedError
5
5
  attr_reader :data
6
- def initialize(data)
6
+ def initialize(data, backtrace = nil)
7
7
  @data = data
8
8
  super(
9
9
  403,
10
10
  :forbidden,
11
11
  'This action requires to be approved.',
12
12
  'CustomActionRequiresApprovalError',
13
+ backtrace,
13
14
  )
14
15
  end
15
16
  end
@@ -2,12 +2,13 @@ module ForestLiana
2
2
  module Ability
3
3
  module Exceptions
4
4
  class TriggerForbidden < ForestLiana::Errors::ExpectedError
5
- def initialize
5
+ def initialize(backtrace = nil)
6
6
  super(
7
7
  403,
8
8
  :forbidden,
9
9
  'You don\'t have the permission to trigger this action',
10
- 'CustomActionTriggerForbiddenError'
10
+ 'CustomActionTriggerForbiddenError',
11
+ backtrace,
11
12
  )
12
13
  end
13
14
  end
@@ -2,12 +2,13 @@ module ForestLiana
2
2
  module Ability
3
3
  module Exceptions
4
4
  class UnknownCollection < ForestLiana::Errors::ExpectedError
5
- def initialize(collection_name)
5
+ def initialize(collection_name, backtrace = nil)
6
6
  super(
7
7
  409,
8
8
  :conflict,
9
9
  "The collection #{collection_name} doesn't exist",
10
- 'collection not found'
10
+ 'collection not found',
11
+ backtrace
11
12
  )
12
13
  end
13
14
  end
@@ -65,8 +65,8 @@ module ForestLiana
65
65
  end
66
66
 
67
67
  records.select(@collection.table_name + '.id').count == attributes[:ids].count
68
- rescue
69
- raise ForestLiana::Ability::Exceptions::ActionConditionError.new
68
+ rescue => exception
69
+ raise ForestLiana::Ability::Exceptions::ActionConditionError.new(exception.backtrace)
70
70
  end
71
71
  end
72
72
 
@@ -27,8 +27,8 @@ module ForestLiana
27
27
  is_allowed
28
28
  rescue ForestLiana::Errors::ExpectedError => exception
29
29
  raise exception
30
- rescue
31
- raise ForestLiana::Ability::Exceptions::UnknownCollection.new(collection_name)
30
+ rescue => exception
31
+ raise ForestLiana::Ability::Exceptions::UnknownCollection.new(collection_name, exception.backtrace)
32
32
  end
33
33
  end
34
34
 
@@ -45,8 +45,8 @@ module ForestLiana
45
45
  smart_action_approval.can_execute?
46
46
  rescue ForestLiana::Errors::ExpectedError => exception
47
47
  raise exception
48
- rescue
49
- raise ForestLiana::Ability::Exceptions::UnknownCollection.new(collection_name)
48
+ rescue => exception
49
+ raise ForestLiana::Ability::Exceptions::UnknownCollection.new(collection_name, exception.backtrace)
50
50
  end
51
51
  end
52
52
 
@@ -10,7 +10,10 @@ module ForestLiana
10
10
  query: query,
11
11
  }).response
12
12
  rescue
13
- raise "Cannot reach Forest API at #{forest_api_url}#{route}, it seems to be down right now."
13
+ message = "Cannot reach Forest API at #{forest_api_url}#{route}, it seems to be down right now."
14
+ FOREST_LOGGER.error message
15
+ FOREST_REPORTER.report message
16
+ raise
14
17
  end
15
18
  end
16
19
 
@@ -29,7 +32,10 @@ module ForestLiana
29
32
  body: body.to_json,
30
33
  }).response
31
34
  rescue
32
- raise "Cannot reach Forest API at #{post_route}, it seems to be down right now."
35
+ message = "Cannot reach Forest API at #{post_route}, it seems to be down right now."
36
+ FOREST_LOGGER.error message
37
+ FOREST_REPORTER.report message
38
+ raise
33
39
  end
34
40
  end
35
41
 
@@ -44,11 +44,13 @@ module ForestLiana
44
44
  class ExpectedError < StandardError
45
45
  attr_reader :error_code, :status, :message, :name
46
46
 
47
- def initialize(error_code, status, message, name = nil)
47
+ def initialize(error_code, status, message, name = nil, backtrace = nil)
48
48
  @error_code = error_code
49
49
  @status = status
50
50
  @message = message
51
51
  @name = name
52
+
53
+ set_backtrace(backtrace) unless backtrace.nil?
52
54
  end
53
55
 
54
56
  def display_error
@@ -80,8 +80,16 @@ module ForestLiana::Collection
80
80
 
81
81
  field = opts.merge({
82
82
  field: name,
83
- is_filterable: !!opts[:is_filterable],
84
- is_sortable: !!opts[:is_sortable],
83
+ is_filterable: if opts.has_key?(:is_filterable)
84
+ !!opts[:is_filterable]
85
+ else
86
+ !!opts[:polymorphic_key]
87
+ end,
88
+ is_sortable: if opts.has_key?(:is_sortable)
89
+ !!opts[:is_sortable]
90
+ else
91
+ !!opts[:polymorphic_key]
92
+ end
85
93
  })
86
94
 
87
95
  add_field(field)
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "9.5.7"
2
+ VERSION = "9.6.3"
3
3
  end
@@ -0,0 +1,34 @@
1
+ module ForestLiana
2
+ describe Errors do
3
+ describe 'ExpectedError' do
4
+ describe 'when initializing' do
5
+ describe 'when backtrace is added' do
6
+ it 'should add the backtrace to the errors if passed' do
7
+ err = nil
8
+
9
+ begin
10
+ raise "This is an exception"
11
+ rescue => error
12
+ err = ForestLiana::Errors::ExpectedError.new(300, 300, error.message, nil, error.backtrace )
13
+ end
14
+
15
+ expect(err.backtrace).to be_truthy
16
+ end
17
+ end
18
+ describe 'when backtrace is not added' do
19
+ it 'should not break nor add any backtrace' do
20
+ err = nil
21
+
22
+ begin
23
+ raise "This is an exception"
24
+ rescue => error
25
+ err = ForestLiana::Errors::ExpectedError.new(300, 300, error.message, nil)
26
+ end
27
+
28
+ expect(err.backtrace).to be_falsy
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ class Forest::Address
2
+ include ForestLiana::Collection
3
+
4
+ collection :Address
5
+
6
+ field :addressable_type, type: 'String', polymorphic_key: true, is_filterable: false do
7
+ object.addressable_type
8
+ end
9
+
10
+ field :addressable_id, type: 'String', polymorphic_key: true do
11
+ object.addressable_type
12
+ end
13
+
14
+ field :address_type, type: 'String' do
15
+ 'delivery'
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ module ForestLiana
2
+ describe Collection do
3
+ before do
4
+ allow(ForestLiana).to receive(:env_secret).and_return(nil)
5
+ end
6
+
7
+ let(:collection) { ForestLiana.apimap.select { |collection| collection.name == 'Address' }.first }
8
+
9
+ describe 'field' do
10
+ it 'add simple smart field' do
11
+ field = collection.fields.select { |field| field[:field] == :address_type }.first
12
+
13
+ expect(field).not_to be_nil
14
+ expect(field).to eq(
15
+ {
16
+ type: "String",
17
+ is_read_only: true,
18
+ is_required: false,
19
+ default_value: nil,
20
+ integration: nil,
21
+ reference: nil,
22
+ inverse_of: nil,
23
+ relationships: nil,
24
+ widget: nil,
25
+ validations: [],
26
+ is_virtual: true,
27
+ field: :address_type,
28
+ is_filterable: false,
29
+ is_sortable: false
30
+ }
31
+ )
32
+ end
33
+
34
+ it 'add polymorphic smart field with default values' do
35
+ field = collection.fields.select { |field| field[:field] == :addressable_id }.first
36
+
37
+ expect(field).not_to be_nil
38
+ expect(field[:is_filterable]).to eq(true)
39
+ expect(field[:is_sortable]).to eq(true)
40
+ end
41
+
42
+ it 'add polymorphic smart field with is_filterable option set to false' do
43
+ field = collection.fields.select { |field| field[:field] == :addressable_type }.first
44
+
45
+ expect(field).not_to be_nil
46
+ expect(field[:is_filterable]).to eq(false)
47
+ expect(field[:is_sortable]).to eq(true)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ module ForestLiana
2
+ describe ForestApiRequester do
3
+ describe 'when an error occurs' do
4
+ before do
5
+ allow(HTTParty).to receive(:get).and_raise(StandardError, 'Custom error message')
6
+ allow(HTTParty).to receive(:post).and_raise(StandardError, 'Custom error message')
7
+ end
8
+
9
+ describe 'Get' do
10
+ it 'should keep the original error and raise it with backtrace' do
11
+ err = nil
12
+
13
+ begin
14
+ ForestApiRequester.get('/incorrect_url')
15
+ rescue => error
16
+ err = error
17
+ end
18
+
19
+ expect(error)
20
+ .to be_instance_of(StandardError)
21
+ .and have_attributes(:message => 'Custom error message')
22
+ .and have_attributes(:backtrace => be_truthy)
23
+ end
24
+ end
25
+
26
+ describe 'Post' do
27
+ it 'should keep the original error and raise it with backtrace' do
28
+ err = nil
29
+
30
+ begin
31
+ ForestApiRequester.post('/incorrect_url')
32
+ rescue => error
33
+ err = error
34
+ end
35
+
36
+ expect(error)
37
+ .to be_instance_of(StandardError)
38
+ .and have_attributes(:message => 'Custom error message')
39
+ .and have_attributes(:backtrace => be_truthy)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.5.7
4
+ version: 9.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-10 00:00:00.000000000 Z
11
+ date: 2024-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -329,6 +329,7 @@ files:
329
329
  - lib/tasks/clear_oidc_data.rake
330
330
  - lib/tasks/display_apimap.rake
331
331
  - lib/tasks/send_apimap.rake
332
+ - spec/config/initializers/errors_spec.rb
332
333
  - spec/config/initializers/logger_spec.rb
333
334
  - spec/dummy/README.rdoc
334
335
  - spec/dummy/Rakefile
@@ -395,6 +396,7 @@ files:
395
396
  - spec/dummy/db/migrate/20220727114930_add_columns_to_products.rb
396
397
  - spec/dummy/db/migrate/20231117084236_create_addresses.rb
397
398
  - spec/dummy/db/schema.rb
399
+ - spec/dummy/lib/forest_liana/collections/address.rb
398
400
  - spec/dummy/lib/forest_liana/collections/island.rb
399
401
  - spec/dummy/lib/forest_liana/collections/location.rb
400
402
  - spec/dummy/lib/forest_liana/collections/user.rb
@@ -403,6 +405,7 @@ files:
403
405
  - spec/helpers/forest_liana/query_helper_spec.rb
404
406
  - spec/helpers/forest_liana/schema_helper_spec.rb
405
407
  - spec/lib/forest_liana/bootstrapper_spec.rb
408
+ - spec/lib/forest_liana/collection_spec.rb
406
409
  - spec/lib/forest_liana/schema_file_updater_spec.rb
407
410
  - spec/rails_helper.rb
408
411
  - spec/requests/actions_controller_spec.rb
@@ -418,6 +421,7 @@ files:
418
421
  - spec/services/forest_liana/ability/permission_spec.rb
419
422
  - spec/services/forest_liana/apimap_sorter_spec.rb
420
423
  - spec/services/forest_liana/filters_parser_spec.rb
424
+ - spec/services/forest_liana/forest_api_requester_spec.rb
421
425
  - spec/services/forest_liana/has_many_getter_spec.rb
422
426
  - spec/services/forest_liana/ip_whitelist_checker_spec.rb
423
427
  - spec/services/forest_liana/line_stat_getter_spec.rb
@@ -630,6 +634,7 @@ test_files:
630
634
  - test/services/forest_liana/operator_date_interval_parser_test.rb
631
635
  - test/services/forest_liana/schema_adapter_test.rb
632
636
  - test/test_helper.rb
637
+ - spec/config/initializers/errors_spec.rb
633
638
  - spec/config/initializers/logger_spec.rb
634
639
  - spec/dummy/README.rdoc
635
640
  - spec/dummy/Rakefile
@@ -696,6 +701,7 @@ test_files:
696
701
  - spec/dummy/db/migrate/20220727114930_add_columns_to_products.rb
697
702
  - spec/dummy/db/migrate/20231117084236_create_addresses.rb
698
703
  - spec/dummy/db/schema.rb
704
+ - spec/dummy/lib/forest_liana/collections/address.rb
699
705
  - spec/dummy/lib/forest_liana/collections/island.rb
700
706
  - spec/dummy/lib/forest_liana/collections/location.rb
701
707
  - spec/dummy/lib/forest_liana/collections/user.rb
@@ -704,6 +710,7 @@ test_files:
704
710
  - spec/helpers/forest_liana/query_helper_spec.rb
705
711
  - spec/helpers/forest_liana/schema_helper_spec.rb
706
712
  - spec/lib/forest_liana/bootstrapper_spec.rb
713
+ - spec/lib/forest_liana/collection_spec.rb
707
714
  - spec/lib/forest_liana/schema_file_updater_spec.rb
708
715
  - spec/rails_helper.rb
709
716
  - spec/requests/actions_controller_spec.rb
@@ -719,6 +726,7 @@ test_files:
719
726
  - spec/services/forest_liana/ability/permission_spec.rb
720
727
  - spec/services/forest_liana/apimap_sorter_spec.rb
721
728
  - spec/services/forest_liana/filters_parser_spec.rb
729
+ - spec/services/forest_liana/forest_api_requester_spec.rb
722
730
  - spec/services/forest_liana/has_many_getter_spec.rb
723
731
  - spec/services/forest_liana/ip_whitelist_checker_spec.rb
724
732
  - spec/services/forest_liana/line_stat_getter_spec.rb