Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logic to save extractor keys as array if string #1611

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 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;
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved
end
end

@reducer = reducer_class.new(new_params)
Expand All @@ -69,7 +72,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;
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved
end
end

@reducer.update(params)
Expand Down Expand Up @@ -131,4 +137,5 @@ def reducer_params(klass)
def record_not_valid(exception)
render json: { error: exception.message }, status: 422
end

end
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 as an array' do
nested_reducer_params[:extractor_keys] = 'test'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats weird. I would have expected if we set extractor keys input to a string that it would keep as string. Maybe you mean nested_reducer_params[:filters][:extractor_keys] ?

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
Loading