Project

General

Profile

« Previous | Next » 

Revision 88c60cb8

Added by Adi Abramovich almost 3 years ago

Fixes #32727 - Added status and version to api call (#8572)

View differences:

app/controllers/api/v2/smart_proxies_controller.rb
api :GET, "/smart_proxies/", N_("List all smart proxies")
param_group :taxonomy_scope, ::Api::V2::BaseController
param_group :search_and_pagination, ::Api::V2::BaseController
param :include_status, :bool, N_("Flag to indicate whether to include status or not")
add_scoped_search_description_for(SmartProxy)
def index
@smart_proxies = resource_scope_for_index.includes(:features)
@status = params[:include_status]
end
api :GET, "/smart_proxies/:id/", N_("Show a smart proxy")
param :id, :identifier, :required => true
param :include_status, :bool, N_("Flag to indicate whether to include status or not")
param :include_version, :bool, N_("Flag to indicate whether to include version or not")
def show
@status = params[:include_status]
@version = params[:include_version]
end
def_param_group :smart_proxy do
app/views/api/v2/smart_proxies/main.json.rabl
extends "api/v2/smart_proxies/base"
attributes :created_at, :updated_at
attributes :created_at, :updated_at, :hosts_count
child :smart_proxy_features => :features do
attributes :capabilities
......
attributes :name, :id
end
end
if @status
node(:status) { |smart_proxy| smart_proxy.ping ? Ping::STATUS_OK : Ping::STATUS_FAIL }
end
app/views/api/v2/smart_proxies/show.json.rabl
node do |hostgroup|
partial("api/v2/taxonomies/children_nodes", :object => hostgroup)
end
if @version
node(:version) { @smart_proxy.statuses[:version].version['version'] }
end
child :smart_proxy_features => :features do
glue :feature do
attributes :name, :id
if @version
node(:version) do |feature|
@smart_proxy.statuses[:version].version['modules'][feature["name"].downcase]
end
end
end
end
test/controllers/api/v2/smart_proxies_controller_test.rb
expected_proxy_ids = SmartProxy.unscoped.with_features("TFTP").map { |p| p.id }
assert_equal expected_proxy_ids, returned_proxy_ids
end
test "should get index including status" do
stub_smart_proxy_v2_features_and_statuses
get :index, params: { :include_status => true }
assert_response :success
smart_proxies = ActiveSupport::JSON.decode(@response.body)
returned_proxy_status = smart_proxies['results'].map { |p| p["status"] }
number_of_proxies = smart_proxies['results'].map { |p| p["id"] }.count
assert_equal number_of_proxies, returned_proxy_status.count
end
test "should show individual record" do
get :show, params: { :id => smart_proxies(:one).to_param }
......
refute_empty show_response
end
test "should show individual record with including status" do
stub_smart_proxy_v2_features_and_statuses
get :show, params: { :id => smart_proxies(:one).to_param, :include_status => true }
assert_response :success
show_response = ActiveSupport::JSON.decode(@response.body)
assert_includes show_response, 'status'
refute_includes show_response, 'version'
end
test "should show individual record including version" do
stub_smart_proxy_v2_features_and_statuses
get :show, params: { :id => smart_proxies(:one).to_param, :include_version => true }
assert_response :success
show_response = ActiveSupport::JSON.decode(@response.body)
refute_includes show_response, 'status'
assert_includes show_response, 'version'
end
test_attributes :pid => '0ffe0dc5-675e-45f4-b7e1-a14d3dd81f6e'
test "should create smart_proxy" do
assert_difference('SmartProxy.unscoped.count') do

Also available in: Unified diff