Revision d5f2f1de
Added by Amir Fefer almost 6 years ago
app/controllers/api/v2/hosts_controller.rb | ||
---|---|---|
@hosts = action_scope_for(:index, resource_scope_for_index)
|
||
|
||
if params[:thin]
|
||
@subtotal = @hosts.total_entries
|
||
@hosts = @hosts.reorder(:name).distinct.pluck(:id, :name)
|
||
render 'thin'
|
||
return
|
test/controllers/api/v2/hosts_controller_test.rb | ||
---|---|---|
assert_equal Host.all.pluck(:id, :name), hosts['results'].map(&:values)
|
||
end
|
||
|
||
test "subtotal should be the same as the search count with thin" do
|
||
FactoryBot.create_list(:host, 2)
|
||
Host.last.update_attribute(:name, 'test')
|
||
|
||
get :index, params: { thin: true, per_page: 1, search: 'host' }
|
||
assert_response :success
|
||
assert_not_nil assigns(:hosts)
|
||
hosts = ActiveSupport::JSON.decode(@response.body)
|
||
assert_equal hosts['subtotal'], Host.search_for('host').size
|
||
end
|
||
|
||
test "should include registered scope on index" do
|
||
# remember the previous state
|
||
old_scopes = Api::V2::HostsController.scopes_for(:index).dup
|
Also available in: Unified diff
Fixes #23599 - fix subtotal value in API call with thin=true