forest_liana 9.12.0 → 9.12.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 +4 -4
- data/app/services/forest_liana/resources_getter.rb +20 -4
- data/lib/forest_liana/version.rb +1 -1
- data/spec/dummy/app/models/tree.rb +2 -0
- data/spec/helpers/forest_liana/query_helper_spec.rb +9 -4
- data/spec/requests/resources_spec.rb +30 -4
- data/spec/services/forest_liana/resources_getter_spec.rb +16 -0
- data/spec/services/forest_liana/schema_adapter_spec.rb +12 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a205f59494a1a151c8bb1a5be912905bf7f1c9242136ae63de22f0372f7268bf
|
4
|
+
data.tar.gz: ddba735dde964ffe46c0dc2907edd065e707a3d63d8283f25b2155c903d3eeb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaaf6fbca9592c4853bcdfa2ec6c5983ee0f468fd62d36aab03cf55dc865a7ae7195c079b8d05a185c174a81cadb834f87e7ff85c69f489336a58ceb65c76559
|
7
|
+
data.tar.gz: 3f2dc59f88da2c969f8cf865809232d0b58988cf1f395d59837b2df0d3ef094854274e82eca82c3432d8672d9a1c760dc0204c86347cbdff3ae5304b5f555323
|
@@ -227,10 +227,20 @@ module ForestLiana
|
|
227
227
|
def compute_select_fields
|
228
228
|
select = ['_forest_admin_eager_load']
|
229
229
|
@params[:fields][@collection_name].split(',').each do |path|
|
230
|
+
association = get_one_association(path)
|
231
|
+
if association
|
232
|
+
while association.options[:through]
|
233
|
+
association = get_one_association(association.options[:through])
|
234
|
+
end
|
235
|
+
|
236
|
+
if SchemaUtils.polymorphic?(association)
|
237
|
+
select << "#{@resource.table_name}.#{association.foreign_type}"
|
238
|
+
end
|
239
|
+
select << "#{@resource.table_name}.#{association.foreign_key}"
|
240
|
+
end
|
241
|
+
|
230
242
|
if @params[:fields].key?(path)
|
231
|
-
association =
|
232
|
-
.select { |association| association.name == path.to_sym }
|
233
|
-
.first
|
243
|
+
association = get_one_association(path)
|
234
244
|
table_name = association.table_name
|
235
245
|
|
236
246
|
@params[:fields][path].split(',').each do |association_path|
|
@@ -245,7 +255,13 @@ module ForestLiana
|
|
245
255
|
end
|
246
256
|
end
|
247
257
|
|
248
|
-
select
|
258
|
+
select.uniq
|
259
|
+
end
|
260
|
+
|
261
|
+
def get_one_association(name)
|
262
|
+
ForestLiana::QueryHelper.get_one_associations(@resource)
|
263
|
+
.select { |association| association.name == name.to_sym }
|
264
|
+
.first
|
249
265
|
end
|
250
266
|
end
|
251
267
|
end
|
data/lib/forest_liana/version.rb
CHANGED
@@ -37,6 +37,7 @@ module ForestLiana
|
|
37
37
|
{ name: :cutter, klass: User },
|
38
38
|
{ name: :island, klass: Island },
|
39
39
|
{ name: :eponymous_island, klass: Island },
|
40
|
+
{ name: :location, klass: Location },
|
40
41
|
]
|
41
42
|
end
|
42
43
|
|
@@ -52,13 +53,17 @@ module ForestLiana
|
|
52
53
|
|
53
54
|
describe 'get_one_association_names_symbol' do
|
54
55
|
it 'should return the one-one associations names as symbols' do
|
55
|
-
expect(QueryHelper.get_one_association_names_symbol(Tree)).to eq(
|
56
|
+
expect(QueryHelper.get_one_association_names_symbol(Tree)).to eq(
|
57
|
+
[:owner, :cutter, :island, :eponymous_island, :location]
|
58
|
+
)
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
59
62
|
describe 'get_one_association_names_string' do
|
60
63
|
it 'should return the one-one associations names as strings' do
|
61
|
-
expect(QueryHelper.get_one_association_names_string(Tree)).to eq(
|
64
|
+
expect(QueryHelper.get_one_association_names_string(Tree)).to eq(
|
65
|
+
['owner', 'cutter', 'island', 'eponymous_island', 'location']
|
66
|
+
)
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
@@ -71,12 +76,12 @@ module ForestLiana
|
|
71
76
|
end
|
72
77
|
end
|
73
78
|
|
74
|
-
context 'on a model having
|
79
|
+
context 'on a model having 3 belongsTo/hasOne associations' do
|
75
80
|
tables_associated_to_relations_name =
|
76
81
|
QueryHelper.get_tables_associated_to_relations_name(Tree)
|
77
82
|
|
78
83
|
it 'should return the one-one associations' do
|
79
|
-
expect(tables_associated_to_relations_name.keys.length).to eq(
|
84
|
+
expect(tables_associated_to_relations_name.keys.length).to eq(3)
|
80
85
|
end
|
81
86
|
|
82
87
|
it 'should return relationships having a name different than the targeted model' do
|
@@ -4,7 +4,9 @@ describe 'Requesting Tree resources', :type => :request do
|
|
4
4
|
let(:scope_filters) { {'scopes' => {}, 'team' => {'id' => '1', 'name' => 'Operations'}} }
|
5
5
|
before do
|
6
6
|
user = User.create(name: 'Michel')
|
7
|
-
Tree.create(name: 'Lemon Tree', owner: user, cutter: user)
|
7
|
+
tree = Tree.create(name: 'Lemon Tree', owner: user, cutter: user)
|
8
|
+
island = Island.create(name: 'Lemon Island', trees: [tree])
|
9
|
+
Location.create(coordinates: '1,2', island: island)
|
8
10
|
|
9
11
|
Rails.cache.write('forest.users', {'1' => { 'id' => 1, 'roleId' => 1, 'rendering_id' => '1' }})
|
10
12
|
Rails.cache.write('forest.has_permission', true)
|
@@ -32,6 +34,8 @@ describe 'Requesting Tree resources', :type => :request do
|
|
32
34
|
after do
|
33
35
|
User.destroy_all
|
34
36
|
Tree.destroy_all
|
37
|
+
Island.destroy_all
|
38
|
+
Location.destroy_all
|
35
39
|
end
|
36
40
|
|
37
41
|
token = JWT.encode({
|
@@ -54,7 +58,7 @@ describe 'Requesting Tree resources', :type => :request do
|
|
54
58
|
describe 'index' do
|
55
59
|
describe 'without any filter' do
|
56
60
|
params = {
|
57
|
-
fields: { 'Tree' => 'id,name' },
|
61
|
+
fields: { 'Tree' => 'id,name,location' },
|
58
62
|
page: { 'number' => '1', 'size' => '10' },
|
59
63
|
searchExtended: '0',
|
60
64
|
sort: '-id',
|
@@ -98,7 +102,8 @@ describe 'Requesting Tree resources', :type => :request do
|
|
98
102
|
|
99
103
|
it 'should respond the tree data' do
|
100
104
|
get '/forest/Tree', params: params, headers: headers
|
101
|
-
|
105
|
+
|
106
|
+
expect(JSON.parse(response.body)).to include({
|
102
107
|
"data" => [{
|
103
108
|
"type" => "Tree",
|
104
109
|
"id" => "1",
|
@@ -108,9 +113,30 @@ describe 'Requesting Tree resources', :type => :request do
|
|
108
113
|
},
|
109
114
|
"links" => {
|
110
115
|
"self" => "/forest/tree/1"
|
116
|
+
},
|
117
|
+
"relationships" => {
|
118
|
+
"location" => {
|
119
|
+
"data" => { "id" => "1", "type" => "Location" },
|
120
|
+
"links" => { "related" => {} }
|
121
|
+
}
|
111
122
|
}
|
112
123
|
}],
|
113
|
-
"included" => [
|
124
|
+
"included" => [{
|
125
|
+
"type" => "Location",
|
126
|
+
"id" => "1",
|
127
|
+
"attributes" => include(
|
128
|
+
"id" => 1,
|
129
|
+
"created_at" => nil,
|
130
|
+
"updated_at" => nil,
|
131
|
+
"coordinates" => nil
|
132
|
+
),
|
133
|
+
"links" => { "self" => "/forest/location/1" },
|
134
|
+
"relationships" => {
|
135
|
+
"island" => {
|
136
|
+
"links" => { "related" => {} }
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}]
|
114
140
|
})
|
115
141
|
end
|
116
142
|
end
|
@@ -290,6 +290,22 @@ module ForestLiana
|
|
290
290
|
end
|
291
291
|
end
|
292
292
|
|
293
|
+
describe 'when getting a has_one through association' do
|
294
|
+
let(:resource) { Tree }
|
295
|
+
let(:fields) { { 'Tree' => 'id,location' } }
|
296
|
+
|
297
|
+
it 'should get the expected records, including the foreign_key for the direct association' do
|
298
|
+
getter.perform
|
299
|
+
records = getter.records
|
300
|
+
count = getter.count
|
301
|
+
|
302
|
+
expect(records.count).to eq Tree.count
|
303
|
+
expect(count).to eq Tree.count
|
304
|
+
expect(records.map(&:id)).to match_array(Tree.pluck(:id))
|
305
|
+
expect(records.map(&:island_id)).to match_array(Tree.pluck(:island_id))
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
293
309
|
describe 'when filtering on an ambiguous field' do
|
294
310
|
let(:resource) { Tree }
|
295
311
|
let(:pageSize) { 5 }
|
@@ -61,7 +61,18 @@ module ForestLiana
|
|
61
61
|
end
|
62
62
|
|
63
63
|
expect(collection.fields.map { |field| field[:field].to_s}).to eq(
|
64
|
-
[
|
64
|
+
[
|
65
|
+
"age",
|
66
|
+
"created_at",
|
67
|
+
"cutter",
|
68
|
+
"eponymous_island",
|
69
|
+
"id",
|
70
|
+
"island",
|
71
|
+
"location",
|
72
|
+
"name",
|
73
|
+
"owner",
|
74
|
+
"updated_at"
|
75
|
+
]
|
65
76
|
)
|
66
77
|
end
|
67
78
|
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.12.
|
4
|
+
version: 9.12.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-05-
|
11
|
+
date: 2025-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|