diff --git a/app/models/kit.rb b/app/models/kit.rb index ffbe90ca98..5accbb4623 100644 --- a/app/models/kit.rb +++ b/app/models/kit.rb @@ -46,7 +46,7 @@ def deactivate # or deallocated, we are changing inventory for inactive items (which we don't allow). # @return [Boolean] def can_reactivate? - line_items.joins(:item).where(items: { active: false }).none? + item.line_items.joins(:item).where(items: { active: false }).none? end def reactivate diff --git a/spec/models/kit_spec.rb b/spec/models/kit_spec.rb index 959e4256fc..bf41ee3212 100644 --- a/spec/models/kit_spec.rb +++ b/spec/models/kit_spec.rb @@ -64,12 +64,15 @@ end describe '#can_deactivate?' do - let(:kit) { create(:kit, organization: organization) } + let(:kit) { + kit_params = attributes_for(:kit) + kit_params[:line_items_attributes] = [{item_id: create(:item).id, quantity: 1}] + KitCreateService.new(organization_id: organization.id, kit_params: kit_params).call.kit + } context 'with inventory' do it 'should return false' do - item = create(:item, :active, organization: organization, kit: kit) - storage_location = create(:storage_location, :with_items, organization: organization, item: item) + storage_location = create(:storage_location, organization: organization) TestInventory.create_inventory(organization, { storage_location.id => { diff --git a/spec/requests/kit_requests_spec.rb b/spec/requests/kit_requests_spec.rb index 243713a409..249a713230 100644 --- a/spec/requests/kit_requests_spec.rb +++ b/spec/requests/kit_requests_spec.rb @@ -38,7 +38,7 @@ context "when it cannot be deactivated" do it "should disable the button" do - storage_location = create(:storage_location) + storage_location = create(:storage_location, organization: organization) TestInventory.create_inventory(kit.organization, { storage_location.id => { kit.item.id => 10 @@ -84,7 +84,7 @@ it "cannot reactivate if it has an inactive item" do kit.deactivate expect(kit).not_to be_active - kit.line_items.first.item.update!(active: false) + kit.item.line_items.first.item.update!(active: false) put reactivate_kit_url(kit) expect(kit.reload).not_to be_active