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

This commit is contained in:
Mark McDowall 2016-04-27 16:18:11 -07:00
parent 7934003b5e
commit 2f6fded7c3
4 changed files with 63 additions and 0 deletions

View File

@ -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);
}
}
}

View File

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

View File

@ -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)");
}
}
}

View File

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