Fixed: An issue preventing access to settings due to extraneous data in the database

pull/3113/head
Mark McDowall 9 years ago
parent 7934003b5e
commit 2f6fded7c3

@ -0,0 +1,37 @@
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Authentication;
using NzbDrone.Core.Housekeeping.Housekeepers;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
{
[TestFixture]
public class CleanupAdditionalUsersFixture : DbTest<CleanupAdditionalUsers, User>
{
[Test]
public void should_delete_additional_users()
{
var specs = Builder<User>.CreateListOfSize(5)
.BuildListOfNew();
Db.InsertMany(specs);
Subject.Clean();
AllStoredModels.Should().HaveCount(1);
}
[Test]
public void should_not_delete_if_only_one_user()
{
var spec = Builder<User>.CreateNew()
.BuildNew();
Db.Insert(spec);
Subject.Clean();
AllStoredModels.Should().HaveCount(1);
}
}
}

@ -207,6 +207,7 @@
<Compile Include="HealthCheck\HealthCheckFixture.cs" />
<Compile Include="HistoryTests\HistoryRepositoryFixture.cs" />
<Compile Include="HistoryTests\HistoryServiceFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalUsersFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalNamingSpecsFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupDuplicateMetadataFilesFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedBlacklistFixture.cs" />

@ -0,0 +1,24 @@
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupAdditionalUsers : IHousekeepingTask
{
private readonly IMainDatabase _database;
public CleanupAdditionalUsers(IMainDatabase database)
{
_database = database;
}
public void Clean()
{
var mapper = _database.GetDataMapper();
mapper.ExecuteNonQuery(@"DELETE FROM Users
WHERE ID NOT IN (
SELECT ID FROM Users
LIMIT 1)");
}
}
}

@ -497,6 +497,7 @@
<Compile Include="History\History.cs" />
<Compile Include="History\HistoryRepository.cs" />
<Compile Include="History\HistoryService.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalUsers.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalNamingSpecs.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupCommandQueue.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupDuplicateMetadataFiles.cs" />

Loading…
Cancel
Save