Project

General

Profile

« Previous | Next » 

Revision 0c82622c

Added by Dmitri Dolguikh about 10 years ago

fixes #5553: FiltersHelper#search_path returns an empty string for unrecognized resources

View differences:

app/helpers/filters_helper.rb
when 'Parameter'
'' # parameter is only used in API
else
resource_path(type) + '/auto_complete_search'
resource_path = resource_path(type)
resource_path.nil? ? "" : resource_path + auto_complete_search_path
end
end
end
def auto_complete_search_path
'/auto_complete_search'
end
def resource_path(type)
return '' if type.nil?
test/unit/helpers/filters_helper_test.rb
require 'test_helper'
class UnknownResource
end
class FiltersHelperTest < ActionView::TestCase
include FiltersHelper
def test_search_path_is_empty_for_nil_resource
assert_equal '', search_path(nil)
end
def test_search_path_is_empty_for_excepted_classes
%w(Image HostClass Parameter).each do |clazz_name|
assert_equal '', search_path(clazz_name), "class #{clazz_name} doesn't support autocomplete, shouldn't return autocomplete path"
end
end
def test_search_path_for_foreman_model
expects(:resource_path).with('Host').returns('hosts_path')
assert_equal 'hosts_path/auto_complete_search', search_path('Host')
end
def test_should_return_empty_search_path_if_resource_is_not_recognized
assert_equal '', search_path('UnknownResource')
end
end

Also available in: Unified diff