forest_liana 5.3.2 → 5.3.3
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: 52b354dcc7c4a05c8303bffa7c1deca674900d7b693f37e816d2bafe665c4b12
|
|
4
|
+
data.tar.gz: 358a702306af12e805a6fe954c2e0fbb1d1ccc3ebe8fe8d8b73d6ebd8f101bb5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 68dac9b8f4e7f427d1c9f4bf885d2412cf740b8e6038a6e83e919c967e9fbe9369fddc753992b7d80a191a04688366c06cc028a2afe309a476686e993603e8a6
|
|
7
|
+
data.tar.gz: fcdb37f174ec29d416bfe1ce668608baa9e1924ec6ea2b51e61dcc74f1976e11fdf6eb41eb5503a22ed352d4e0ad772bc1498f2f31f958a467ac54dcf6e56a75
|
|
@@ -53,7 +53,14 @@ module ForestLiana
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
# Apply result on fields (transform the object back to an array), preserve order.
|
|
56
|
-
fields = action.fields.map
|
|
56
|
+
fields = action.fields.map do |field|
|
|
57
|
+
updated_field = result[field[:field]]
|
|
58
|
+
# Reset `value` when not present in `enums` (which means `enums` has changed).
|
|
59
|
+
if updated_field[:enums].is_a?(Array) && !updated_field[:enums].include?(updated_field[:value])
|
|
60
|
+
updated_field[:value] = nil
|
|
61
|
+
end
|
|
62
|
+
updated_field
|
|
63
|
+
end
|
|
57
64
|
|
|
58
65
|
render serializer: nil, json: { fields: fields}, status: :ok
|
|
59
66
|
end
|
data/lib/forest_liana/version.rb
CHANGED
|
@@ -30,6 +30,12 @@ describe 'Requesting Actions routes', :type => :request do
|
|
|
30
30
|
description: nil,
|
|
31
31
|
widget: nil,
|
|
32
32
|
}
|
|
33
|
+
enum = {
|
|
34
|
+
field: 'enum',
|
|
35
|
+
type: 'Enum',
|
|
36
|
+
enums: %w[a b c],
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
action_definition = {
|
|
34
40
|
name: 'my_action',
|
|
35
41
|
fields: [foo],
|
|
@@ -76,11 +82,25 @@ describe 'Requesting Actions routes', :type => :request do
|
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
}
|
|
85
|
+
enums_action_definition = {
|
|
86
|
+
name: 'enums_action',
|
|
87
|
+
fields: [foo, enum],
|
|
88
|
+
hooks: {
|
|
89
|
+
:change => {
|
|
90
|
+
'foo' => -> (context) {
|
|
91
|
+
fields = context[:fields]
|
|
92
|
+
fields['enum'][:enums] = %w[c d e]
|
|
93
|
+
return fields
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
79
98
|
action = ForestLiana::Model::Action.new(action_definition)
|
|
80
99
|
fail_action = ForestLiana::Model::Action.new(fail_action_definition)
|
|
81
100
|
cheat_action = ForestLiana::Model::Action.new(cheat_action_definition)
|
|
101
|
+
enums_action = ForestLiana::Model::Action.new(enums_action_definition)
|
|
82
102
|
island = ForestLiana.apimap.find {|collection| collection.name.to_s == ForestLiana.name_for(Island)}
|
|
83
|
-
island.actions = [action, fail_action, cheat_action]
|
|
103
|
+
island.actions = [action, fail_action, cheat_action, enums_action]
|
|
84
104
|
|
|
85
105
|
describe 'call /load' do
|
|
86
106
|
params = {recordIds: [1], collectionName: 'Island'}
|
|
@@ -114,7 +134,7 @@ describe 'Requesting Actions routes', :type => :request do
|
|
|
114
134
|
it 'should respond 200' do
|
|
115
135
|
post '/forest/actions/my_action/hooks/change', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
|
|
116
136
|
expect(response.status).to eq(200)
|
|
117
|
-
expected = updated_foo.merge({:value => 'baz'})
|
|
137
|
+
expected = updated_foo.clone.merge({:value => 'baz'})
|
|
118
138
|
expected[:widgetEdit] = nil
|
|
119
139
|
expected.delete(:widget)
|
|
120
140
|
expect(JSON.parse(response.body)).to eq({'fields' => [expected.stringify_keys]})
|
|
@@ -134,6 +154,21 @@ describe 'Requesting Actions routes', :type => :request do
|
|
|
134
154
|
post '/forest/actions/cheat_action/hooks/change', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
|
|
135
155
|
expect(response.status).to eq(500)
|
|
136
156
|
end
|
|
157
|
+
|
|
158
|
+
it 'should reset value when enums has changed' do
|
|
159
|
+
updated_enum = enum.clone.merge({:previousValue => nil, :value => 'a'}) # set value to a
|
|
160
|
+
p = {recordIds: [1], fields: [updated_foo, updated_enum], collectionName: 'Island', changedField: 'foo'}
|
|
161
|
+
post '/forest/actions/enums_action/hooks/change', JSON.dump(p), 'CONTENT_TYPE' => 'application/json'
|
|
162
|
+
expect(response.status).to eq(200)
|
|
163
|
+
|
|
164
|
+
expected_enum = updated_enum.clone.merge({ :enums => %w[c d e], :value => nil, :widgetEdit => nil})
|
|
165
|
+
expected_enum.delete(:widget)
|
|
166
|
+
expected_foo = updated_foo.clone.merge({ :widgetEdit => nil})
|
|
167
|
+
expected_foo.delete(:widget)
|
|
168
|
+
|
|
169
|
+
expect(JSON.parse(response.body)).to eq({'fields' => [expected_foo.stringify_keys, expected_enum.stringify_keys]})
|
|
170
|
+
end
|
|
171
|
+
|
|
137
172
|
end
|
|
138
173
|
end
|
|
139
174
|
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: 5.3.
|
|
4
|
+
version: 5.3.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: 2020-12-
|
|
11
|
+
date: 2020-12-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|