diff --git a/app/controllers/api/v1/inventories_controller.rb b/app/controllers/api/v1/inventories_controller.rb index a1efdb845..84aef0a5b 100644 --- a/app/controllers/api/v1/inventories_controller.rb +++ b/app/controllers/api/v1/inventories_controller.rb @@ -11,6 +11,7 @@ module Api def index inventories = @team.repositories + .active .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) render jsonapi: inventories, each_serializer: InventorySerializer diff --git a/app/controllers/api/v1/inventory_items_controller.rb b/app/controllers/api/v1/inventory_items_controller.rb index c0446612c..be8850a83 100644 --- a/app/controllers/api/v1/inventory_items_controller.rb +++ b/app/controllers/api/v1/inventory_items_controller.rb @@ -13,6 +13,7 @@ module Api def index items = @inventory.repository_rows + .active .preload(repository_cells: :repository_column) .preload(repository_cells: @inventory.cell_preload_includes) .page(params.dig(:page, :number)) diff --git a/spec/requests/api/v1/inventories_controller_spec.rb b/spec/requests/api/v1/inventories_controller_spec.rb index 3fe54e0c6..a71ec6b65 100644 --- a/spec/requests/api/v1/inventories_controller_spec.rb +++ b/spec/requests/api/v1/inventories_controller_spec.rb @@ -46,6 +46,21 @@ RSpec.describe 'Api::V1::InventoriesController', type: :request do expect { hash_body = json }.not_to raise_exception expect(hash_body['errors'][0]).to include('status': 403) end + + context 'when have some archived inventories' do + before do + create(:repository, :archived, name: Faker::Name.unique.name, created_by: @user, team: @teams.first) + end + + it 'will ignore them' do + hash_body = nil + + get api_v1_team_inventories_path(team_id: @teams.first.id), headers: @valid_headers + + expect { hash_body = json }.not_to raise_exception + expect(hash_body['data'].count).to be_eql 2 + end + end end describe 'GET inventory, #show' do diff --git a/spec/requests/api/v1/inventory_items_controller_spec.rb b/spec/requests/api/v1/inventory_items_controller_spec.rb index 53dda8a16..553ae8bf0 100644 --- a/spec/requests/api/v1/inventory_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_items_controller_spec.rb @@ -50,7 +50,7 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do attributes: { name: Faker::Name.unique.name } }, - included: [ + included: [ { type: 'inventory_cells', attributes: { column_id: text_column.id, @@ -150,6 +150,25 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do expect { hash_body = json }.not_to raise_exception expect(hash_body['errors'][0]).to include('status': 404) end + + context 'when have some archived rows' do + before do + create(:repository_row, :archived, + name: Faker::Name.unique.name, created_by: @user, repository: @teams.first.repositories.first) + end + + it 'will ignore them' do + hash_body = nil + + get api_v1_team_inventory_items_path( + team_id: @teams.first.id, + inventory_id: @teams.first.repositories.first.id + ), params: { page: { size: 200 } }, headers: @valid_headers + + expect { hash_body = json }.not_to raise_exception + expect(hash_body['data'].count).to be_eql 100 + end + end end describe 'DELETE inventory_items, #destroy' do