forest_liana 5.4.0 → 5.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/forest_liana/actions_controller.rb +12 -2
- data/lib/forest_liana/version.rb +1 -1
- data/spec/dummy/app/assets/config/manifest.js +1 -0
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/db/migrate/20190226172951_create_user.rb +1 -1
- data/spec/dummy/db/migrate/20190226173051_create_isle.rb +1 -1
- data/spec/dummy/db/migrate/20190226174951_create_tree.rb +1 -1
- data/spec/dummy/db/migrate/20190716130830_add_age_to_tree.rb +1 -1
- data/spec/dummy/db/migrate/20190716135241_add_type_to_user.rb +1 -1
- data/spec/dummy/db/schema.rb +18 -20
- data/spec/requests/actions_controller_spec.rb +59 -11
- data/spec/requests/resources_spec.rb +4 -4
- data/test/dummy/app/assets/config/manifest.js +1 -0
- data/test/dummy/config/application.rb +1 -1
- data/test/dummy/db/migrate/20150608130516_create_date_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131430_create_integer_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131603_create_decimal_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131610_create_float_field.rb +1 -1
- data/test/dummy/db/migrate/20150608132159_create_boolean_field.rb +1 -1
- data/test/dummy/db/migrate/20150608132621_create_string_field.rb +1 -1
- data/test/dummy/db/migrate/20150608133038_create_belongs_to_field.rb +1 -1
- data/test/dummy/db/migrate/20150608133044_create_has_one_field.rb +1 -1
- data/test/dummy/db/migrate/20150608150016_create_has_many_field.rb +1 -1
- data/test/dummy/db/migrate/20150609114636_create_belongs_to_class_name_field.rb +1 -1
- data/test/dummy/db/migrate/20150612112520_create_has_and_belongs_to_many_field.rb +1 -1
- data/test/dummy/db/migrate/20150616150629_create_polymorphic_field.rb +1 -1
- data/test/dummy/db/migrate/20150623115554_create_has_many_class_name_field.rb +1 -1
- data/test/dummy/db/migrate/20150814081918_create_has_many_through_field.rb +1 -1
- data/test/dummy/db/migrate/20160627172810_create_owner.rb +1 -1
- data/test/dummy/db/migrate/20160627172951_create_tree.rb +1 -1
- data/test/dummy/db/migrate/20160628173505_add_timestamps.rb +1 -1
- data/test/dummy/db/migrate/20170614141921_create_serialize_field.rb +1 -1
- data/test/dummy/db/migrate/20181111162121_create_references_table.rb +1 -1
- data/test/services/forest_liana/resources_getter_test.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e6b91f8b65d70c711aa9f0f20e5efaf8ee6eddc7324b09629cab67ddbc7534b
|
4
|
+
data.tar.gz: c21d927739263c46975a51e67bbbe51c00affcb82db53ea5895bd18f107dc864
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e160240b6a18c405861906143eb1fc121eb97317f0ee3a826ba07b7f93509a43ed906d03a91dccc978f3fa5432702b7d13d47afaa3e4109a46afb732bc3a4659
|
7
|
+
data.tar.gz: 3470dbf5dab1b67904d00eb183f63b70a511f158427fcedc8d2b63aad6080ce38dda979859eb5f5a5fd28cfbb97b3e7e4c132c776bd4c5cb1efb34b4d60674e4
|
@@ -55,10 +55,20 @@ module ForestLiana
|
|
55
55
|
# Apply result on fields (transform the object back to an array), preserve order.
|
56
56
|
fields = action.fields.map do |field|
|
57
57
|
updated_field = result[field[:field]]
|
58
|
+
|
58
59
|
# Reset `value` when not present in `enums` (which means `enums` has changed).
|
59
|
-
if updated_field[:enums].is_a?(Array)
|
60
|
-
|
60
|
+
if updated_field[:enums].is_a?(Array)
|
61
|
+
# `value` can be an array if the type of fields is `[x]`
|
62
|
+
if updated_field[:type].is_a?(Array) && updated_field[:value].is_a?(Array) && !(updated_field[:value] - updated_field[:enums]).empty?
|
63
|
+
updated_field[:value] = nil
|
64
|
+
end
|
65
|
+
|
66
|
+
# `value` can be any other value
|
67
|
+
if !updated_field[:type].is_a?(Array) && !updated_field[:enums].include?(updated_field[:value])
|
68
|
+
updated_field[:value] = nil
|
69
|
+
end
|
61
70
|
end
|
71
|
+
|
62
72
|
updated_field
|
63
73
|
end
|
64
74
|
|
data/lib/forest_liana/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{}
|
@@ -20,7 +20,7 @@ module Dummy
|
|
20
20
|
# config.i18n.default_locale = :de
|
21
21
|
|
22
22
|
# Do not swallow errors in after_commit/after_rollback callbacks.
|
23
|
-
config.active_record.raise_in_transactional_callbacks = true
|
23
|
+
# config.active_record.raise_in_transactional_callbacks = true
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -1,44 +1,42 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# This file is auto-generated from the current state of the database. Instead
|
3
2
|
# of editing this file, please use the migrations feature of Active Record to
|
4
3
|
# incrementally modify your database, and then regenerate this schema definition.
|
5
4
|
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# from scratch.
|
10
|
-
#
|
5
|
+
# This file is the source Rails uses to define your schema when running `rails
|
6
|
+
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
|
7
|
+
# be faster and is potentially less error prone than running all of your
|
8
|
+
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
|
+
# migrations use external dependencies or application code.
|
11
10
|
#
|
12
11
|
# It's strongly recommended that you check this file into your version control system.
|
13
12
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 2019_07_16_135241) do
|
15
14
|
|
16
15
|
create_table "isle", force: :cascade do |t|
|
17
|
-
t.string
|
18
|
-
t.binary
|
16
|
+
t.string "name"
|
17
|
+
t.binary "map"
|
19
18
|
t.datetime "created_at"
|
20
19
|
t.datetime "updated_at"
|
21
20
|
end
|
22
21
|
|
23
22
|
create_table "trees", force: :cascade do |t|
|
24
|
-
t.string
|
25
|
-
t.integer
|
26
|
-
t.integer
|
27
|
-
t.integer
|
23
|
+
t.string "name"
|
24
|
+
t.integer "owner_id"
|
25
|
+
t.integer "cutter_id"
|
26
|
+
t.integer "island_id"
|
28
27
|
t.datetime "created_at"
|
29
28
|
t.datetime "updated_at"
|
30
|
-
t.integer
|
29
|
+
t.integer "age"
|
30
|
+
t.index ["cutter_id"], name: "index_trees_on_cutter_id"
|
31
|
+
t.index ["island_id"], name: "index_trees_on_island_id"
|
32
|
+
t.index ["owner_id"], name: "index_trees_on_owner_id"
|
31
33
|
end
|
32
34
|
|
33
|
-
add_index "trees", ["cutter_id"], name: "index_trees_on_cutter_id"
|
34
|
-
add_index "trees", ["island_id"], name: "index_trees_on_island_id"
|
35
|
-
add_index "trees", ["owner_id"], name: "index_trees_on_owner_id"
|
36
|
-
|
37
35
|
create_table "users", force: :cascade do |t|
|
38
|
-
t.string
|
36
|
+
t.string "name"
|
39
37
|
t.datetime "created_at"
|
40
38
|
t.datetime "updated_at"
|
41
|
-
t.integer
|
39
|
+
t.integer "title"
|
42
40
|
end
|
43
41
|
|
44
42
|
end
|
@@ -35,6 +35,11 @@ describe 'Requesting Actions routes', :type => :request do
|
|
35
35
|
type: 'Enum',
|
36
36
|
enums: %w[a b c],
|
37
37
|
}
|
38
|
+
multiple_enum = {
|
39
|
+
field: 'multipleEnum',
|
40
|
+
type: ['Enum'],
|
41
|
+
enums: %w[a b c],
|
42
|
+
}
|
38
43
|
|
39
44
|
action_definition = {
|
40
45
|
name: 'my_action',
|
@@ -95,34 +100,50 @@ describe 'Requesting Actions routes', :type => :request do
|
|
95
100
|
}
|
96
101
|
}
|
97
102
|
}
|
103
|
+
|
104
|
+
multiple_enums_action_definition = {
|
105
|
+
name: 'multiple_enums_action',
|
106
|
+
fields: [foo, multiple_enum],
|
107
|
+
hooks: {
|
108
|
+
:change => {
|
109
|
+
'foo' => -> (context) {
|
110
|
+
fields = context[:fields]
|
111
|
+
fields['multipleEnum'][:enums] = %w[c d z]
|
112
|
+
return fields
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
98
118
|
action = ForestLiana::Model::Action.new(action_definition)
|
99
119
|
fail_action = ForestLiana::Model::Action.new(fail_action_definition)
|
100
120
|
cheat_action = ForestLiana::Model::Action.new(cheat_action_definition)
|
101
121
|
enums_action = ForestLiana::Model::Action.new(enums_action_definition)
|
122
|
+
multiple_enums_action = ForestLiana::Model::Action.new(multiple_enums_action_definition)
|
102
123
|
island = ForestLiana.apimap.find {|collection| collection.name.to_s == ForestLiana.name_for(Island)}
|
103
|
-
island.actions = [action, fail_action, cheat_action, enums_action]
|
124
|
+
island.actions = [action, fail_action, cheat_action, enums_action, multiple_enums_action]
|
104
125
|
|
105
126
|
describe 'call /load' do
|
106
127
|
params = {recordIds: [1], collectionName: 'Island'}
|
107
128
|
|
108
129
|
it 'should respond 200' do
|
109
|
-
post '/forest/actions/my_action/hooks/load', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
|
130
|
+
post '/forest/actions/my_action/hooks/load', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
110
131
|
expect(response.status).to eq(200)
|
111
132
|
expect(JSON.parse(response.body)).to eq({'fields' => [foo.merge({:value => nil}).stringify_keys]})
|
112
133
|
end
|
113
134
|
|
114
135
|
it 'should respond 500 with bad params' do
|
115
|
-
post '/forest/actions/my_action/hooks/load', {}
|
136
|
+
post '/forest/actions/my_action/hooks/load', params: {}
|
116
137
|
expect(response.status).to eq(500)
|
117
138
|
end
|
118
139
|
|
119
140
|
it 'should respond 500 with bad hook result type' do
|
120
|
-
post '/forest/actions/fail_action/hooks/load', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
|
141
|
+
post '/forest/actions/fail_action/hooks/load', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
121
142
|
expect(response.status).to eq(500)
|
122
143
|
end
|
123
144
|
|
124
145
|
it 'should respond 500 with bad hook result data structure' do
|
125
|
-
post '/forest/actions/cheat_action/hooks/load', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
|
146
|
+
post '/forest/actions/cheat_action/hooks/load', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
126
147
|
expect(response.status).to eq(500)
|
127
148
|
end
|
128
149
|
end
|
@@ -132,7 +153,7 @@ describe 'Requesting Actions routes', :type => :request do
|
|
132
153
|
params = {recordIds: [1], fields: [updated_foo], collectionName: 'Island', changedField: 'foo'}
|
133
154
|
|
134
155
|
it 'should respond 200' do
|
135
|
-
post '/forest/actions/my_action/hooks/change', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
|
156
|
+
post '/forest/actions/my_action/hooks/change', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
136
157
|
expect(response.status).to eq(200)
|
137
158
|
expected = updated_foo.clone.merge({:value => 'baz'})
|
138
159
|
expected[:widgetEdit] = nil
|
@@ -141,24 +162,24 @@ describe 'Requesting Actions routes', :type => :request do
|
|
141
162
|
end
|
142
163
|
|
143
164
|
it 'should respond 500 with bad params' do
|
144
|
-
post '/forest/actions/my_action/hooks/change', {}
|
165
|
+
post '/forest/actions/my_action/hooks/change', params: {}
|
145
166
|
expect(response.status).to eq(500)
|
146
167
|
end
|
147
168
|
|
148
169
|
it 'should respond 500 with bad hook result type' do
|
149
|
-
post '/forest/actions/fail_action/hooks/change', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
|
170
|
+
post '/forest/actions/fail_action/hooks/change', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
150
171
|
expect(response.status).to eq(500)
|
151
172
|
end
|
152
173
|
|
153
174
|
it 'should respond 500 with bad hook result data structure' do
|
154
|
-
post '/forest/actions/cheat_action/hooks/change', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
|
175
|
+
post '/forest/actions/cheat_action/hooks/change', params: JSON.dump(params), headers: { 'CONTENT_TYPE' => 'application/json' }
|
155
176
|
expect(response.status).to eq(500)
|
156
177
|
end
|
157
178
|
|
158
179
|
it 'should reset value when enums has changed' do
|
159
180
|
updated_enum = enum.clone.merge({:previousValue => nil, :value => 'a'}) # set value to a
|
160
181
|
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'
|
182
|
+
post '/forest/actions/enums_action/hooks/change', params: JSON.dump(p), headers: { 'CONTENT_TYPE' => 'application/json' }
|
162
183
|
expect(response.status).to eq(200)
|
163
184
|
|
164
185
|
expected_enum = updated_enum.clone.merge({ :enums => %w[c d e], :value => nil, :widgetEdit => nil})
|
@@ -169,6 +190,33 @@ describe 'Requesting Actions routes', :type => :request do
|
|
169
190
|
expect(JSON.parse(response.body)).to eq({'fields' => [expected_foo.stringify_keys, expected_enum.stringify_keys]})
|
170
191
|
end
|
171
192
|
|
193
|
+
it 'should not reset value when every enum values are in the enums definition' do
|
194
|
+
updated_multiple_enum = multiple_enum.clone.merge({:previousValue => nil, :value => %w[c]})
|
195
|
+
p = {recordIds: [1], fields: [foo, updated_multiple_enum], collectionName: 'Island', changedField: 'foo'}
|
196
|
+
post '/forest/actions/multiple_enums_action/hooks/change', params: JSON.dump(p), headers: { 'CONTENT_TYPE' => 'application/json' }
|
197
|
+
expect(response.status).to eq(200)
|
198
|
+
|
199
|
+
expected_multiple_enum = updated_multiple_enum.clone.merge({ :enums => %w[c d z], :widgetEdit => nil, :value => %w[c]})
|
200
|
+
expected_multiple_enum.delete(:widget)
|
201
|
+
expected_foo = foo.clone.merge({ :widgetEdit => nil})
|
202
|
+
expected_foo.delete(:widget)
|
203
|
+
|
204
|
+
expect(JSON.parse(response.body)).to eq({'fields' => [expected_foo.stringify_keys, expected_multiple_enum.stringify_keys]})
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'should reset value when one of the enum values is not in the enums definition' do
|
208
|
+
wrongly_updated_multiple_enum = multiple_enum.clone.merge({:previousValue => nil, :value => %w[a b]})
|
209
|
+
p = {recordIds: [1], fields: [foo, wrongly_updated_multiple_enum], collectionName: 'Island', changedField: 'foo'}
|
210
|
+
post '/forest/actions/multiple_enums_action/hooks/change', params: JSON.dump(p), headers: { 'CONTENT_TYPE' => 'application/json' }
|
211
|
+
expect(response.status).to eq(200)
|
212
|
+
|
213
|
+
expected_multiple_enum = wrongly_updated_multiple_enum.clone.merge({ :enums => %w[c d z], :widgetEdit => nil, :value => nil })
|
214
|
+
expected_multiple_enum.delete(:widget)
|
215
|
+
expected_foo = foo.clone.merge({ :widgetEdit => nil})
|
216
|
+
expected_foo.delete(:widget)
|
217
|
+
|
218
|
+
expect(JSON.parse(response.body)).to eq({'fields' => [expected_foo.stringify_keys, expected_multiple_enum.stringify_keys]})
|
219
|
+
end
|
172
220
|
end
|
173
221
|
end
|
174
|
-
end
|
222
|
+
end
|
@@ -46,12 +46,12 @@ describe 'Requesting Tree resources', :type => :request do
|
|
46
46
|
}
|
47
47
|
|
48
48
|
it 'should respond 200' do
|
49
|
-
get '/forest/Tree', params, headers
|
49
|
+
get '/forest/Tree', params: params, headers: headers
|
50
50
|
expect(response.status).to eq(200)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'should respond the tree data' do
|
54
|
-
get '/forest/Tree', params, headers
|
54
|
+
get '/forest/Tree', params: params, headers: headers
|
55
55
|
expect(JSON.parse(response.body)).to eq({
|
56
56
|
"data" => [{
|
57
57
|
"type" => "Tree",
|
@@ -83,12 +83,12 @@ describe 'Requesting Tree resources', :type => :request do
|
|
83
83
|
}
|
84
84
|
|
85
85
|
it 'should respond 200' do
|
86
|
-
get '/forest/Tree', params, headers
|
86
|
+
get '/forest/Tree', params: params, headers: headers
|
87
87
|
expect(response.status).to eq(200)
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'should respond the tree data' do
|
91
|
-
get '/forest/Tree', params, headers
|
91
|
+
get '/forest/Tree', params: params, headers: headers
|
92
92
|
expect(JSON.parse(response.body)).to eq({
|
93
93
|
"data" => [{
|
94
94
|
"type" => "Tree",
|
@@ -0,0 +1 @@
|
|
1
|
+
{}
|
@@ -20,7 +20,7 @@ module Dummy
|
|
20
20
|
# config.i18n.default_locale = :de
|
21
21
|
|
22
22
|
# Do not swallow errors in after_commit/after_rollback callbacks.
|
23
|
-
config.active_record.raise_in_transactional_callbacks = true
|
23
|
+
# config.active_record.raise_in_transactional_callbacks = true
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
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.4.
|
4
|
+
version: 5.4.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:
|
11
|
+
date: 2021-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -302,6 +302,7 @@ files:
|
|
302
302
|
- lib/tasks/send_apimap.rake
|
303
303
|
- spec/dummy/README.rdoc
|
304
304
|
- spec/dummy/Rakefile
|
305
|
+
- spec/dummy/app/assets/config/manifest.js
|
305
306
|
- spec/dummy/app/assets/javascripts/application.js
|
306
307
|
- spec/dummy/app/assets/stylesheets/application.css
|
307
308
|
- spec/dummy/app/config/routes.rb
|
@@ -357,6 +358,7 @@ files:
|
|
357
358
|
- spec/spec_helper.rb
|
358
359
|
- test/dummy/README.rdoc
|
359
360
|
- test/dummy/Rakefile
|
361
|
+
- test/dummy/app/assets/config/manifest.js
|
360
362
|
- test/dummy/app/assets/javascripts/application.js
|
361
363
|
- test/dummy/app/assets/stylesheets/application.css
|
362
364
|
- test/dummy/app/controllers/application_controller.rb
|
@@ -510,6 +512,7 @@ test_files:
|
|
510
512
|
- test/dummy/app/helpers/application_helper.rb
|
511
513
|
- test/dummy/app/assets/javascripts/application.js
|
512
514
|
- test/dummy/app/assets/stylesheets/application.css
|
515
|
+
- test/dummy/app/assets/config/manifest.js
|
513
516
|
- test/dummy/app/controllers/application_controller.rb
|
514
517
|
- test/dummy/Rakefile
|
515
518
|
- test/dummy/bin/rake
|
@@ -580,6 +583,7 @@ test_files:
|
|
580
583
|
- spec/dummy/app/helpers/application_helper.rb
|
581
584
|
- spec/dummy/app/assets/javascripts/application.js
|
582
585
|
- spec/dummy/app/assets/stylesheets/application.css
|
586
|
+
- spec/dummy/app/assets/config/manifest.js
|
583
587
|
- spec/dummy/app/config/routes.rb
|
584
588
|
- spec/dummy/app/controllers/application_controller.rb
|
585
589
|
- spec/dummy/Rakefile
|