forest_liana 9.15.0 → 9.15.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c700fa60cbdb6da1e131e2e041d7bec408052bf6ce50304e51f2e6f6525e8d8
|
4
|
+
data.tar.gz: fdc53e76cf29afabdd6b18ec6a3279bd0e9bec3b467e8f8b16cb6cbb7dda87aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe65c60f75a320f96e826dc7b93e25106d0958c62f1157212496ba57eef33e9be08776ab104200b2eb9d7e772fc1f2cae58f811f2033d57e2969e877cf3dbc64
|
7
|
+
data.tar.gz: bf3c7eb151213fb126ef896d040369c2a3c65500e8e2ecbd292c06cbb016939fc607e295db9fc719b09e428c52ad7f4462bee211f7f532794be0d4895ef2d50d
|
@@ -168,7 +168,7 @@ module ForestLiana
|
|
168
168
|
@includes = (includes & @field_names_requested).concat(includes_for_smart_search)
|
169
169
|
else
|
170
170
|
@includes = associations_has_one
|
171
|
-
|
171
|
+
# Avoid eager loading has_one associations pointing to a different database as ORM can't join cross databases
|
172
172
|
.reject { |association| separate_database?(@resource, association) }
|
173
173
|
.map(&:name)
|
174
174
|
end
|
@@ -198,15 +198,29 @@ module ForestLiana
|
|
198
198
|
|
199
199
|
def extract_associations_from_filter
|
200
200
|
associations = []
|
201
|
-
|
202
|
-
|
201
|
+
|
202
|
+
filters = @params[:filters]
|
203
|
+
filters = JSON.parse(filters) if filters.is_a?(String)
|
204
|
+
|
205
|
+
conditions = []
|
206
|
+
|
207
|
+
if filters.is_a?(Hash) && filters.key?('conditions')
|
208
|
+
conditions = filters['conditions']
|
209
|
+
elsif filters.is_a?(Hash) && filters.key?('field')
|
210
|
+
conditions = [filters]
|
211
|
+
end
|
212
|
+
|
213
|
+
conditions.each do |condition|
|
214
|
+
field = condition['field']
|
215
|
+
if field&.include?(':')
|
203
216
|
associations << field.split(':').first.to_sym
|
204
217
|
@count_needs_includes = true
|
205
218
|
end
|
206
219
|
end
|
220
|
+
|
207
221
|
@count_needs_includes = true if @params[:search]
|
208
222
|
|
209
|
-
associations
|
223
|
+
associations.uniq
|
210
224
|
end
|
211
225
|
|
212
226
|
def prepare_query
|
@@ -352,8 +366,8 @@ module ForestLiana
|
|
352
366
|
|
353
367
|
def get_one_association(name)
|
354
368
|
ForestLiana::QueryHelper.get_one_associations(@resource)
|
355
|
-
|
356
|
-
|
369
|
+
.select { |association| association.name == name.to_sym }
|
370
|
+
.first
|
357
371
|
end
|
358
372
|
end
|
359
373
|
end
|
data/lib/forest_liana/version.rb
CHANGED
@@ -38,7 +38,7 @@ module ForestLiana
|
|
38
38
|
clean_database
|
39
39
|
|
40
40
|
users = ['Michel', 'Robert', 'Vince', 'Sandro', 'Olesya', 'Romain', 'Valentin', 'Jason', 'Arnaud', 'Jeff', 'Steve', 'Marc', 'Xavier', 'Paul', 'Mickael', 'Mike', 'Maxime', 'Gertrude', 'Monique', 'Mia', 'Rachid', 'Edouard', 'Sacha', 'Caro', 'Amand', 'Nathan', 'Noémie', 'Robin', 'Gaelle', 'Isabelle']
|
41
|
-
|
41
|
+
.map { |name| User.create(name: name) }
|
42
42
|
|
43
43
|
islands = [
|
44
44
|
{ :name => 'Skull', :updated_at => Time.now - 1.years },
|
@@ -309,18 +309,18 @@ module ForestLiana
|
|
309
309
|
describe 'when filtering on an ambiguous field' do
|
310
310
|
let(:resource) { Tree }
|
311
311
|
let(:pageSize) { 5 }
|
312
|
-
let(:fields) { { 'Tree' => 'id' } }
|
312
|
+
let(:fields) { { 'Tree' => 'id,name', 'cutter' => 'id' } }
|
313
313
|
let(:filters) { {
|
314
314
|
aggregator: 'and',
|
315
315
|
conditions: [{
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
316
|
+
field: 'created_at',
|
317
|
+
operator: 'after',
|
318
|
+
value: "#{Time.now - 6.year}",
|
319
|
+
}, {
|
320
|
+
field: 'cutter:name',
|
321
|
+
operator: 'equal',
|
322
|
+
value: 'Michel'
|
323
|
+
}]
|
324
324
|
}.to_json }
|
325
325
|
|
326
326
|
it 'should get only the expected records' do
|
@@ -332,7 +332,6 @@ module ForestLiana
|
|
332
332
|
expect(count).to eq 1
|
333
333
|
expect(records.first.id).to eq 3
|
334
334
|
expect(records.first.name).to eq 'Apple Tree'
|
335
|
-
expect(records.first.cutter.name).to eq 'Michel'
|
336
335
|
end
|
337
336
|
end
|
338
337
|
|
@@ -379,7 +378,7 @@ module ForestLiana
|
|
379
378
|
describe 'when sorting on an ambiguous field name with a filter' do
|
380
379
|
let(:resource) { Tree }
|
381
380
|
let(:sort) { '-name' }
|
382
|
-
let(:fields) { { 'Tree' => 'id' } }
|
381
|
+
let(:fields) { { 'Tree' => 'id,name' } }
|
383
382
|
let(:filters) { {
|
384
383
|
field: 'cutter:name',
|
385
384
|
operator: 'equal',
|
@@ -417,7 +416,7 @@ module ForestLiana
|
|
417
416
|
|
418
417
|
describe 'when filtering on an updated_at field of an associated collection' do
|
419
418
|
let(:resource) { Tree }
|
420
|
-
let(:fields) { { 'Tree' => 'id' } }
|
419
|
+
let(:fields) { { 'Tree' => 'id,name' } }
|
421
420
|
let(:filters) { {
|
422
421
|
field: 'island:updated_at',
|
423
422
|
operator: 'previous_year'
|
@@ -510,9 +509,9 @@ module ForestLiana
|
|
510
509
|
|
511
510
|
it 'should raise the right error' do
|
512
511
|
expect { getter }.to raise_error(
|
513
|
-
|
514
|
-
|
515
|
-
|
512
|
+
ForestLiana::Errors::NotImplementedMethodError,
|
513
|
+
"method filter on smart field 'alter_coordinates' not found"
|
514
|
+
)
|
516
515
|
end
|
517
516
|
end
|
518
517
|
|
@@ -555,10 +554,10 @@ module ForestLiana
|
|
555
554
|
let(:filters) { {
|
556
555
|
aggregator: 'and',
|
557
556
|
conditions: [{
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
557
|
+
field: 'name',
|
558
|
+
operator: 'contains',
|
559
|
+
value: 'a',
|
560
|
+
}]
|
562
561
|
}.to_json }
|
563
562
|
|
564
563
|
it 'should get only the records matching the scope' do
|
@@ -592,6 +591,64 @@ module ForestLiana
|
|
592
591
|
end
|
593
592
|
end
|
594
593
|
|
594
|
+
describe '#extract_associations_from_filter' do
|
595
|
+
let(:resource) { Tree }
|
596
|
+
|
597
|
+
before { init_scopes }
|
598
|
+
|
599
|
+
context 'with a single filter as JSON string' do
|
600
|
+
let(:filters) {
|
601
|
+
{
|
602
|
+
field: 'island:updated_at',
|
603
|
+
operator: 'equal',
|
604
|
+
value: '2024-01-01'
|
605
|
+
}.to_json
|
606
|
+
}
|
607
|
+
|
608
|
+
it 'extracts the correct association' do
|
609
|
+
expect(getter.send(:extract_associations_from_filter)).to eq [:island]
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
613
|
+
context 'with grouped conditions as JSON string' do
|
614
|
+
let(:filters) {
|
615
|
+
{
|
616
|
+
aggregator: 'and',
|
617
|
+
conditions: [
|
618
|
+
{ field: 'island:updated_at', operator: 'equal', value: '2024-01-01' },
|
619
|
+
{ field: 'owner:name', operator: 'equal', value: 'Michel' },
|
620
|
+
{ field: 'id', operator: 'present', value: nil }
|
621
|
+
]
|
622
|
+
}.to_json
|
623
|
+
}
|
624
|
+
|
625
|
+
it 'extracts all unique associations' do
|
626
|
+
expect(getter.send(:extract_associations_from_filter)).to match_array [:island, :owner]
|
627
|
+
end
|
628
|
+
end
|
629
|
+
|
630
|
+
context 'when filters has no association field' do
|
631
|
+
let(:filters) {
|
632
|
+
{
|
633
|
+
field: 'id',
|
634
|
+
operator: 'equal',
|
635
|
+
value: 1
|
636
|
+
}.to_json
|
637
|
+
}
|
638
|
+
|
639
|
+
it 'returns an empty array' do
|
640
|
+
expect(getter.send(:extract_associations_from_filter)).to eq []
|
641
|
+
end
|
642
|
+
end
|
643
|
+
|
644
|
+
context 'when filters is nil' do
|
645
|
+
let(:filters) { nil }
|
646
|
+
|
647
|
+
it 'returns an empty array' do
|
648
|
+
expect(getter.send(:extract_associations_from_filter)).to eq []
|
649
|
+
end
|
650
|
+
end
|
651
|
+
end
|
595
652
|
end
|
596
653
|
end
|
597
|
-
end
|
654
|
+
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.15.
|
4
|
+
version: 9.15.1
|
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-07-
|
11
|
+
date: 2025-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|