Skip to content

Commit d65c065

Browse files
fix(smart-actions): use changedField instead of comparing values to trigger the correct change hook (#396)
1 parent 207a6d8 commit d65c065

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

app/controllers/forest_liana/actions_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ def change
8686
formatted_fields = context[:fields].clone # clone for following test on is_same_data_structure
8787

8888
# Call the user-defined change hook.
89-
field_name = params[:fields].select { |field| field[:value] != field[:previousValue] }[0][:field]
90-
result = action.hooks[:change][field_name].(context)
89+
result = action.hooks[:change][params[:changedField]].(context)
9190

9291
handle_result(result, formatted_fields, action)
9392
end

spec/requests/actions_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109

110110
describe 'call /change' do
111111
updated_foo = foo.clone.merge({:previousValue => nil, :value => 'bar'})
112-
params = {recordIds: [1], fields: [updated_foo], collectionName: 'Island'}
112+
params = {recordIds: [1], fields: [updated_foo], collectionName: 'Island', changedField: 'foo'}
113113

114114
it 'should respond 200' do
115115
post '/forest/actions/my_action/hooks/change', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'

0 commit comments

Comments
 (0)