diff --git a/app/controllers/commands_controller.rb b/app/controllers/commands_controller.rb index a5f6b90f0..35fd34426 100644 --- a/app/controllers/commands_controller.rb +++ b/app/controllers/commands_controller.rb @@ -37,6 +37,9 @@ class CommandsController < ApplicationController end def respond_with_execution_result(result) + # This saves unnecessary back and forth between server and client (e.g: to redirect)- + result = result.is_a?(Array) && result.one? ? result.first : result + case result when Array respond_with_composite_response(result) diff --git a/app/models/command/ai/parser.rb b/app/models/command/ai/parser.rb index ab973ca02..c2e1db3b3 100644 --- a/app/models/command/ai/parser.rb +++ b/app/models/command/ai/parser.rb @@ -30,11 +30,7 @@ class Command::Ai::Parser commands.unshift Command::VisitUrl.new(user: user, url: query_context.url, context: resolved_context) end - if commands.many? - Command::Composite.new(title: query, commands: commands, user: user, line: query, context: resolved_context) - else - build_standalone_command(commands, query) - end + Command::Composite.new(title: query, commands: commands, user: user, line: query, context: resolved_context) end def commands_from_query(normalized_query, context) @@ -44,13 +40,6 @@ class Command::Ai::Parser end end - # This saves unnecessary interchanges with browser for redirect responses - def build_standalone_command(commands, query) - commands.first.tap do |command| - command.line = query - end - end - def resolve_named_params_to_ids(normalized_query) normalized_query.tap do |query_json| if query_context = query_json[:context].presence diff --git a/test/models/command/ai/parser_test.rb b/test/models/command/ai/parser_test.rb index c1b9d5e96..7416d6912 100644 --- a/test/models/command/ai/parser_test.rb +++ b/test/models/command/ai/parser_test.rb @@ -16,7 +16,7 @@ class Command::Ai::ParserTest < ActionDispatch::IntegrationTest test "resolve filter string params as ids" do command = parse_command "cards assigned to kevin, tagged with #web, in the collection writebook" - url = command.url + url = command.commands.first.url query_string = URI.parse(url).query params = Rack::Utils.parse_nested_query(query_string).with_indifferent_access diff --git a/test/models/command/go_to_card_test.rb b/test/models/command/go_to_card_test.rb index 09c17d3b8..3d4f0aaab 100644 --- a/test/models/command/go_to_card_test.rb +++ b/test/models/command/go_to_card_test.rb @@ -21,6 +21,7 @@ class Command::GoToCardTest < ActionDispatch::IntegrationTest assert command.valid? result = command.execute - assert_equal cards_path(terms: [ "123" ]), result.url + assert_equal 1, result.size + assert_equal cards_path(terms: [ "123" ]), result.first.url end end