diff --git a/lib/rails/convert_rails_test_request_methods_4_2_to_5_0.rb b/lib/rails/convert_rails_test_request_methods_4_2_to_5_0.rb index 40101041..b0a22b63 100644 --- a/lib/rails/convert_rails_test_request_methods_4_2_to_5_0.rb +++ b/lib/rails/convert_rails_test_request_methods_4_2_to_5_0.rb @@ -35,8 +35,9 @@ next if argument_node.to_source == 'nil' if argument_node.type == :hash - new_value = argument_node.children.reject { |pair_node| %i[format xhr].include?(pair_node.key.to_value) } - .map(&:to_source).join(', ') + new_value = + argument_node.children.reject { |pair_node| %i[format xhr].include?(pair_node.key.to_value) }.map(&:to_source) + .join(', ') "#{key}: #{add_curly_brackets_if_necessary(new_value)}" if new_value.length > 0 else "#{key}: #{argument_node.to_source}" @@ -91,8 +92,7 @@ %w[get post put patch delete].each do |message| with_node type: 'send', message: message do next unless node.arguments.size > 1 - if node.arguments[1].type == :hash && - (node.arguments[1].key?(:params) || node.arguments[1].key?(:headers)) + if node.arguments[1].type == :hash && (node.arguments[1].key?(:params) || node.arguments[1].key?(:headers)) next end diff --git a/lib/rails/convert_routes_2_3_to_3_0.rb b/lib/rails/convert_routes_2_3_to_3_0.rb index 24a2ce90..23548441 100644 --- a/lib/rails/convert_routes_2_3_to_3_0.rb +++ b/lib/rails/convert_routes_2_3_to_3_0.rb @@ -327,26 +327,26 @@ url = node.arguments.first.to_value hash_node = node.arguments.last if hash_node.type == :hash && hash_node.key?(:controller) - if hash_node.key?(:action) || url !~ /:action/ - controller_action_name = - if hash_node.key?(:action) - extract_controller_action_name(hash_node) - else - "#{hash_node.hash_value(:controller).to_value}#index" - end - method = extract_method(hash_node) - subdomain_node = extract_subdomain_node(hash_node) - other_options_code = reject_keys_from_hash(hash_node, :controller, :action, :method, :conditions) - other_options_code += ":constraints => {:subdomain => #{subdomain_node.to_source}}" if subdomain_node - if other_options_code.length > 0 - replace_with "#{method} {{arguments.first}}, :to => \"#{controller_action_name}\", #{other_options_code}, :as => \"#{message}\"" + if hash_node.key?(:action) || url !~ /:action/ + controller_action_name = + if hash_node.key?(:action) + extract_controller_action_name(hash_node) else - replace_with "#{method} {{arguments.first}}, :to => \"#{controller_action_name}\", :as => \"#{message}\"" + "#{hash_node.hash_value(:controller).to_value}#index" end + method = extract_method(hash_node) + subdomain_node = extract_subdomain_node(hash_node) + other_options_code = reject_keys_from_hash(hash_node, :controller, :action, :method, :conditions) + other_options_code += ":constraints => {:subdomain => #{subdomain_node.to_source}}" if subdomain_node + if other_options_code.length > 0 + replace_with "#{method} {{arguments.first}}, :to => \"#{controller_action_name}\", #{other_options_code}, :as => \"#{message}\"" else - replace_with 'match {{arguments}}' + replace_with "#{method} {{arguments.first}}, :to => \"#{controller_action_name}\", :as => \"#{message}\"" end + else + replace_with 'match {{arguments}}' end + end end end end diff --git a/spec/rails/convert_rails_test_request_methods_4_2_to_5_0_spec.rb b/spec/rails/convert_rails_test_request_methods_4_2_to_5_0_spec.rb index 1f548402..601495c1 100644 --- a/spec/rails/convert_rails_test_request_methods_4_2_to_5_0_spec.rb +++ b/spec/rails/convert_rails_test_request_methods_4_2_to_5_0_spec.rb @@ -31,6 +31,7 @@ def test_xhr end end EOS + let(:test_rewritten_content) { <<~EOS } class PostsControllerTest < ActionController::TestCase def test_show