forest_liana 9.15.3 → 9.15.5
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: cfe8bf0157f9d29d2dcc9131bc3e5ab3ad46e487a7a1d0c931fb6d9702e3f699
|
4
|
+
data.tar.gz: a58e6a4880d3f5640bdb98d2ac188090ba0b0c68e5cdbb69492b1d53c046b07a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cc3acf083ea28eb0562ff90eb662d77ebbf52d7a5f910cfe5355211f01135a9b383e45b1f2b21d35944c20a38f2a0af04aaded4028c2b00192f7791f8d87e3f
|
7
|
+
data.tar.gz: 13f80d33d32895478d31ce251dd6e73ceab910fb6420eaeb292011b00987987a0d629b7e35089c4c1c2300c9512dddf26a9f075a4bc37493cf1a9360132f954d
|
@@ -40,6 +40,8 @@ module ForestLiana
|
|
40
40
|
|
41
41
|
def serialize_model(record, options = {})
|
42
42
|
options[:is_collection] = false
|
43
|
+
options[:context] = { unoptimized: true }.merge(options[:context] || {})
|
44
|
+
|
43
45
|
json = ForestAdmin::JSONAPI::Serializer.serialize(record, options)
|
44
46
|
|
45
47
|
force_utf8_encoding(json)
|
@@ -178,7 +180,7 @@ module ForestLiana
|
|
178
180
|
else
|
179
181
|
smart_relations.each do |smart_relation|
|
180
182
|
if smart_relation[:field].to_s == relation_name
|
181
|
-
fields[
|
183
|
+
fields[relation_name] = relation_fields
|
182
184
|
end
|
183
185
|
end
|
184
186
|
end
|
@@ -4,6 +4,8 @@ module ForestLiana
|
|
4
4
|
attr_reader :includes
|
5
5
|
attr_reader :records_count
|
6
6
|
|
7
|
+
SUPPORTED_ASSOCIATION_MACROS = [:belongs_to, :has_one, :has_and_belongs_to_many].freeze
|
8
|
+
|
7
9
|
def initialize(resource, association, params, forest_user)
|
8
10
|
@resource = resource
|
9
11
|
@association = association
|
@@ -43,22 +45,21 @@ module ForestLiana
|
|
43
45
|
.reflect_on_all_associations
|
44
46
|
.select do |association|
|
45
47
|
|
48
|
+
next false unless SUPPORTED_ASSOCIATION_MACROS.include?(association.macro)
|
49
|
+
|
46
50
|
if SchemaUtils.polymorphic?(association)
|
47
51
|
inclusion = SchemaUtils.polymorphic_models(association)
|
48
|
-
.all? { |model| SchemaUtils.model_included?(model) }
|
49
|
-
[:belongs_to, :has_and_belongs_to_many].include?(association.macro)
|
52
|
+
.all? { |model| SchemaUtils.model_included?(model) }
|
50
53
|
else
|
51
|
-
inclusion = SchemaUtils.model_included?(association.klass)
|
52
|
-
[:belongs_to, :has_and_belongs_to_many].include?(association.macro)
|
54
|
+
inclusion = SchemaUtils.model_included?(association.klass)
|
53
55
|
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
57
|
+
if @field_names_requested.any?
|
58
|
+
inclusion && @field_names_requested.include?(association.name)
|
59
|
+
else
|
60
|
+
inclusion
|
60
61
|
end
|
61
|
-
.map
|
62
|
+
end.map(&:name)
|
62
63
|
end
|
63
64
|
|
64
65
|
def field_names_requested
|
data/lib/forest_liana/version.rb
CHANGED
@@ -113,6 +113,95 @@ module ForestLiana
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
116
|
+
|
117
|
+
describe 'compute_includes' do
|
118
|
+
it 'should include has_one relation from association' do
|
119
|
+
expect(subject.includes).to include(:location)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should include belongs_to relations from association' do
|
123
|
+
expect(subject.includes).to include(:owner, :cutter, :island, :eponymous_island)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should exclude has_many relations' do
|
127
|
+
has_many_associations = Tree.reflect_on_all_associations
|
128
|
+
.select { |a| a.macro == :has_many }
|
129
|
+
.map(&:name)
|
130
|
+
|
131
|
+
has_many_associations.each do |assoc|
|
132
|
+
expect(subject.includes).not_to include(assoc)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should include all supported associations from association by default' do
|
137
|
+
expected_associations = Tree.reflect_on_all_associations
|
138
|
+
.select { |a| [:belongs_to, :has_one, :has_and_belongs_to_many].include?(a.macro) }
|
139
|
+
.map(&:name)
|
140
|
+
|
141
|
+
expect(subject.includes).to match_array(expected_associations)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should respect fields filter for associations' do
|
145
|
+
params[:fields] = { 'Tree' => 'owner,island' }
|
146
|
+
getter = described_class.new(Island, association, params, user)
|
147
|
+
|
148
|
+
expect(getter.includes).to include(:owner, :island)
|
149
|
+
expect(getter.includes).not_to include(:cutter, :eponymous_island, :location)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should exclude Tree associations when models not included' do
|
153
|
+
allow(SchemaUtils).to receive(:model_included?).and_return(false)
|
154
|
+
expect(subject.includes).to be_empty
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'on polymorphic associations' do
|
158
|
+
let(:base_params) do
|
159
|
+
{
|
160
|
+
id: Island.first&.id || 1,
|
161
|
+
association_name: 'trees',
|
162
|
+
page: { size: 15, number: 1 },
|
163
|
+
timezone: 'UTC'
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
before do
|
168
|
+
# temporarily add a polymorphic association on Tree
|
169
|
+
Tree.class_eval { belongs_to :addressable, polymorphic: true, optional: true }
|
170
|
+
|
171
|
+
allow_any_instance_of(described_class).to receive(:prepare_query).and_return(nil)
|
172
|
+
allow(ForestLiana).to receive(:name_for).and_return('trees')
|
173
|
+
end
|
174
|
+
|
175
|
+
after do
|
176
|
+
%w[addressable].each do |name|
|
177
|
+
Tree._reflections.delete(name)
|
178
|
+
Tree.reflections.delete(name)
|
179
|
+
end
|
180
|
+
%w[addressable addressable= addressable_id addressable_type].each do |m|
|
181
|
+
Tree.undef_method(m) rescue nil
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should exclude the polymorphic association when not all target models are includable' do
|
186
|
+
params = base_params.merge(fields: { 'trees' => 'addressable' })
|
187
|
+
|
188
|
+
allow(SchemaUtils).to receive(:model_included?).and_return(true, false)
|
189
|
+
|
190
|
+
getter = described_class.new(Island, association, params, user)
|
191
|
+
expect(getter.includes).to eq([])
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should include the polymorphic association only when all target models are includable' do
|
195
|
+
params = base_params.merge(fields: { 'trees' => 'addressable' })
|
196
|
+
|
197
|
+
allow(SchemaUtils).to receive(:model_included?).and_return(true, true)
|
198
|
+
|
199
|
+
getter = described_class.new(Island, association, params, user)
|
200
|
+
expect(getter.includes).to contain_exactly(:addressable)
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
end
|
116
205
|
end
|
117
206
|
end
|
118
207
|
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.5
|
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-
|
11
|
+
date: 2025-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|