Project

General

Profile

« Previous | Next » 

Revision a322a96e

Added by Ori Rabin about 8 years ago

Fixes #14190 - consistent api output and search options

View differences:

app/models/concerns/hostext/search.rb
scoped_search :in => :model, :on => :name, :complete_value => true, :rename => :model
scoped_search :in => :hostgroup, :on => :name, :complete_value => true, :rename => :hostgroup
scoped_search :in => :hostgroup, :on => :name, :complete_enabled => false, :rename => :hostgroup_name, :only_explicit => true
scoped_search :in => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_fullname
scoped_search :in => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_title
scoped_search :in => :hostgroup, :on => :id, :complete_enabled => false, :rename => :hostgroup_id, :only_explicit => true
app/views/api/v2/hosts/main.json.rabl
attributes :ip, :environment_id, :environment_name, :last_report, :mac, :realm_id, :realm_name,
:sp_mac, :sp_ip, :sp_name, :domain_id, :domain_name, :architecture_id, :architecture_name, :operatingsystem_id, :operatingsystem_name,
:subnet_id, :subnet_name, :sp_subnet_id, :ptable_id, :ptable_name, :medium_id, :medium_name, :build,
:comment, :disk, :installed_at, :model_id, :hostgroup_id, :hostgroup_name, :owner_id, :owner_type,
:comment, :disk, :installed_at, :model_id, :hostgroup_id, :owner_id, :owner_type,
:enabled, :puppet_ca_proxy_id, :managed, :use_image, :image_file, :uuid, :compute_resource_id, :compute_resource_name,
:compute_profile_id, :compute_profile_name, :capabilities, :provision_method,
:puppet_proxy_id, :certname, :image_id, :image_name, :created_at, :updated_at,
......
attributes "#{status_class.humanized_name}_status", "#{status_class.humanized_name}_status_label", :if => @object.get_status(status_class).relevant?
end
node :hostgroup_name do |host|
host.hostgroup.name if host.hostgroup.present?
end
node :hostgroup_title do |host|
host.hostgroup.title if host.hostgroup.present?
end
@object.facets_with_definitions.each do |_facet, definition|
node do
partial(definition.api_list_view, :object => @object) if definition.api_list_view
test/functional/api/v2/hosts_controller_test.rb
get :template, { :id => managed_host.to_param, :kind => 'provitamin' }
assert_response :not_found
end
context 'search by hostgroup' do
def setup
@hostgroup = FactoryGirl.create(:hostgroup, :with_parent)
@managed_host = FactoryGirl.create(:host, :managed, :hostgroup => @hostgroup)
end
test "should search host by hostgroup name" do
get :index, { :search => "hostgroup_name = #{@hostgroup.name}" }
assert_equal [@managed_host], assigns(:hosts)
end
test "should search host by hostgroup title" do
get :index, { :search => "hostgroup_title = #{@hostgroup.title}" }
assert_equal [@managed_host], assigns(:hosts)
end
end
end

Also available in: Unified diff