Skip to content

Commit

Permalink
add logic to save extractor keys as array if string (#1611)
Browse files Browse the repository at this point in the history
* add logic to save extractor keys as array if string

* remove convert_to_array logic form reducers_controller

* sync in base

* modify test case
  • Loading branch information
Tooyosi authored Oct 15, 2024
1 parent b07b52f commit 4ff7c17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/controllers/reducers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def create

filters = new_params.fetch('filters', {})
if filters.has_key?('extractor_keys') && filters['extractor_keys'].is_a?(String)
filters['extractor_keys'] = JSON.parse(filters['extractor_keys'])
begin
filters['extractor_keys'] = JSON.parse(filters['extractor_keys'])
rescue JSON::ParserError, TypeError;
end
end

reset_config_reducer_keys(new_params)
Expand Down Expand Up @@ -71,7 +74,10 @@ def update

filters = params.fetch('filters', {})
if filters.has_key?('extractor_keys') && filters['extractor_keys'].is_a?(String)
filters['extractor_keys'] = JSON.parse(filters['extractor_keys'])
begin
filters['extractor_keys'] = JSON.parse(filters['extractor_keys'])
rescue JSON::ParserError, TypeError;
end
end

reset_config_reducer_keys(params)
Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/reducers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@
expect(workflow.reducers.first.filters['extractor_keys']).to eq(['test'])
end

it 'saves extractor_keys in inputted format' do
nested_reducer_params[:filters][:extractor_keys] = '[\'test\']'
post :create, params: {
workflow_id: workflow.id,
reducer: nested_reducer_params
}, format: :json

expect(workflow.reducers.first.filters['extractor_keys']).to eq('[\'test\']')
end

it 'jsonifies extractor_keys' do
post :create, params: {
workflow_id: workflow.id,
Expand Down

0 comments on commit 4ff7c17

Please sign in to comment.