forest_liana 9.15.6 → 9.15.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34a394e776ab9ef99fe30e7e367e834f84e5e0fdf0a2314aaa76ec368dc7f0a3
4
- data.tar.gz: 619adc9e67f4d7a9182be43a383a688a7782de23718a3c2e1640cf361386b61d
3
+ metadata.gz: 196dd946e590abc0f8d08471986655e8bd3244638cb278e91fd9e13ae446dcf4
4
+ data.tar.gz: 6fc5262c9b202656e03f6f490d0c25776cee50c5af1743705667f06aee69d205
5
5
  SHA512:
6
- metadata.gz: b56de9223cf035c62a35bd1cebf6a8390ce0887d11818940a8f945ca90295c0d4ad7d7d63e6991378c224f2f3c549ab011e0127cf41b8e2e99a83c9eabf8d559
7
- data.tar.gz: db9cf2fa2a26ac1f1d084ffab1046b7cb9d22d1cc4bc4bf36e5dc196ca58792102a2e1d636117d96f50da32f303b4ac57074dd0bf23f8397ccb74523aea97e81
6
+ metadata.gz: 72a7ce8cca5d0e3d0e3829a5db69120d30c1c99e6ce09a766a00bb9816b52e071c4ed2c8a57879d0ce2e09213bc24b32ee782cd382ec4328af2131baa5b30167
7
+ data.tar.gz: d78f92c535f06d035ea1eb896621dfc8cb0c9f77001f252b84f594c8f5c58215b57a7bdb7cac5f339f7e7f7612baf506ef94e6a983bcec8f7cd849cedde6072b
@@ -188,7 +188,11 @@ module ForestLiana
188
188
  else
189
189
  smart_relations.each do |smart_relation|
190
190
  if smart_relation[:field].to_s == relation_name
191
- fields[relation_name] = relation_fields
191
+ if smart_relation[:reference].split('.').first == params[:collection]
192
+ fields[relation_name] = relation_fields
193
+ else
194
+ fields[smart_relation[:reference].split('.').first] = relation_fields
195
+ end
192
196
  end
193
197
  end
194
198
  end
@@ -60,28 +60,20 @@ module ForestLiana
60
60
  unformatted_attr_name = serializer.unformat_name(attribute_name).to_sym
61
61
  object = nil
62
62
  is_collection = false
63
- is_valid_attr = false
64
63
  if serializer.has_one_relationships.has_key?(unformatted_attr_name)
65
64
  # only added this condition
66
65
  if root_object.class.reflect_on_association(unformatted_attr_name)&.polymorphic?
67
66
  options[:context][:unoptimized] = true
68
67
  end
69
68
 
70
- is_valid_attr = true
71
69
  attr_data = serializer.has_one_relationships[unformatted_attr_name]
72
70
  object = serializer.has_one_relationship(unformatted_attr_name, attr_data)
73
71
  elsif serializer.has_many_relationships.has_key?(unformatted_attr_name)
74
- is_valid_attr = true
75
72
  is_collection = true
76
73
  attr_data = serializer.has_many_relationships[unformatted_attr_name]
77
74
  object = serializer.has_many_relationship(unformatted_attr_name, attr_data)
78
75
  end
79
76
 
80
- if !is_valid_attr
81
- raise ForestAdmin::JSONAPI::Serializer::InvalidIncludeError.new(
82
- "'#{attribute_name}' is not a valid include.")
83
- end
84
-
85
77
  if attribute_name != serializer.format_name(attribute_name)
86
78
  expected_name = serializer.format_name(attribute_name)
87
79
 
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "9.15.6"
2
+ VERSION = "9.15.8"
3
3
  end
@@ -606,4 +606,93 @@ describe 'Requesting Actions routes', :type => :request do
606
606
  controller.send(:serialize_models, records, options)
607
607
  end
608
608
  end
609
+
610
+ describe 'fields_per_model method' do
611
+ let(:model) { Island }
612
+ let(:collection_name) { 'Island' }
613
+
614
+ before do
615
+ forest_collection = double('forest_collection')
616
+ allow(ForestLiana).to receive(:apimap).and_return([forest_collection])
617
+ allow(forest_collection).to receive(:name).and_return(collection_name)
618
+ end
619
+
620
+ context 'with smart relations pointing to external models' do
621
+ it 'should use reference model name as key for external smart relations' do
622
+ smart_relations = [
623
+ {
624
+ field: :organization,
625
+ reference: 'Api__OrganizationsView.id',
626
+ is_virtual: true,
627
+ is_searchable: false,
628
+ type: 'String'
629
+ }
630
+ ]
631
+
632
+ forest_collection = double('forest_collection')
633
+ allow(forest_collection).to receive(:name).and_return(collection_name)
634
+ allow(forest_collection).to receive(:fields_smart_belongs_to).and_return(smart_relations)
635
+ allow(ForestLiana).to receive(:apimap).and_return([forest_collection])
636
+
637
+ params_fields = ActionController::Parameters.new({
638
+ 'organization' => 'name'
639
+ })
640
+
641
+ mock_params = ActionController::Parameters.new({
642
+ collection: 'Island',
643
+ fields: { 'Island' => 'id,name', 'organization' => 'name'},
644
+ page: { 'number' => '1', 'size' => '10' },
645
+ searchExtended: '0',
646
+ sort: '-id',
647
+ timezone: 'Europe/Paris'
648
+ })
649
+ allow(controller).to receive(:params).and_return(mock_params)
650
+
651
+ result = controller.send(:fields_per_model, params_fields, model)
652
+
653
+ expect(result).to have_key('Api__OrganizationsView')
654
+ expect(result['Api__OrganizationsView']).to eq('name')
655
+ expect(result).not_to have_key('organization')
656
+ end
657
+ end
658
+
659
+ context 'with smart relations pointing to same collection (self-reference)' do
660
+ it 'should use relation name as key for self-referencing smart relations' do
661
+ smart_relations = [
662
+ {
663
+ field: :parent_island,
664
+ reference: 'Island.id',
665
+ is_virtual: true,
666
+ is_searchable: false,
667
+ type: 'String'
668
+ }
669
+ ]
670
+
671
+ forest_collection = double('forest_collection')
672
+ allow(forest_collection).to receive(:name).and_return(collection_name)
673
+ allow(forest_collection).to receive(:fields_smart_belongs_to).and_return(smart_relations)
674
+ allow(ForestLiana).to receive(:apimap).and_return([forest_collection])
675
+
676
+ params_fields = ActionController::Parameters.new({
677
+ 'parent_island' => 'name'
678
+ })
679
+
680
+ mock_params = ActionController::Parameters.new({
681
+ collection: 'Island',
682
+ fields: { 'Island' => 'id,name', 'parent_island' => 'name'},
683
+ page: { 'number' => '1', 'size' => '10' },
684
+ searchExtended: '0',
685
+ sort: '-id',
686
+ timezone: 'Europe/Paris'
687
+ })
688
+ allow(controller).to receive(:params).and_return(mock_params)
689
+
690
+ result = controller.send(:fields_per_model, params_fields, model)
691
+
692
+ expect(result).to have_key('parent_island')
693
+ expect(result['parent_island']).to eq('name')
694
+ expect(result).not_to have_key('Island')
695
+ end
696
+ end
697
+ end
609
698
  end
@@ -167,6 +167,52 @@ describe 'Requesting Tree resources', :type => :request do
167
167
  end
168
168
  end
169
169
  end
170
+
171
+ describe 'csv' do
172
+ it 'should return CSV with correct headers and data' do
173
+ params = {
174
+ fields: { 'Tree' => 'id,name,owner', 'owner' => 'name'},
175
+ page: { 'number' => '1', 'size' => '10' },
176
+ searchExtended: '0',
177
+ sort: '-id',
178
+ timezone: 'Europe/Paris',
179
+ header: 'id,name,owner',
180
+ }
181
+ get '/forest/Tree.csv', params: params, headers: headers
182
+
183
+ expect(response.status).to eq(200)
184
+ expect(response.headers['Content-Type']).to include('text/csv')
185
+ expect(response.headers['Content-Disposition']).to include('attachment')
186
+
187
+ csv_content = response.body
188
+ csv_lines = csv_content.split("\n")
189
+
190
+ expect(csv_lines.first).to eq(params[:header])
191
+ expect(csv_lines[1]).to eq('1,Lemon Tree,Michel')
192
+ end
193
+
194
+ it 'returns CSV with only requested fields and ignores optional relation' do
195
+ params = {
196
+ fields: { 'Tree' => 'id,name', 'owner' => 'name'},
197
+ page: { 'number' => '1', 'size' => '10' },
198
+ searchExtended: '0',
199
+ sort: '-id',
200
+ timezone: 'Europe/Paris',
201
+ header: 'id,name',
202
+ }
203
+ get '/forest/Tree.csv', params: params, headers: headers
204
+
205
+ expect(response.status).to eq(200)
206
+ expect(response.headers['Content-Type']).to include('text/csv')
207
+ expect(response.headers['Content-Disposition']).to include('attachment')
208
+
209
+ csv_content = response.body
210
+ csv_lines = csv_content.split("\n")
211
+
212
+ expect(csv_lines.first).to eq(params[:header])
213
+ expect(csv_lines[1]).to eq('1,Lemon Tree')
214
+ end
215
+ end
170
216
  end
171
217
 
172
218
  describe 'Requesting User resources', :type => :request do
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.15.6
4
+ version: 9.15.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-27 00:00:00.000000000 Z
11
+ date: 2025-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails